Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
2dc75912
提交
2dc75912
authored
7月 29, 2022
作者:
Rune Michael Dominik
提交者:
Brandon T. Willard
8月 11, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add scipy's owens_t function as op
上级
fd50f36b
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
90 行增加
和
0 行删除
+90
-0
math.py
aesara/scalar/math.py
+29
-0
inplace.py
aesara/tensor/inplace.py
+5
-0
math.py
aesara/tensor/math.py
+6
-0
test_math_scipy.py
tests/tensor/test_math_scipy.py
+50
-0
没有找到文件。
aesara/scalar/math.py
浏览文件 @
2dc75912
...
...
@@ -250,6 +250,35 @@ class Erfcinv(UnaryScalarOp):
erfcinv
=
Erfcinv
(
upgrade_to_float_no_complex
,
name
=
"erfcinv"
)
class
Owens_t
(
BinaryScalarOp
):
nfunc_spec
=
(
"scipy.special.owens_t"
,
2
,
1
)
@staticmethod
def
st_impl
(
h
,
a
):
return
scipy
.
special
.
owens_t
(
h
,
a
)
def
impl
(
self
,
h
,
a
):
return
Owens_t
.
st_impl
(
h
,
a
)
def
grad
(
self
,
inputs
,
grads
):
(
h
,
a
)
=
inputs
(
gz
,)
=
grads
return
[
gz
*
(
-
1
)
*
exp
(
-
(
h
**
2
)
/
2
)
*
erf
(
a
*
h
/
np
.
sqrt
(
2
))
/
(
2
*
np
.
sqrt
(
2
*
np
.
pi
)),
gz
*
exp
(
-
0.5
*
(
a
**
2
+
1
)
*
h
**
2
)
/
(
2
*
np
.
pi
*
(
a
**
2
+
1
)),
]
def
c_code
(
self
,
*
args
,
**
kwargs
):
raise
NotImplementedError
()
owens_t
=
Owens_t
(
upgrade_to_float
,
name
=
"owens_t"
)
class
Gamma
(
UnaryScalarOp
):
nfunc_spec
=
(
"scipy.special.gamma"
,
1
,
1
)
...
...
aesara/tensor/inplace.py
浏览文件 @
2dc75912
...
...
@@ -233,6 +233,11 @@ def erfcx_inplace(a):
"""scaled complementary error function"""
@scalar_elemwise
def
owens_t_inplace
(
h
,
a
):
"""owens t function"""
@scalar_elemwise
def
gamma_inplace
(
a
):
"""gamma function"""
...
...
aesara/tensor/math.py
浏览文件 @
2dc75912
...
...
@@ -1339,6 +1339,11 @@ def erfcinv(a):
"""inverse complementary error function"""
@scalar_elemwise
def
owens_t
(
h
,
a
):
"""owens t function"""
@scalar_elemwise
def
gamma
(
a
):
"""gamma function"""
...
...
@@ -3062,6 +3067,7 @@ __all__ = [
"erfcx"
,
"erfinv"
,
"erfcinv"
,
"owens_t"
,
"gamma"
,
"gammaln"
,
"psi"
,
...
...
tests/tensor/test_math_scipy.py
浏览文件 @
2dc75912
...
...
@@ -53,6 +53,7 @@ expected_erf = scipy.special.erf
expected_erfc
=
scipy
.
special
.
erfc
expected_erfinv
=
scipy
.
special
.
erfinv
expected_erfcinv
=
scipy
.
special
.
erfcinv
expected_owenst
=
scipy
.
special
.
owens_t
expected_gamma
=
scipy
.
special
.
gamma
expected_gammaln
=
scipy
.
special
.
gammaln
expected_psi
=
scipy
.
special
.
psi
...
...
@@ -146,6 +147,55 @@ TestErfcinvBroadcast = makeBroadcastTester(
mode
=
mode_no_scipy
,
)
rng
=
np
.
random
.
default_rng
(
seed
=
utt
.
fetch_seed
())
_good_broadcast_binary_owenst
=
dict
(
normal
=
(
random_ranged
(
-
5
,
5
,
(
2
,
3
),
rng
=
rng
),
random_ranged
(
-
5
,
5
,
(
2
,
3
),
rng
=
rng
),
),
empty
=
(
np
.
asarray
([],
dtype
=
config
.
floatX
),
np
.
asarray
([],
dtype
=
config
.
floatX
)),
int
=
(
integers_ranged
(
-
5
,
5
,
(
2
,
3
),
rng
=
rng
),
integers_ranged
(
-
5
,
5
,
(
2
,
3
),
rng
=
rng
),
),
uint8
=
(
integers_ranged
(
1
,
6
,
(
2
,
3
),
rng
=
rng
)
.
astype
(
"uint8"
),
integers_ranged
(
1
,
6
,
(
2
,
3
),
rng
=
rng
)
.
astype
(
"uint8"
),
),
uint16
=
(
integers_ranged
(
1
,
10
,
(
2
,
3
),
rng
=
rng
)
.
astype
(
"uint16"
),
integers_ranged
(
1
,
10
,
(
2
,
3
),
rng
=
rng
)
.
astype
(
"uint16"
),
),
uint64
=
(
integers_ranged
(
1
,
10
,
(
2
,
3
),
rng
=
rng
)
.
astype
(
"uint64"
),
integers_ranged
(
1
,
10
,
(
2
,
3
),
rng
=
rng
)
.
astype
(
"uint64"
),
),
)
_grad_broadcast_binary_owenst
=
dict
(
normal
=
(
random_ranged
(
-
5
,
5
,
(
2
,
3
),
rng
=
rng
),
random_ranged
(
-
5
,
5
,
(
2
,
3
),
rng
=
rng
),
)
)
TestOwensTBroadcast
=
makeBroadcastTester
(
op
=
at
.
owens_t
,
expected
=
expected_owenst
,
good
=
_good_broadcast_binary_owenst
,
grad
=
_grad_broadcast_binary_owenst
,
eps
=
2e-10
,
mode
=
mode_no_scipy
,
)
TestOwensTInplaceBroadcast
=
makeBroadcastTester
(
op
=
inplace
.
owens_t_inplace
,
expected
=
expected_owenst
,
good
=
_good_broadcast_binary_owenst
,
eps
=
2e-10
,
mode
=
mode_no_scipy
,
inplace
=
True
,
)
rng
=
np
.
random
.
default_rng
(
seed
=
utt
.
fetch_seed
())
_good_broadcast_unary_gammaln
=
dict
(
normal
=
(
random_ranged
(
-
1
+
1e-2
,
10
,
(
2
,
3
),
rng
=
rng
),),
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论