[SciPy-User] overflow

Mr Nilsson super.inframan at gmail.com
Sat Jul 10 19:00:20 EDT 2010


Hm well the reason im going 8/16 bit in the first place is to conserve
memory, so going back to float isnt optimal..
Is there a reason numpy overflows in the first place? Coming from an
image processing background i cant really think of any situation where
it would be preferable, possibly other than performance?

thanks for the help,
Gusty

On 10 July, 23:10, Charles R Harris <charlesr.har... at gmail.com> wrote:
> On Sat, Jul 10, 2010 at 3:43 PM, Sebastian Haase <seb.ha... at gmail.com>wrote:
>
>
>
>
>
> > On Sat, Jul 10, 2010 at 11:28 PM, Sturla Molden <stu... at molden.no> wrote:
> > > 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);
> > > }
>
> > This does not sound like an easy solution ...
> > First: How to sub-class a basic thing like this  .... this looks like
> > it's happening on the C level ... !?
> > Second: there are probably quite a lot of functions to take care of ...
>
> > Could numexpr be helpful for this - if memory is an issue ?
> > If memory is no issue, it probably the easiest solution to just
> > (explicitly) convert to float32 and only as last step convert back to
> > uint8.
>
> That's what I would recommend as the minimal work approach if memory isn't
> an issue.
>
> Chuck
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-U... at scipy.orghttp://mail.scipy.org/mailman/listinfo/scipy-user



More information about the SciPy-User mailing list