On Wed, 2022-06-01 at 08:49 -0700, Sebastian Berg wrote:
> Hi all,
> 
> I would like to share the first formal draft of
> 
>     NEP 50: Promotion rules for Python scalars
> 
> with everyone.  The full text can be found here:
> 
>     https://numpy.org/neps/nep-0050-scalar-promotion.html
> 

As a brief update on this, as noted in the NEP (Note at the end of the
abstract), our nightly wheels can now be used to try out the first
changes here.  To use you have to install NumPy from the nightlies:

    pip install -i https://pypi.anaconda.org/scipy-wheels-nightly/simple numpy 
--upgrade

(I added an --upgrade in case you have a numpy version already).  And
then run Python e.g. with:

    NPY_PROMOTION_STATE=weak ipython

Please see the NEP note for more information.  As of now, especially
the error when integers are too large is missing (this is added in an
open PR).

It would be very interesting to hear whether your use case (e.g.
scripts) is affected by the changes!  Right now mainly scipy and
sklearn were tried, but for this change I believe the impact on end-
users is much more important than that on libraries.

Cheers,

Sebastian


> NEP 50 is an attempt to remove value-based casting/promotion.  We
> wish
> to replace it with clearer rules for the resulting dtype when mixing
> NumPy arrays and Python scalars.  As a brief example, the proposal
> allows the following (unchanged):
> 
>     >>> np.array([1, 2, 3], dtype=np.int8) + 100
>     np.array([101, 102, 103], dtype=np.int8)
> 
> While clearing up confusion caused by the value-inspecting behavior
> that we see sometimes, such as:
> 
>     >>> np.array([1, 2, 3], dtype=np.int8) + 300
>     np.array([301, 302, 303], dtype=np.int16)  # note the int16
> 
> Where 300 is too large to fit an ``int8``.  As well as removing the
> special behavior of 0-D arrays or NumPy scalars:
> 
>     >>> res = np.array(1, dtype=np.int8) + 100
>     >>> res.dtype
>     dtype('int64')
> 
> This is the continuation of a long discussion (see the "Discussion"
> section), including the poll I once posted:
> https://discuss.scientific-python.org/t/poll-future-numpy-behavior-when-mixing-arrays-numpy-scalars-and-python-scalars/202
> 
> I would be happy for any feadback, be it just editorial or
> fundamental
> discussion.  There are many alternatives which I have tried to
> capture
> in the NEP.
> So lets discuss here, or on discuss:
> 
>    
> https://discuss.scientific-python.org/t/nep-50-promotion-rules-for-python-scalars/280
> 
> For smaller edits, don't hesitate to open a NumPy PR, or propose
> edits
> on my branch (you can use the edit button to create a PR):
> 
>    
> https://github.com/seberg/numpy/blob/nep50/doc/neps/nep-0050-scalar-promotion.rst
> 
> An important part of moving forward will be assessing the real world
> impact.  To start that process, I have created a branch as a draft PR
> (at this time):
> 
>     https://github.com/numpy/numpy/pull/21626
> 
> It is missing some parts, but should allow preliminary testing. The
> main missing part is that the integer warnings and errors are less
> strict than proposed in the NEP.
> It would be invaluable to get a better idea to what extent existing
> code, especially end-user code, is affected by the proposed changes.
> 
> Thanks in advance for any input!  This is a big, complicated
> proposal,
> but finding a way forward will hopefully clear up a source of
> confusion
> and inconsistencies that make both maintainers and users life harder.
> 
> Cheers,
> 
> Sebastian
> _______________________________________________
> 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: sebast...@sipsolutions.net

Attachment: signature.asc
Description: This is a digitally signed message part

_______________________________________________
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