[Numpy-discussion] Should ndarray be a context manager?

Sebastian Berg 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 ;).

- Sebastian

> 
> 
> Sturla
> 
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
> 

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20141210/e4be4739/attachment.sig>


More information about the NumPy-Discussion mailing list