[Numpy-discussion] Release of 1.0b5 this weekend

Charles R Harris charlesr.harris at gmail.com
Tue Aug 29 15:17:29 CDT 2006


On 8/29/06, Tim Hochberg <tim.hochberg at ieee.org> wrote:
>
> Charles R Harris wrote:
> > Hi,
> >
> > On 8/29/06, *Tim Hochberg* <tim.hochberg at ieee.org
> > <mailto:tim.hochberg at ieee.org>> wrote:
> >
> >
> >     -0.5 from me if what we're talking about here is having mutating
> >     methods
> >     return self rather than None. Chaining stuff is pretty, but having
> >     methods that mutate self and return self looks like a source of
> >     elusive
> >     bugs to me.
> >
> >     -tim
> >
> >
> > But how is that any worse than the current mutating operators? I think
> > the operating principal is that methods generally work in place,
> > functions make copies. The exceptions to this rule need to be noted.
> Is that really the case? I was more under the impression that there
> wasn't much rhyme nor reason to this. Let's do a quick dir(somearray)
> and see what we get (I'll strip out the __XXX__ names):
>
> 'all', 'any', 'argmax', 'argmin', 'argsort', 'astype', 'base',
> 'byteswap', 'choose', 'clip', 'compress', 'conj', 'conjugate', 'copy',
> 'ctypes', 'cumprod', 'cumsum', 'data', 'diagonal', 'dtype', 'dump',
> 'dumps', 'fill', 'flags', 'flat', 'flatten', 'getfield', 'imag', 'item',
> 'itemsize', 'max', 'mean', 'min', 'nbytes', 'ndim', 'newbyteorder',
> 'nonzero', 'prod', 'ptp', 'put', 'putmask', 'ravel', 'real', 'repeat',
> 'reshape', 'resize', 'round', 'searchsorted', 'setfield', 'setflags',
> 'shape', 'size', 'sort', 'squeeze', 'std', 'strides', 'sum', 'swapaxes',
> 'take', 'tofile', 'tolist', 'tostring', 'trace', 'transpose', 'var',
> 'view'


There are certainly many methods where inplace operations make no sense. But
for such things as conjugate and clip I think it should be preferred. Think
of them as analogs of the "+=" operators that allow memory efficient inplace
operations. At the moment there are too few such operators, IMHO, and that
makes it hard to write memory efficient code when you want to do so. If you
need a copy, the functional form should be the preferred way to go and can
easily be implement by constructions like a.copy().sort().

Hmmm. Without taking too much time to go through these one at a time,
> I'm pretty certain that they do not in general mutate things in place.
> Probably at least half return, or can return new arrays, sometimes with
> references to the original data, but new shapes, sometimes with
> completely new data. In fact, other than sort, I'm not sure which of
> these does mutate in place.
>
> -tim


Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20060829/a6d250ac/attachment.html 


More information about the Numpy-discussion mailing list