
I would have thought that this snippet would raise an exception: import numpy numpy.seterr(all='raise') a = numpy.array([1.0,0.0,-1.0]) b = numpy.log(a) I get as a result (in b): [0, -Inf, NaN] It's basically the same issue as: http://numpy-discussion.10968.n7.nabble.com/numpy-log-does-not-raise- exceptions-td5854.html Except that I have explicitly set the error flags to raise exceptions. It works fine for sqrt(), but not for log(). I've checked numpy 1.4.0 and 1.7.1 and both have the same behavior. Is there a way to force the log (and log10) function to raise an exception on invalid input?

On 22.10.2014 05:52, Daniel Hyams wrote:
I would have thought that this snippet would raise an exception:
import numpy numpy.seterr(all='raise') a = numpy.array([1.0,0.0,-1.0]) b = numpy.log(a)
I get as a result (in b): [0, -Inf, NaN]
It's basically the same issue as:
http://numpy-discussion.10968.n7.nabble.com/numpy-log-does-not-raise- exceptions-td5854.html
Except that I have explicitly set the error flags to raise exceptions. It works fine for sqrt(), but not for log(). I've checked numpy 1.4.0 and 1.7.1 and both have the same behavior.
Is there a way to force the log (and log10) function to raise an exception on invalid input?
What platform are you using? whether you get exceptions or not depends on your math library.

I guess we could make this more consistent by hand if we wanted - isnan is pretty cheap? On 22 Oct 2014 07:44, "Julian Taylor" <jtaylor.debian@googlemail.com> wrote:
On 22.10.2014 05:52, Daniel Hyams wrote:
I would have thought that this snippet would raise an exception:
import numpy numpy.seterr(all='raise') a = numpy.array([1.0,0.0,-1.0]) b = numpy.log(a)
I get as a result (in b): [0, -Inf, NaN]
It's basically the same issue as:
http://numpy-discussion.10968.n7.nabble.com/numpy-log-does-not-raise- exceptions-td5854.html
Except that I have explicitly set the error flags to raise exceptions.
It
works fine for sqrt(), but not for log(). I've checked numpy 1.4.0 and 1.7.1 and both have the same behavior.
Is there a way to force the log (and log10) function to raise an exception on invalid input?
What platform are you using? whether you get exceptions or not depends on your math library.
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion

On 22 Oct 2014 14:57, "Daπid" <davidmenhur@gmail.com> wrote:
On 22 October 2014 15:43, Nathaniel Smith <njs@pobox.com> wrote:
I guess we could make this more consistent by hand if we wanted - isnan
is pretty cheap?
Can it be made avoiding storing the full bool array? The 1/8 memory
overhead can be problematic for large arrays. Yeah, we could push the check into the inner loop so the memory overhead would be, like, 1 byte.
participants (4)
-
Daniel Hyams
-
Daπid
-
Julian Taylor
-
Nathaniel Smith