>>> from scipy.special import erf
>>> print (erf(0.j))
__main__:1: RuntimeWarning: invalid value encountered in erf
0j
This warning is only printed once (even if I do scipy.special.errprint(0)), but I don’t understand why it’s printed at all. Really, 0.j is the same number as 0. and it has no problem with that one.
I suppose there are two questions:
1) Is there any way to suppress this warning?
2) Is this warning a bug, or am I missing something?
UPDATE
I (think I) tracked down the error function in the scipy source tree. It is located in: scipy/special/specfun/specfun.f (subroutine CERROR). This function does not raise the warning (It works fine when called from a simple fortran program).
You can turn off warnings with
numpy.seterr:0.jis not the same as0.. The former is a complex number, that latter is just a float.The complex erf and real erf use different algorithms, e.g.
Since the real erf and complex erf use different algorithms, some warnings in the complex erf will not be present in the real erf. If we check the Fortran implementation, we’ll find:
In particular, Z = 0 + 0j, so Z1 = 0 + 0j, so CS = CR = 0 + 0j before the loop. At the first iteration of the loop, we get:
and then the condition requires CR/CS, which is a 0/0, which is an invalid floating point operation, and thus the warning.
This is a minor issue which can be “fixed” easily by checking if Z == 0 at the beginning. You could report a bug if you find this behavior erratic.