same_value casting in ndarray.astype
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/numpy-discussion@python.org/thread/B66...> What do you think? Matti
I like the idea of adding "same_value" casting. I have added some comments to the PR. -- Marten matti picus via NumPy-Discussion <numpy-discussion@python.org> writes:
In PR 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
What do you think? Matti
participants (2)
-
Marten van Kerkwijk -
matti picus