question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`numpy.exp` is not raising overflow error for large values

See original GitHub issue

Here is an example:

import numpy as np
np.seterr(all='raise')
np.exp(750.0)

this used to raise FloatingPointError: overflow... in older NumPy version, but isn’t raising it as of version 1.14.2

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
oleksandr-pavlykcommented, Sep 16, 2019

@tadeu It will be inefficient to use Intel Math Kernel Library’s VML routines for a single entry due to an overhead cost.

I can confirm that NumPy 1.17 from intel channel does raise the FP exception:

Python 3.6.9 |Intel Corporation| (default, Sep 11 2019, 11:50:16) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Intel(R) Distribution for Python is brought to you by Intel Corporation.
Please check out: https://software.intel.com/en-us/python-distribution
>>> import numpy as np
>>> np.seterr(all='raise')
{'divide': 'warn', 'over': 'warn', 'under': 'ignore', 'invalid': 'warn'}
>>> np.exp(750.0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
FloatingPointError: overflow encountered in exp
>>>

However, NumPy in the Intel channel is compiled with Intel C Compiler, and uses Intel’s C compiler run-time, which implement scalar transcendental functions.

NumPy installed from conda-forge channel, presumably also compiled with MSVC raises the error:

(np117_v) C:\Users\opavlyk\devel>python
Python 3.6.7 (default, Jul  2 2019, 02:21:41) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> np.seterr(all='raise')
{'divide': 'warn', 'over': 'warn', 'under': 'ignore', 'invalid': 'warn'}
>>> np.exp(750.0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
FloatingPointError: overflow encountered in exp

Perhaps someone from Anaconda team needs to look into the problem and comment.

1reaction
mattipcommented, Sep 16, 2019

The answer to your question is no, this was a compilation using no linalg accelerator. Additionally, BLAS/Lapack is not involved in np.exp.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Overflow Error in Python's numpy.exp function
As fuglede says, the issue here is that np.float64 can't handle a number as large as exp(1234.1) . Try using np.float128 instead:
Read more >
numpy.exp is not raising overflow error for large values #16
Issue: numpy.exp is not raising overflow error for large values, only in the Anaconda distribution, present in the latest version and at ...
Read more >
How to Fix: RuntimeWarning: overflow encountered in exp
This warning occurs when you use the NumPy exp function, but use a value that is too large for it to handle. It's...
Read more >
How to Fix: RuntimeWarning: Overflow encountered in exp
This warning occurs while using the NumPy library's exp() function upon using on a value that is too large. This function is used...
Read more >
numpy.exp — NumPy v1.24 Manual
Calculate the exponential of all elements in the input array. Parameters: xarray_like ... If not provided or None, a freshly-allocated array is returned....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found