Skip to content

Commit

Permalink
ENH: special: restore backwards compatibility for integer-arg functions
Browse files Browse the repository at this point in the history
Special-case old functions which cast silently their input arguments to
integers. This restores full backwards compatibility.
  • Loading branch information
pv committed Nov 4, 2012
1 parent 7591869 commit 044a861
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 15 deletions.
56 changes: 56 additions & 0 deletions scipy/special/_legacy.pxd
@@ -0,0 +1,56 @@
# -*- cython -*-
"""
Many Scipy special functions originally cast silently double input
arguments to integers.
Here, we define such unsafe wrappers manually.
"""

cdef extern from "cephes.h":
double bdtrc(int k, int n, double p) nogil
double bdtr(int k, int n, double p) nogil
double bdtri(int k, int n, double y) nogil
double expn(int n, double x) nogil
double hyp2f0(double a, double b, double x, int type, double *err) nogil
double nbdtrc(int k, int n, double p) nogil
double nbdtr(int k, int n, double p) nogil
double nbdtri(int k, int n, double p) nogil
double pdtrc(int k, double m) nogil
double pdtr(int k, double m) nogil
double pdtri(int k, double y) nogil
double kn(int n, double x) nogil
double yn(int n, double x) nogil
double smirnov(int n, double e) nogil
double smirnovi(int n, double p) nogil

cdef inline double bdtrc_unsafe(double k, double n, double p) nogil:
return bdtrc(<int>k, <int>n, p)
cdef inline double bdtr_unsafe(double k, double n, double p) nogil:
return bdtr(<int>k, <int>n, p)
cdef inline double bdtri_unsafe(double k, double n, double y) nogil:
return bdtri(<int>k, <int>n, y)
cdef inline double expn_unsafe(double n, double x) nogil:
return expn(<int>n, x)
cdef inline double hyp2f0_unsafe(double a, double b, double x, double type, double *err) nogil:
return hyp2f0(a, b, x, <int>type, err)
cdef inline double nbdtrc_unsafe(double k, double n, double p) nogil:
return nbdtrc(<int>k, <int>n, p)
cdef inline double nbdtr_unsafe(double k, double n, double p) nogil:
return nbdtr(<int>k, <int>n, p)
cdef inline double nbdtri_unsafe(double k, double n, double p) nogil:
return nbdtri(<int>k, <int>n, p)
cdef inline double pdtrc_unsafe(double k, double m) nogil:
return pdtrc(<int>k, m)
cdef inline double pdtr_unsafe(double k, double m) nogil:
return pdtr(<int>k, m)
cdef inline double pdtri_unsafe(double k, double y) nogil:
return pdtri(<int>k, y)
cdef inline double kn_unsafe(double n, double x) nogil:
return kn(<int>n, x)
cdef inline double yn_unsafe(double n, double x) nogil:
return yn(<int>n, x)
cdef inline double smirnov_unsafe(double n, double e) nogil:
return smirnov(<int>n, e)
cdef inline double smirnovi_unsafe(double n, double p) nogil:
return smirnovi(<int>n, p)
30 changes: 15 additions & 15 deletions scipy/special/generate_ufuncs.py
Expand Up @@ -68,9 +68,9 @@
_eval_chebyt -- eval_poly_chebyt: ld->d -- orthogonal_eval.pxd
logit -- logitf: f->f, logit: d->d, logitl: g->g -- _logit.h
expit -- expitf: f->f, expit: d->d, expitl: g->g -- _logit.h
bdtrc -- bdtrc: iid->d -- cephes.h
bdtr -- bdtr: iid->d -- cephes.h
bdtri -- bdtri: iid->d -- cephes.h
bdtrc -- bdtrc: iid->d, bdtrc_unsafe: ddd->d -- cephes.h, _legacy.pxd
bdtr -- bdtr: iid->d, bdtr_unsafe: ddd->d -- cephes.h, _legacy.pxd
bdtri -- bdtri: iid->d, bdtri_unsafe: ddd->d -- cephes.h, _legacy.pxd
btdtr -- btdtr: ddd->d -- cephes.h
btdtri -- incbi: ddd->d -- cephes.h
fdtrc -- fdtrc: ddd->d -- cephes.h
Expand All @@ -81,14 +81,14 @@
hyp2f1 -- hyp2f1: dddd->d, chyp2f1_wrap: dddD->D -- cephes.h, specfun_wrappers.h
hyp1f1 -- hyp1f1_wrap: ddd->d, chyp1f1_wrap: ddD->D -- specfun_wrappers.h
hyperu -- hypU_wrap: ddd->d -- specfun_wrappers.h
hyp2f0 -- hyp2f0: dddi*d->d -- cephes.h
hyp2f0 -- hyp2f0: dddi*d->d, hyp2f0_unsafe: dddd*d->d -- cephes.h, _legacy.pxd
hyp1f2 -- onef2: dddd*d->d -- cephes.h
hyp3f0 -- threef0: dddd*d->d -- cephes.h
betainc -- incbet: ddd->d -- cephes.h
betaincinv -- incbi: ddd->d -- cephes.h
nbdtrc -- nbdtrc: iid->d -- cephes.h
nbdtr -- nbdtr: iid->d -- cephes.h
nbdtri -- nbdtri: iid->d -- cephes.h
nbdtrc -- nbdtrc: iid->d, nbdtrc_unsafe: ddd->d -- cephes.h, _legacy.pxd
nbdtr -- nbdtr: iid->d, nbdtr_unsafe: ddd->d -- cephes.h, _legacy.pxd
nbdtri -- nbdtri: iid->d, nbdtri_unsafe: ddd->d -- cephes.h, _legacy.pxd
beta -- beta: dd->d -- cephes.h
betaln -- lbeta: dd->d -- cephes.h
cbrt -- cbrt: d->d -- cephes.h
Expand All @@ -114,16 +114,16 @@
iv -- iv: dd->d, cbesi_wrap: dD->D -- cephes.h, amos_wrappers.h
ive -- cbesi_wrap_e_real: dd->d, cbesi_wrap_e: dD->D -- amos_wrappers.h
ellipj -- ellpj: dd*dddd->*i -- cephes.h
expn -- expn: id->d -- cephes.h
expn -- expn: id->d, expn_unsafe: dd->d -- cephes.h, _legacy.pxd
exp1 -- exp1_wrap: d->d, cexp1_wrap: D->D -- specfun_wrappers.h
expi -- expi_wrap: d->d, cexpi_wrap: D->D -- specfun_wrappers.h
kn -- kn: id->d -- cephes.h
pdtrc -- pdtrc: id->d -- cephes.h
pdtr -- pdtr: id->d -- cephes.h
pdtri -- pdtri: id->d -- cephes.h
yn -- yn: id->d -- cephes.h
smirnov -- smirnov: id->d -- cephes.h
smirnovi -- smirnovi: id->d -- cephes.h
kn -- kn: id->d, kn_unsafe: dd->d -- cephes.h, _legacy.pxd
pdtrc -- pdtrc: id->d, pdtrc_unsafe: dd->d -- cephes.h, _legacy.pxd
pdtr -- pdtr: id->d, pdtr_unsafe: dd->d -- cephes.h, _legacy.pxd
pdtri -- pdtri: id->d, pdtri_unsafe: dd->d -- cephes.h, _legacy.pxd
yn -- yn: id->d, yn_unsafe: dd->d -- cephes.h, _legacy.pxd
smirnov -- smirnov: id->d, smirnov_unsafe: dd->d -- cephes.h, _legacy.pxd
smirnovi -- smirnovi: id->d, smirnovi_unsafe: dd->d -- cephes.h, _legacy.pxd
airy -- airy: d*dddd->*i, cairy_wrap: D*DDDD->*i -- cephes.h, amos_wrappers.h
itairy -- itairy_wrap: d*dddd->*i -- specfun_wrappers.h
airye -- cairy_wrap_e_real: d*dddd->*i, cairy_wrap_e: D*DDDD->*i -- amos_wrappers.h
Expand Down

0 comments on commit 044a861

Please sign in to comment.