[SciPy-User] overflow
Sturla Molden
sturla at molden.no
Sat Jul 10 17:28:09 EDT 2010
Mr Nilsson skrev:
> Is there a way to have numpy clip the values to the maximum value of
> whatever dtype is used instead of overflowing?
>
Subclass the scalar np.uint8, and change how multiplication works to
something like this:
inline npy_uint8 multiply(npy_uint8 a, npy_uint8 b)
{
npy_unit32 tmp = b;
tmp *= a;
return (npy_uint8)((tmp >> 2) ? 0xFF : tmp);
}
Sturla
More information about the SciPy-User
mailing list