提交 903d1d3c authored 作者: Arnaud Bergeron's avatar Arnaud Bergeron

Remove tentacles in scalar.

上级 9cde027a
...@@ -100,8 +100,7 @@ class Erfcx(UnaryScalarOp): ...@@ -100,8 +100,7 @@ class Erfcx(UnaryScalarOp):
Notes Notes
----- -----
This op can still be executed on GPU, despite not having c_code. When This op can still be executed on GPU, despite not having c_code. When
running on GPU, sandbox.cuda.opt.local_gpu_elemwise_[0,1] replaces this op running on GPU an optimization will replace it with a gpu version.
with sandbox.cuda.elemwise.ErfcxGPU.
""" """
def impl(self, x): def impl(self, x):
...@@ -135,8 +134,7 @@ class Erfinv(UnaryScalarOp): ...@@ -135,8 +134,7 @@ class Erfinv(UnaryScalarOp):
Notes Notes
----- -----
This op can still be executed on GPU, despite not having c_code. When This op can still be executed on GPU, despite not having c_code. When
running on GPU, sandbox.cuda.opt.local_gpu_elemwise_[0,1] replaces this op running on GPU, an optimization will replace it with a GPU version.
with sandbox.cuda.elemwise.ErfinvGPU.
(TODO) Find a C implementation of erfinv for CPU. (TODO) Find a C implementation of erfinv for CPU.
""" """
...@@ -298,47 +296,52 @@ class Psi(UnaryScalarOp): ...@@ -298,47 +296,52 @@ class Psi(UnaryScalarOp):
return ( return (
""" """
// For GPU support // For GPU support
#ifdef __CUDACC__ #ifdef WITHIN_KERNEL
#define DEVICE __device__ #define DEVICE WITHIN_KERNEL
#else #else
#define DEVICE #define DEVICE
#endif #endif
#ifndef ga_double
#define ga_double double
#ifndef _PSIFUNCDEFINED #ifndef _PSIFUNCDEFINED
#define _PSIFUNCDEFINED #define _PSIFUNCDEFINED
DEVICE double _psi(double x){ DEVICE double _psi(ga_double x) {
/*taken from /*taken from
Bernardo, J. M. (1976). Algorithm AS 103: Bernardo, J. M. (1976). Algorithm AS 103:
Psi (Digamma) Function. Applied Statistics. 25 (3), 315-317. Psi (Digamma) Function. Applied Statistics. 25 (3), 315-317.
http://www.uv.es/~bernardo/1976AppStatist.pdf */ http://www.uv.es/~bernardo/1976AppStatist.pdf */
double y, R, psi_ = 0; ga_double y, R, psi_ = 0;
double S = 1.0e-5; ga_double S = 1.0e-5;
double C = 8.5; ga_double C = 8.5;
double S3 = 8.333333333e-2; ga_double S3 = 8.333333333e-2;
double S4 = 8.333333333e-3; ga_double S4 = 8.333333333e-3;
double S5 = 3.968253968e-3; ga_double S5 = 3.968253968e-3;
double D1 = -0.5772156649; ga_double D1 = -0.5772156649;
y = x; y = x;
if (y <= 0.0) if (y <= 0.0)
return psi_; return psi_;
if (y <= S ) if (y <= S)
return D1 - 1.0/y; return D1 - 1.0/y;
while (y < C){ while (y < C) {
psi_ = psi_ - 1.0 / y; psi_ = psi_ - 1.0 / y;
y = y + 1;} y = y + 1;
}
R = 1.0 / y; R = 1.0 / y;
psi_ = psi_ + log(y) - .5 * R ; psi_ = psi_ + log(y) - .5 * R ;
R= R*R; R= R*R;
psi_ = psi_ - R * (S3 - R * (S4 - R * S5)); psi_ = psi_ - R * (S3 - R * (S4 - R * S5));
return psi_;} return psi_;
}
#endif #endif
""") """)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论