Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
db673f0d
提交
db673f0d
authored
5月 24, 2023
作者:
Ricardo Vieira
提交者:
Ricardo Vieira
5月 24, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix mixed dtype bug in gammaincc_grad
上级
53b00ea6
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
36 行增加
和
1 行删除
+36
-1
math.py
pytensor/scalar/math.py
+1
-1
test_math.py
tests/scalar/test_math.py
+35
-0
没有找到文件。
pytensor/scalar/math.py
浏览文件 @
db673f0d
...
@@ -854,7 +854,7 @@ def gammaincc_grad(k, x, skip_loops=constant(False, dtype="bool")):
...
@@ -854,7 +854,7 @@ def gammaincc_grad(k, x, skip_loops=constant(False, dtype="bool")):
log_s
=
np
.
array
(
0.0
,
dtype
=
dtype
)
log_s
=
np
.
array
(
0.0
,
dtype
=
dtype
)
s_sign
=
np
.
array
(
1
,
dtype
=
"int8"
)
s_sign
=
np
.
array
(
1
,
dtype
=
"int8"
)
n
=
np
.
array
(
1
,
dtype
=
"int32"
)
n
=
np
.
array
(
1
,
dtype
=
"int32"
)
log_delta
=
log_s
-
2
*
log
(
k
)
log_delta
=
log_s
-
2
*
log
(
k
)
.
astype
(
dtype
)
def
inner_loop_b
(
sum_b
,
log_s
,
s_sign
,
log_delta
,
n
,
k
,
log_x
):
def
inner_loop_b
(
sum_b
,
log_s
,
s_sign
,
log_delta
,
n
,
k
,
log_x
):
delta
=
exp
(
log_delta
)
delta
=
exp
(
log_delta
)
...
...
tests/scalar/test_math.py
浏览文件 @
db673f0d
import
itertools
import
numpy
as
np
import
numpy
as
np
import
pytest
import
scipy.special
as
sp
import
scipy.special
as
sp
import
pytensor.tensor
as
at
import
pytensor.tensor
as
at
from
pytensor
import
function
from
pytensor
import
function
from
pytensor.compile.mode
import
Mode
from
pytensor.compile.mode
import
Mode
from
pytensor.graph
import
ancestors
from
pytensor.graph.fg
import
FunctionGraph
from
pytensor.graph.fg
import
FunctionGraph
from
pytensor.link.c.basic
import
CLinker
from
pytensor.link.c.basic
import
CLinker
from
pytensor.scalar
import
ScalarLoop
,
float32
,
float64
,
int32
from
pytensor.scalar.math
import
(
from
pytensor.scalar.math
import
(
betainc
,
betainc
,
betainc_grad
,
betainc_grad
,
...
@@ -13,6 +18,7 @@ from pytensor.scalar.math import (
...
@@ -13,6 +18,7 @@ from pytensor.scalar.math import (
gammaincc
,
gammaincc
,
gammal
,
gammal
,
gammau
,
gammau
,
hyp2f1
,
)
)
from
tests.link.test_link
import
make_function
from
tests.link.test_link
import
make_function
...
@@ -89,3 +95,32 @@ def test_betainc_derivative_nan():
...
@@ -89,3 +95,32 @@ def test_betainc_derivative_nan():
assert
np
.
isnan
(
test_func
(
1
,
1
,
2
))
assert
np
.
isnan
(
test_func
(
1
,
1
,
2
))
assert
np
.
isnan
(
test_func
(
1
,
-
1
,
1
))
assert
np
.
isnan
(
test_func
(
1
,
-
1
,
1
))
assert
np
.
isnan
(
test_func
(
1
,
1
,
-
1
))
assert
np
.
isnan
(
test_func
(
1
,
1
,
-
1
))
@pytest.mark.parametrize
(
"op, scalar_loop_grads"
,
[
(
gammainc
,
[
0
]),
(
gammaincc
,
[
0
]),
(
betainc
,
[
0
,
1
]),
(
hyp2f1
,
[
0
,
1
,
2
]),
],
)
def
test_scalarloop_grad_mixed_dtypes
(
op
,
scalar_loop_grads
):
nin
=
op
.
nin
for
types
in
itertools
.
product
((
float32
,
float64
,
int32
),
repeat
=
nin
):
inputs
=
[
type
()
for
type
in
types
]
out
=
op
(
*
inputs
)
wrt
=
[
inp
for
idx
,
inp
in
enumerate
(
inputs
)
if
idx
in
scalar_loop_grads
and
inp
.
type
.
dtype
.
startswith
(
"float"
)
]
if
not
wrt
:
continue
# The ScalarLoop in the graph will fail if the input types are different from the updates
grad
=
at
.
grad
(
out
,
wrt
=
wrt
)
assert
any
(
(
var
.
owner
and
isinstance
(
var
.
owner
.
op
,
ScalarLoop
))
for
var
in
ancestors
(
grad
)
)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论