[Numpy-discussion] Get rid of special scalar arithmetic

Sebastian Berg sebastian at sipsolutions.net
Wed Jan 13 12:59:35 EST 2016


On Mi, 2016-01-13 at 10:33 -0500, Marten van Kerkwijk wrote:
> Just thought I would add here a general comment I made in the thread:
> replacing scalars everywhere with array scalars (i.e., ndim=0) would
> be great also from the perspective of ndarray subclasses; as is, it
> is quite annoying to have to special-case, e.g., getting a single
> subclass element, and rewrapping the scalar in the subclass.
> -- Marten

I understand the sentiment, and right now I think we usually give the
subclass the chance to rewrap itself around 0-d arrays. But ideally I
think this is incorrect. Either you want the scalar to be a scalar, or
the array actually holds information which is associated with the dtype
(i.e. units) and thus should survive conversion to scalar.

To me personally, I don't think that we can really remove scalars, due
to things such as mutability, sequence ABC registration and with that
also hashability.

My gut feeling is that there is actually an advantage in having a
scalar object, even if internally this scalar object could reuse a lot.
Note that a, e.g. 0-d write-only array would raise an error on `a +=
1`....

Now practicality beating purity and all that, but to me it is not
obvious that it would be the best thing to get rid of scalars completly
(getting rid of the code duplication is a different issue).

- Sebastian



> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> https://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/20160113/0ebdbd06/attachment.sig>


More information about the NumPy-Discussion mailing list