[Numpy-discussion] Should ndarray be a context manager?
sebastian at sipsolutions.net
Wed Dec 10 04:04:19 EST 2014
On Mi, 2014-12-10 at 07:25 +0000, Sturla Molden wrote:
> 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 :-)
Completly agree, we may tell the user where the gun is, but we shouldn't
put it in their hand and then point it at their feet as well ;).
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 819 bytes
Desc: This is a digitally signed message part
More information about the NumPy-Discussion