same_value casting in ndarray.astype

matti picus via NumPy-Discussion <[email protected]>
Newsgroups gmane.comp.python.numeric.general
Message-ID <CAO8bCgjWUSJ5OaDKa=t7SBsmfJ5EOr45BKkgC9i0nYx=T1qcBQ@mail.gmail.com>
In PR 29129 <https://github.com/numpy/numpy/pull/29129> I propose to add a
new casting option to ndarray.astype(dtype, casting='XXX') called
same_value. It changes the inner casting loop to check that the value
round-trips, and raises a value error on overflow or float-to-int
truncation. While the PR adds infrastructure for further same_value casting
in user-defined dtypes and elsewhere in NumPy, the current work is only
exposed in ndarray.astype (and not in np.astype, since there is no casting
option in that function).

This was motivated by user desire to have some kind of value-based casting.

See also the discussion of saturation-based ufuncs
<https://mail.python.org/archives/list/[email protected]/thread/B66THXMXAAC33UORRFOZGLTFKCU7VUBM/#B66THXMXAAC33UORRFOZGLTFKCU7VUBM>

What do you think?
Matti

_______________________________________________
NumPy-Discussion mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/numpy-discussion.python.org
Member address: [email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.