[Numpy-discussion] Can numpy catch this error for me?

Robert Kern robert.kern@gmail....
Tue Apr 7 15:58:08 CDT 2009


On Tue, Apr 7, 2009 at 15:27, Nathaniel Peterson
<nathanielpeterson08@gmail.com> wrote:
> Thanks for the quick response.
> In http://www.scipy.org/Cookbook/Indexing
> I see
>
>>>> a = C[1,2,3]
>
>>>> a
> 23
>>>> type(a)
>
> <type 'numpy.int32'>
>>>> type(int(a))
>
> <type 'int'>
>>>> a**a
>
> Warning: overflow encountered in long_scalars
>
> -1276351769
>>>> int(a)**int(a)
>
> 20880467999847912034355032910567L
>
> This shows numpy can catch an overflow generated by a**a.
> Why is it that numpy can catch this overflow,
>
> but can not catch one generated by np.multiply.reduce?

Unlike true floating point errors (where the hardware FPU sets a flag
whenever it does an atomic operation that overflows), we need to
implement the integer overflow detection ourselves. We do it on the
scalars, but not arrays because it would be too slow to implement for
every atomic operation on arrays.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
  -- Umberto Eco


More information about the Numpy-discussion mailing list