Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
7411a082
提交
7411a082
authored
1月 23, 2025
作者:
Ricardo Vieira
提交者:
Ricardo Vieira
2月 12, 2025
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
More direct access to special functions
上级
0b94be01
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
31 行增加
和
31 行删除
+31
-31
math.py
pytensor/scalar/math.py
+31
-31
没有找到文件。
pytensor/scalar/math.py
浏览文件 @
7411a082
...
@@ -9,7 +9,7 @@ from pathlib import Path
...
@@ -9,7 +9,7 @@ from pathlib import Path
from
textwrap
import
dedent
from
textwrap
import
dedent
import
numpy
as
np
import
numpy
as
np
import
scipy.
special
from
scipy
import
special
from
pytensor.configdefaults
import
config
from
pytensor.configdefaults
import
config
from
pytensor.gradient
import
grad_not_implemented
,
grad_undefined
from
pytensor.gradient
import
grad_not_implemented
,
grad_undefined
...
@@ -52,7 +52,7 @@ class Erf(UnaryScalarOp):
...
@@ -52,7 +52,7 @@ class Erf(UnaryScalarOp):
nfunc_spec
=
(
"scipy.special.erf"
,
1
,
1
)
nfunc_spec
=
(
"scipy.special.erf"
,
1
,
1
)
def
impl
(
self
,
x
):
def
impl
(
self
,
x
):
return
s
cipy
.
s
pecial
.
erf
(
x
)
return
special
.
erf
(
x
)
def
L_op
(
self
,
inputs
,
outputs
,
grads
):
def
L_op
(
self
,
inputs
,
outputs
,
grads
):
(
x
,)
=
inputs
(
x
,)
=
inputs
...
@@ -86,7 +86,7 @@ class Erfc(UnaryScalarOp):
...
@@ -86,7 +86,7 @@ class Erfc(UnaryScalarOp):
nfunc_spec
=
(
"scipy.special.erfc"
,
1
,
1
)
nfunc_spec
=
(
"scipy.special.erfc"
,
1
,
1
)
def
impl
(
self
,
x
):
def
impl
(
self
,
x
):
return
s
cipy
.
s
pecial
.
erfc
(
x
)
return
special
.
erfc
(
x
)
def
L_op
(
self
,
inputs
,
outputs
,
grads
):
def
L_op
(
self
,
inputs
,
outputs
,
grads
):
(
x
,)
=
inputs
(
x
,)
=
inputs
...
@@ -113,7 +113,7 @@ class Erfc(UnaryScalarOp):
...
@@ -113,7 +113,7 @@ class Erfc(UnaryScalarOp):
return
f
"{z} = erfc(({cast}){x});"
return
f
"{z} = erfc(({cast}){x});"
# s
cipy.s
pecial.erfc don't support complex. Why?
# special.erfc don't support complex. Why?
erfc
=
Erfc
(
upgrade_to_float_no_complex
,
name
=
"erfc"
)
erfc
=
Erfc
(
upgrade_to_float_no_complex
,
name
=
"erfc"
)
...
@@ -135,7 +135,7 @@ class Erfcx(UnaryScalarOp):
...
@@ -135,7 +135,7 @@ class Erfcx(UnaryScalarOp):
nfunc_spec
=
(
"scipy.special.erfcx"
,
1
,
1
)
nfunc_spec
=
(
"scipy.special.erfcx"
,
1
,
1
)
def
impl
(
self
,
x
):
def
impl
(
self
,
x
):
return
s
cipy
.
s
pecial
.
erfcx
(
x
)
return
special
.
erfcx
(
x
)
def
L_op
(
self
,
inputs
,
outputs
,
grads
):
def
L_op
(
self
,
inputs
,
outputs
,
grads
):
(
x
,)
=
inputs
(
x
,)
=
inputs
...
@@ -191,7 +191,7 @@ class Erfinv(UnaryScalarOp):
...
@@ -191,7 +191,7 @@ class Erfinv(UnaryScalarOp):
nfunc_spec
=
(
"scipy.special.erfinv"
,
1
,
1
)
nfunc_spec
=
(
"scipy.special.erfinv"
,
1
,
1
)
def
impl
(
self
,
x
):
def
impl
(
self
,
x
):
return
s
cipy
.
s
pecial
.
erfinv
(
x
)
return
special
.
erfinv
(
x
)
def
L_op
(
self
,
inputs
,
outputs
,
grads
):
def
L_op
(
self
,
inputs
,
outputs
,
grads
):
(
x
,)
=
inputs
(
x
,)
=
inputs
...
@@ -226,7 +226,7 @@ class Erfcinv(UnaryScalarOp):
...
@@ -226,7 +226,7 @@ class Erfcinv(UnaryScalarOp):
nfunc_spec
=
(
"scipy.special.erfcinv"
,
1
,
1
)
nfunc_spec
=
(
"scipy.special.erfcinv"
,
1
,
1
)
def
impl
(
self
,
x
):
def
impl
(
self
,
x
):
return
s
cipy
.
s
pecial
.
erfcinv
(
x
)
return
special
.
erfcinv
(
x
)
def
L_op
(
self
,
inputs
,
outputs
,
grads
):
def
L_op
(
self
,
inputs
,
outputs
,
grads
):
(
x
,)
=
inputs
(
x
,)
=
inputs
...
@@ -261,7 +261,7 @@ class Owens_t(BinaryScalarOp):
...
@@ -261,7 +261,7 @@ class Owens_t(BinaryScalarOp):
nfunc_spec
=
(
"scipy.special.owens_t"
,
2
,
1
)
nfunc_spec
=
(
"scipy.special.owens_t"
,
2
,
1
)
def
impl
(
self
,
h
,
a
):
def
impl
(
self
,
h
,
a
):
return
s
cipy
.
s
pecial
.
owens_t
(
h
,
a
)
return
special
.
owens_t
(
h
,
a
)
def
grad
(
self
,
inputs
,
grads
):
def
grad
(
self
,
inputs
,
grads
):
(
h
,
a
)
=
inputs
(
h
,
a
)
=
inputs
...
@@ -286,7 +286,7 @@ class Gamma(UnaryScalarOp):
...
@@ -286,7 +286,7 @@ class Gamma(UnaryScalarOp):
nfunc_spec
=
(
"scipy.special.gamma"
,
1
,
1
)
nfunc_spec
=
(
"scipy.special.gamma"
,
1
,
1
)
def
impl
(
self
,
x
):
def
impl
(
self
,
x
):
return
s
cipy
.
s
pecial
.
gamma
(
x
)
return
special
.
gamma
(
x
)
def
L_op
(
self
,
inputs
,
outputs
,
gout
):
def
L_op
(
self
,
inputs
,
outputs
,
gout
):
(
x
,)
=
inputs
(
x
,)
=
inputs
...
@@ -321,7 +321,7 @@ class GammaLn(UnaryScalarOp):
...
@@ -321,7 +321,7 @@ class GammaLn(UnaryScalarOp):
nfunc_spec
=
(
"scipy.special.gammaln"
,
1
,
1
)
nfunc_spec
=
(
"scipy.special.gammaln"
,
1
,
1
)
def
impl
(
self
,
x
):
def
impl
(
self
,
x
):
return
s
cipy
.
s
pecial
.
gammaln
(
x
)
return
special
.
gammaln
(
x
)
def
L_op
(
self
,
inputs
,
outputs
,
grads
):
def
L_op
(
self
,
inputs
,
outputs
,
grads
):
(
x
,)
=
inputs
(
x
,)
=
inputs
...
@@ -361,7 +361,7 @@ class Psi(UnaryScalarOp):
...
@@ -361,7 +361,7 @@ class Psi(UnaryScalarOp):
nfunc_spec
=
(
"scipy.special.psi"
,
1
,
1
)
nfunc_spec
=
(
"scipy.special.psi"
,
1
,
1
)
def
impl
(
self
,
x
):
def
impl
(
self
,
x
):
return
s
cipy
.
s
pecial
.
psi
(
x
)
return
special
.
psi
(
x
)
def
L_op
(
self
,
inputs
,
outputs
,
grads
):
def
L_op
(
self
,
inputs
,
outputs
,
grads
):
(
x
,)
=
inputs
(
x
,)
=
inputs
...
@@ -448,7 +448,7 @@ class TriGamma(UnaryScalarOp):
...
@@ -448,7 +448,7 @@ class TriGamma(UnaryScalarOp):
"""
"""
def
impl
(
self
,
x
):
def
impl
(
self
,
x
):
return
s
cipy
.
s
pecial
.
polygamma
(
1
,
x
)
return
special
.
polygamma
(
1
,
x
)
def
L_op
(
self
,
inputs
,
outputs
,
outputs_gradients
):
def
L_op
(
self
,
inputs
,
outputs
,
outputs_gradients
):
(
x
,)
=
inputs
(
x
,)
=
inputs
...
@@ -547,7 +547,7 @@ class PolyGamma(BinaryScalarOp):
...
@@ -547,7 +547,7 @@ class PolyGamma(BinaryScalarOp):
return
upgrade_to_float_no_complex
(
x_type
)
return
upgrade_to_float_no_complex
(
x_type
)
def
impl
(
self
,
n
,
x
):
def
impl
(
self
,
n
,
x
):
return
s
cipy
.
s
pecial
.
polygamma
(
n
,
x
)
return
special
.
polygamma
(
n
,
x
)
def
L_op
(
self
,
inputs
,
outputs
,
output_gradients
):
def
L_op
(
self
,
inputs
,
outputs
,
output_gradients
):
(
n
,
x
)
=
inputs
(
n
,
x
)
=
inputs
...
@@ -574,7 +574,7 @@ class GammaInc(BinaryScalarOp):
...
@@ -574,7 +574,7 @@ class GammaInc(BinaryScalarOp):
nfunc_spec
=
(
"scipy.special.gammainc"
,
2
,
1
)
nfunc_spec
=
(
"scipy.special.gammainc"
,
2
,
1
)
def
impl
(
self
,
k
,
x
):
def
impl
(
self
,
k
,
x
):
return
s
cipy
.
s
pecial
.
gammainc
(
k
,
x
)
return
special
.
gammainc
(
k
,
x
)
def
grad
(
self
,
inputs
,
grads
):
def
grad
(
self
,
inputs
,
grads
):
(
k
,
x
)
=
inputs
(
k
,
x
)
=
inputs
...
@@ -621,7 +621,7 @@ class GammaIncC(BinaryScalarOp):
...
@@ -621,7 +621,7 @@ class GammaIncC(BinaryScalarOp):
nfunc_spec
=
(
"scipy.special.gammaincc"
,
2
,
1
)
nfunc_spec
=
(
"scipy.special.gammaincc"
,
2
,
1
)
def
impl
(
self
,
k
,
x
):
def
impl
(
self
,
k
,
x
):
return
s
cipy
.
s
pecial
.
gammaincc
(
k
,
x
)
return
special
.
gammaincc
(
k
,
x
)
def
grad
(
self
,
inputs
,
grads
):
def
grad
(
self
,
inputs
,
grads
):
(
k
,
x
)
=
inputs
(
k
,
x
)
=
inputs
...
@@ -668,7 +668,7 @@ class GammaIncInv(BinaryScalarOp):
...
@@ -668,7 +668,7 @@ class GammaIncInv(BinaryScalarOp):
nfunc_spec
=
(
"scipy.special.gammaincinv"
,
2
,
1
)
nfunc_spec
=
(
"scipy.special.gammaincinv"
,
2
,
1
)
def
impl
(
self
,
k
,
x
):
def
impl
(
self
,
k
,
x
):
return
s
cipy
.
s
pecial
.
gammaincinv
(
k
,
x
)
return
special
.
gammaincinv
(
k
,
x
)
def
grad
(
self
,
inputs
,
grads
):
def
grad
(
self
,
inputs
,
grads
):
(
k
,
x
)
=
inputs
(
k
,
x
)
=
inputs
...
@@ -693,7 +693,7 @@ class GammaIncCInv(BinaryScalarOp):
...
@@ -693,7 +693,7 @@ class GammaIncCInv(BinaryScalarOp):
nfunc_spec
=
(
"scipy.special.gammainccinv"
,
2
,
1
)
nfunc_spec
=
(
"scipy.special.gammainccinv"
,
2
,
1
)
def
impl
(
self
,
k
,
x
):
def
impl
(
self
,
k
,
x
):
return
s
cipy
.
s
pecial
.
gammainccinv
(
k
,
x
)
return
special
.
gammainccinv
(
k
,
x
)
def
grad
(
self
,
inputs
,
grads
):
def
grad
(
self
,
inputs
,
grads
):
(
k
,
x
)
=
inputs
(
k
,
x
)
=
inputs
...
@@ -928,7 +928,7 @@ class GammaU(BinaryScalarOp):
...
@@ -928,7 +928,7 @@ class GammaU(BinaryScalarOp):
# Note there is no basic SciPy version so no nfunc_spec.
# Note there is no basic SciPy version so no nfunc_spec.
def
impl
(
self
,
k
,
x
):
def
impl
(
self
,
k
,
x
):
return
s
cipy
.
special
.
gammaincc
(
k
,
x
)
*
scipy
.
special
.
gamma
(
k
)
return
s
pecial
.
gammaincc
(
k
,
x
)
*
special
.
gamma
(
k
)
def
c_support_code
(
self
,
**
kwargs
):
def
c_support_code
(
self
,
**
kwargs
):
return
(
C_CODE_PATH
/
"gamma.c"
)
.
read_text
(
encoding
=
"utf-8"
)
return
(
C_CODE_PATH
/
"gamma.c"
)
.
read_text
(
encoding
=
"utf-8"
)
...
@@ -960,7 +960,7 @@ class GammaL(BinaryScalarOp):
...
@@ -960,7 +960,7 @@ class GammaL(BinaryScalarOp):
# Note there is no basic SciPy version so no nfunc_spec.
# Note there is no basic SciPy version so no nfunc_spec.
def
impl
(
self
,
k
,
x
):
def
impl
(
self
,
k
,
x
):
return
s
cipy
.
special
.
gammainc
(
k
,
x
)
*
scipy
.
special
.
gamma
(
k
)
return
s
pecial
.
gammainc
(
k
,
x
)
*
special
.
gamma
(
k
)
def
c_support_code
(
self
,
**
kwargs
):
def
c_support_code
(
self
,
**
kwargs
):
return
(
C_CODE_PATH
/
"gamma.c"
)
.
read_text
(
encoding
=
"utf-8"
)
return
(
C_CODE_PATH
/
"gamma.c"
)
.
read_text
(
encoding
=
"utf-8"
)
...
@@ -992,7 +992,7 @@ class Jv(BinaryScalarOp):
...
@@ -992,7 +992,7 @@ class Jv(BinaryScalarOp):
nfunc_spec
=
(
"scipy.special.jv"
,
2
,
1
)
nfunc_spec
=
(
"scipy.special.jv"
,
2
,
1
)
def
impl
(
self
,
v
,
x
):
def
impl
(
self
,
v
,
x
):
return
s
cipy
.
s
pecial
.
jv
(
v
,
x
)
return
special
.
jv
(
v
,
x
)
def
grad
(
self
,
inputs
,
grads
):
def
grad
(
self
,
inputs
,
grads
):
v
,
x
=
inputs
v
,
x
=
inputs
...
@@ -1017,7 +1017,7 @@ class J1(UnaryScalarOp):
...
@@ -1017,7 +1017,7 @@ class J1(UnaryScalarOp):
nfunc_spec
=
(
"scipy.special.j1"
,
1
,
1
)
nfunc_spec
=
(
"scipy.special.j1"
,
1
,
1
)
def
impl
(
self
,
x
):
def
impl
(
self
,
x
):
return
s
cipy
.
s
pecial
.
j1
(
x
)
return
special
.
j1
(
x
)
def
grad
(
self
,
inputs
,
grads
):
def
grad
(
self
,
inputs
,
grads
):
(
x
,)
=
inputs
(
x
,)
=
inputs
...
@@ -1044,7 +1044,7 @@ class J0(UnaryScalarOp):
...
@@ -1044,7 +1044,7 @@ class J0(UnaryScalarOp):
nfunc_spec
=
(
"scipy.special.j0"
,
1
,
1
)
nfunc_spec
=
(
"scipy.special.j0"
,
1
,
1
)
def
impl
(
self
,
x
):
def
impl
(
self
,
x
):
return
s
cipy
.
s
pecial
.
j0
(
x
)
return
special
.
j0
(
x
)
def
grad
(
self
,
inp
,
grads
):
def
grad
(
self
,
inp
,
grads
):
(
x
,)
=
inp
(
x
,)
=
inp
...
@@ -1071,7 +1071,7 @@ class Iv(BinaryScalarOp):
...
@@ -1071,7 +1071,7 @@ class Iv(BinaryScalarOp):
nfunc_spec
=
(
"scipy.special.iv"
,
2
,
1
)
nfunc_spec
=
(
"scipy.special.iv"
,
2
,
1
)
def
impl
(
self
,
v
,
x
):
def
impl
(
self
,
v
,
x
):
return
s
cipy
.
s
pecial
.
iv
(
v
,
x
)
return
special
.
iv
(
v
,
x
)
def
grad
(
self
,
inputs
,
grads
):
def
grad
(
self
,
inputs
,
grads
):
v
,
x
=
inputs
v
,
x
=
inputs
...
@@ -1096,7 +1096,7 @@ class I1(UnaryScalarOp):
...
@@ -1096,7 +1096,7 @@ class I1(UnaryScalarOp):
nfunc_spec
=
(
"scipy.special.i1"
,
1
,
1
)
nfunc_spec
=
(
"scipy.special.i1"
,
1
,
1
)
def
impl
(
self
,
x
):
def
impl
(
self
,
x
):
return
s
cipy
.
s
pecial
.
i1
(
x
)
return
special
.
i1
(
x
)
def
grad
(
self
,
inputs
,
grads
):
def
grad
(
self
,
inputs
,
grads
):
(
x
,)
=
inputs
(
x
,)
=
inputs
...
@@ -1118,7 +1118,7 @@ class I0(UnaryScalarOp):
...
@@ -1118,7 +1118,7 @@ class I0(UnaryScalarOp):
nfunc_spec
=
(
"scipy.special.i0"
,
1
,
1
)
nfunc_spec
=
(
"scipy.special.i0"
,
1
,
1
)
def
impl
(
self
,
x
):
def
impl
(
self
,
x
):
return
s
cipy
.
s
pecial
.
i0
(
x
)
return
special
.
i0
(
x
)
def
grad
(
self
,
inp
,
grads
):
def
grad
(
self
,
inp
,
grads
):
(
x
,)
=
inp
(
x
,)
=
inp
...
@@ -1140,7 +1140,7 @@ class Ive(BinaryScalarOp):
...
@@ -1140,7 +1140,7 @@ class Ive(BinaryScalarOp):
nfunc_spec
=
(
"scipy.special.ive"
,
2
,
1
)
nfunc_spec
=
(
"scipy.special.ive"
,
2
,
1
)
def
impl
(
self
,
v
,
x
):
def
impl
(
self
,
v
,
x
):
return
s
cipy
.
s
pecial
.
ive
(
v
,
x
)
return
special
.
ive
(
v
,
x
)
def
grad
(
self
,
inputs
,
grads
):
def
grad
(
self
,
inputs
,
grads
):
v
,
x
=
inputs
v
,
x
=
inputs
...
@@ -1165,7 +1165,7 @@ class Kve(BinaryScalarOp):
...
@@ -1165,7 +1165,7 @@ class Kve(BinaryScalarOp):
nfunc_spec
=
(
"scipy.special.kve"
,
2
,
1
)
nfunc_spec
=
(
"scipy.special.kve"
,
2
,
1
)
def
impl
(
self
,
v
,
x
):
def
impl
(
self
,
v
,
x
):
return
s
cipy
.
s
pecial
.
kve
(
v
,
x
)
return
special
.
kve
(
v
,
x
)
def
L_op
(
self
,
inputs
,
outputs
,
output_grads
):
def
L_op
(
self
,
inputs
,
outputs
,
output_grads
):
v
,
x
=
inputs
v
,
x
=
inputs
...
@@ -1195,7 +1195,7 @@ class Sigmoid(UnaryScalarOp):
...
@@ -1195,7 +1195,7 @@ class Sigmoid(UnaryScalarOp):
nfunc_spec
=
(
"scipy.special.expit"
,
1
,
1
)
nfunc_spec
=
(
"scipy.special.expit"
,
1
,
1
)
def
impl
(
self
,
x
):
def
impl
(
self
,
x
):
return
s
cipy
.
s
pecial
.
expit
(
x
)
return
special
.
expit
(
x
)
def
grad
(
self
,
inp
,
grads
):
def
grad
(
self
,
inp
,
grads
):
(
x
,)
=
inp
(
x
,)
=
inp
...
@@ -1362,7 +1362,7 @@ class BetaInc(ScalarOp):
...
@@ -1362,7 +1362,7 @@ class BetaInc(ScalarOp):
nfunc_spec
=
(
"scipy.special.betainc"
,
3
,
1
)
nfunc_spec
=
(
"scipy.special.betainc"
,
3
,
1
)
def
impl
(
self
,
a
,
b
,
x
):
def
impl
(
self
,
a
,
b
,
x
):
return
s
cipy
.
s
pecial
.
betainc
(
a
,
b
,
x
)
return
special
.
betainc
(
a
,
b
,
x
)
def
grad
(
self
,
inp
,
grads
):
def
grad
(
self
,
inp
,
grads
):
a
,
b
,
x
=
inp
a
,
b
,
x
=
inp
...
@@ -1622,7 +1622,7 @@ class BetaIncInv(ScalarOp):
...
@@ -1622,7 +1622,7 @@ class BetaIncInv(ScalarOp):
nfunc_spec
=
(
"scipy.special.betaincinv"
,
3
,
1
)
nfunc_spec
=
(
"scipy.special.betaincinv"
,
3
,
1
)
def
impl
(
self
,
a
,
b
,
x
):
def
impl
(
self
,
a
,
b
,
x
):
return
s
cipy
.
s
pecial
.
betaincinv
(
a
,
b
,
x
)
return
special
.
betaincinv
(
a
,
b
,
x
)
def
grad
(
self
,
inputs
,
grads
):
def
grad
(
self
,
inputs
,
grads
):
(
a
,
b
,
x
)
=
inputs
(
a
,
b
,
x
)
=
inputs
...
@@ -1661,7 +1661,7 @@ class Hyp2F1(ScalarOp):
...
@@ -1661,7 +1661,7 @@ class Hyp2F1(ScalarOp):
nfunc_spec
=
(
"scipy.special.hyp2f1"
,
4
,
1
)
nfunc_spec
=
(
"scipy.special.hyp2f1"
,
4
,
1
)
def
impl
(
self
,
a
,
b
,
c
,
z
):
def
impl
(
self
,
a
,
b
,
c
,
z
):
return
s
cipy
.
s
pecial
.
hyp2f1
(
a
,
b
,
c
,
z
)
return
special
.
hyp2f1
(
a
,
b
,
c
,
z
)
def
grad
(
self
,
inputs
,
grads
):
def
grad
(
self
,
inputs
,
grads
):
a
,
b
,
c
,
z
=
inputs
a
,
b
,
c
,
z
=
inputs
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论