Skip to content

Commit

Permalink
BLD Instead of fmin use C++'s algorithm.max for windows compatibility.
Browse files Browse the repository at this point in the history
  • Loading branch information
twiecki committed May 8, 2015
1 parent 33c57de commit 521596b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

try:
from Cython.Build import cythonize
ext_modules = cythonize([Extension('wfpt', ['src/wfpt.pyx']),
ext_modules = cythonize([Extension('wfpt', ['src/wfpt.pyx'], language='c++'),
Extension('cdfdif_wrapper', ['src/cdfdif_wrapper.pyx', 'src/cdfdif.c']),
])

except ImportError:
ext_modules = [Extension('wfpt', ['src/wfpt.c']),
ext_modules = [Extension('wfpt', ['src/wfpt.c'], language='c++'),
Extension('cdfdif_wrapper', ['src/cdfdif_wrapper.c', 'src/cdfdif.c'])
]

Expand Down
9 changes: 6 additions & 3 deletions src/pdf.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@ cdef extern from "math.h" nogil:
double log(double)
double exp(double)
double sqrt(double)
double fmax(double, double)
# double fmax(double, double)
double pow(double, double)
double ceil(double)
double floor(double)
double fabs(double)
double M_PI

cdef extern from "<algorithm>" namespace "std" nogil:
T max[T](T a, T b)

cdef double ftt_01w(double tt, double w, double err) nogil:
"""Compute f(t|0,1,w) for the likelihood of the drift diffusion model using the method
and implementation of Navarro & Fuss, 2009.
Expand All @@ -32,14 +35,14 @@ cdef double ftt_01w(double tt, double w, double err) nogil:
# calculate number of terms needed for large t
if M_PI*tt*err<1: # if error threshold is set low enough
kl=sqrt(-2*log(M_PI*tt*err)/(M_PI**2*tt)) # bound
kl=fmax(kl,1./(M_PI*sqrt(tt))) # ensure boundary conditions met
kl=max(kl,1./(M_PI*sqrt(tt))) # ensure boundary conditions met
else: # if error threshold set too high
kl=1./(M_PI*sqrt(tt)) # set to boundary condition

# calculate number of terms needed for small t
if 2*sqrt(2*M_PI*tt)*err<1: # if error threshold is set low enough
ks=2+sqrt(-2*tt*log(2*sqrt(2*M_PI*tt)*err)) # bound
ks=fmax(ks,sqrt(tt)+1) # ensure boundary conditions are met
ks=max(ks,sqrt(tt)+1) # ensure boundary conditions are met
else: # if error threshold was set too high
ks=2 # minimal kappa for that case

Expand Down

0 comments on commit 521596b

Please sign in to comment.