I think it is a not so infrequent requirement to do castings from float types
to integer types of from float types to lower precision float types where it is
OK to have a loss of precision, but you want to be sure not to get values that
are completely unrelated to the input ones because of wrapping effects.
A typical application can be in sound/image processing, where you do filtering
with floating point, but then you want to go back to integer types for the
final result and if you have values too large for the integer type, then you
want the values to saturate to the maximum ones and not certainly a positive
value to become negative because of wrapping. Missing the clipping step in
some cases can even be dangerous (e.g. resulting in sound signals that once
played through a headset can get so loud to damage the hear).
As of today, I think that this conversion can only be done with
`.clip().astype(...)`. However, this is a bit inconvenient: on one hand,
for the clip step you need to have the minimum and maximum values, which could
be automatically determined from the type you want (but clip knows nothing
about it yet). Secondly, this method concatenation creates temporary copies
that would be unneeded if the operation could be done in just one step.
Ideally, I'd like to be able to write `a.astype(np.int16, casting=`clip`).
___
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