[Numpy-discussion] Should ndarray be a context manager?
Sturla Molden
sturla.molden at gmail.com
Wed Dec 10 02:25:44 EST 2014
Nathaniel Smith <njs at pobox.com> wrote:
> This should be pretty trivial to implement. AFAICT you don't need any
> complicated cython
I have a bad habit of thinking in terms of too complicated C instead of
just using NumPy.
> @contextmanager
> def tmp_zeros(*args, **kwargs):
> arr = np.zeros(*args, **kwargs)
> try:
> yield arr
> finally:
> arr.resize((0,), check_refs=False)
>
> Given how intrinsically dangerous this is, and how easily it can be
> implemented using numpy's existing public API, I think maybe we should
> leave this for third-party daredevils instead of implementing it in numpy
> proper.
It seems so :-)
Sturla
More information about the NumPy-Discussion
mailing list