Skip to content

Commit 0a8cc54

Browse files
committed
Fall back to local erf if no other is available.
1 parent 6c82fb2 commit 0a8cc54

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

spectral/algorithms/resampling.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,32 @@
3434

3535
from __future__ import division, print_function, unicode_literals
3636

37+
def erf_local(x):
38+
import math
39+
# save the sign of x
40+
sign = 1 if x >= 0 else -1
41+
x = abs(x)
42+
43+
# constants
44+
a1 = 0.254829592
45+
a2 = -0.284496736
46+
a3 = 1.421413741
47+
a4 = -1.453152027
48+
a5 = 1.061405429
49+
p = 0.3275911
50+
51+
# A&S formula 7.1.26
52+
t = 1.0/(1.0 + p*x)
53+
y = 1.0 - (((((a5*t + a4)*t) + a3)*t + a2)*t + a1)*t*math.exp(-x*x)
54+
return sign*y # erf(-x) = -erf(x)
55+
3756
try:
3857
from math import erf
3958
except:
40-
from scipy.special import erf
59+
try:
60+
from scipy.special import erf
61+
except:
62+
erf = erf_local
4163

4264
def erfc(z):
4365
'''Complement of the error function.'''

0 commit comments

Comments
 (0)