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

Robert Kern robert.kern at gmail.com
Tue Apr 7 16:58:08 EDT 2009


On Tue, Apr 7, 2009 at 15:27, Nathaniel Peterson
<nathanielpeterson08 at 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