[Numpy-discussion] Shouldn't all in-place operations simply return self?
josef.pktd@gmai...
josef.pktd@gmai...
Wed Jan 16 19:53:58 CST 2013
On Wed, Jan 16, 2013 at 7:11 PM, eat <e.antero.tammi@gmail.com> wrote:
> Hi,
>
> In a recent thread
> http://article.gmane.org/gmane.comp.python.numeric.general/52772 it was
> proposed that .fill(.) should return self as an alternative for a trivial
> two-liner.
>
> I'm raising now the question: what if all in-place operations indeed could
> return self? How bad this would be? A 'strong' counter argument may be found
> at http://mail.python.org/pipermail/python-dev/2003-October/038855.html.
>
> But anyway, at least for me. it would be much more straightforward to
> implement simple mini dsl's
> (http://en.wikipedia.org/wiki/Domain-specific_language) a much more
> straightforward manner.
>
> What do you think?
I'm against it.
I think it requires too much thinking by users and developers.
The function in numpy are conceptually much closer to basic python,
not some heavy object oriented framework where we need lots of
chaining.
(I thought I remembered some discussion and justification for
returning self in sqlalchemy for this, but couldn't find it.)
I'm chasing quite a few bugs with inplace operations
>>> a = np.arange(10)
>>> a *= np.pi
>>> a
???
>>> a = np.random.random_integers(0, 5, size=5)
>>> b = a.sort()
>>> b
>>> a
array([0, 1, 2, 5, 5])
>>> b = np.random.shuffle(a)
>>> b
>>> b = np.random.permutation(a)
>>> b
array([0, 5, 5, 2, 1])
How do I remember if shuffle shuffles or permutes ?
Do we have a list of functions that are inplace?
Josef
>
>
> -eat
>
> P.S. FWIW, if this idea really gains momentum obviously I'm volunteering to
> create a PR of it.
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
More information about the NumPy-Discussion
mailing list