Integer type casting and OverflowError
With master numpy (and back to 1.6.1, at least): [~] |1> np.int32(3054212286) -1240755010 It seems like at one time, this used to raise an OverflowError. We can see this in at least one place in scipy: https://github.com/scipy/scipy/blob/master/scipy/interpolate/fitpack.py#L912 Is this a regression in numpy, or should the code in scipy be fixed to use a different test? Even if it is technically a regression, it might be one of those "it's been broken so long, it's a feature now" regressions. -- Robert Kern
On 9 May 2013 12:21, Robert Kern <robert.kern@gmail.com> wrote:
With master numpy (and back to 1.6.1, at least):
[~] |1> np.int32(3054212286) -1240755010
It seems like at one time, this used to raise an OverflowError. We can see this in at least one place in scipy:
https://github.com/scipy/scipy/blob/master/scipy/interpolate/fitpack.py#L912
No doubt I'm missing something, but isn't the OverflowError raised here https://github.com/scipy/scipy/blob/master/scipy/interpolate/fitpack.py#L40 and not in Numpy? Cheers, Scott
On Thu, May 9, 2013 at 11:38 AM, Scott Sinclair <scott.sinclair.za@gmail.com> wrote:
On 9 May 2013 12:21, Robert Kern <robert.kern@gmail.com> wrote:
With master numpy (and back to 1.6.1, at least):
[~] |1> np.int32(3054212286) -1240755010
It seems like at one time, this used to raise an OverflowError. We can see this in at least one place in scipy:
https://github.com/scipy/scipy/blob/master/scipy/interpolate/fitpack.py#L912
No doubt I'm missing something, but isn't the OverflowError raised here https://github.com/scipy/scipy/blob/master/scipy/interpolate/fitpack.py#L40 and not in Numpy?
Heh. I wrote this email before I submitted the PR with that fix. :-) Here is what the code used to look like: https://github.com/scipy/scipy/blob/c1625b2cd026553cc9414ad12bb90c74a469e714... -- Robert Kern
On 9 May 2013 12:45, Robert Kern <robert.kern@gmail.com> wrote:
On Thu, May 9, 2013 at 11:38 AM, Scott Sinclair <scott.sinclair.za@gmail.com> wrote:
On 9 May 2013 12:21, Robert Kern <robert.kern@gmail.com> wrote:
With master numpy (and back to 1.6.1, at least):
[~] |1> np.int32(3054212286) -1240755010
It seems like at one time, this used to raise an OverflowError. We can see this in at least one place in scipy:
https://github.com/scipy/scipy/blob/master/scipy/interpolate/fitpack.py#L912
No doubt I'm missing something, but isn't the OverflowError raised here https://github.com/scipy/scipy/blob/master/scipy/interpolate/fitpack.py#L40 and not in Numpy?
Heh. I wrote this email before I submitted the PR with that fix. :-)
Hah. I should have checked recent commits as well... Cheers, Scott
09.05.2013 13:21, Robert Kern kirjoitti:
With master numpy (and back to 1.6.1, at least):
[~] |1> np.int32(3054212286) -1240755010
It seems like at one time, this used to raise an OverflowError. We can see this in at least one place in scipy:
It actually still raises an overflowerror if the integer is too big to fit into int64 (or maybe into int32 on 32-bit systems). The behavior is the same as in Numpy 1.2.0, so it has perhaps been like this forever. So most likely, the code in Scipy was correct only for 32-bit systems. -- Pauli Virtanen
On Thu, May 9, 2013 at 11:50 AM, Pauli Virtanen <pav@iki.fi> wrote:
09.05.2013 13:21, Robert Kern kirjoitti:
With master numpy (and back to 1.6.1, at least):
[~] |1> np.int32(3054212286) -1240755010
It seems like at one time, this used to raise an OverflowError. We can see this in at least one place in scipy:
It actually still raises an overflowerror if the integer is too big to fit into int64 (or maybe into int32 on 32-bit systems). The behavior is the same as in Numpy 1.2.0, so it has perhaps been like this forever.
So most likely, the code in Scipy was correct only for 32-bit systems.
Which does not surprise me in the slightest. -- Robert Kern
participants (3)
-
Pauli Virtanen -
Robert Kern -
Scott Sinclair