[SciPy-User] overflow

Sturla Molden sturla@molden...
Sat Jul 10 16:28:09 CDT 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