On Mon, Feb 21, 2022, at 20:56, Juan Nunez-Iglesias wrote:
> > the
> > latter would seem consistent with the "principle of least surprise" when 
> > moving from a typed language to
> > NumPy work perhaps, though arguably slightly less user-friendly if naively 
> > doing some operations with
> > a less formal view of typing (new Python user messing around with NumPy?)
> 
> fwiw, my rationale here is that many (most?) beginners will eventually become 
> intermediate-to-advanced, at which point purity becomes increasingly 
> important. It is often easier to explain a "pure" principle to a beginner 
> than it is to navigate around magic behaviour as an expert. At scikit-image 
> tutorials we often begin by having the users overflow a uint8 image, then we 
> explain why that's the case and how to work around it.

Just to play a bit of devil's advocate here, I'd have to say that most people 
will not expect

x[0] + 200

To often yield a number less than 200!

I think uint8's are especially problematic because they overflow so quickly 
(you won't easily run into the same behavior with uint16 and higher).  Of 
course, there is no way to pretend that NumPy integers are Python integers, but 
by changing the casting table for uint8 a bit we may be able to avoid many 
common errors.

Besides, coming from value based casting, users already have this expectation:

In [1]: np.uint8(255) + 1
Out[1]: 256

Currently, NumPy scalars and arrays are treated differently.  Arrays have 
stronger types than scalars, in that users expect:

In [3]: np.array([253, 254, 255], dtype=np.uint8) + 3
Out[3]: array([0, 1, 2], dtype=uint8)

So perhaps the real question is: how important is it to us that arrays and 
scalars behave the same in the new casting scheme?  (JAX, from the docs you 
linked, also makes the scalar vs array distinction.)

> We have also increasingly encountered users surprised/annoyed that 
> scikit-image blew up their uint8 to a float64, using 8x the RAM.

I know this used to be true, but my sense is that it is less and less so, 
especially now that almost all skimage functions use floatx internally.

Stéfan

_______________________________________________
NumPy-Discussion mailing list -- numpy-discussion@python.org
To unsubscribe send an email to numpy-discussion-le...@python.org
https://mail.python.org/mailman3/lists/numpy-discussion.python.org/
Member address: arch...@mail-archive.com

Reply via email to