Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
96122d15
提交
96122d15
authored
9月 22, 2025
作者:
ricardoV94
提交者:
Ricardo Vieira
9月 23, 2025
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix backwards compatibility in ScalarOp hash
上级
ee107cba
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
18 行增加
和
3 行删除
+18
-3
basic.py
pytensor/scalar/basic.py
+2
-3
test_basic.py
tests/scalar/test_basic.py
+16
-0
没有找到文件。
pytensor/scalar/basic.py
浏览文件 @
96122d15
...
@@ -1294,13 +1294,12 @@ class ScalarOp(COp):
...
@@ -1294,13 +1294,12 @@ class ScalarOp(COp):
return
self
.
grad
(
inputs
,
output_gradients
)
return
self
.
grad
(
inputs
,
output_gradients
)
def
__eq__
(
self
,
other
):
def
__eq__
(
self
,
other
):
test
=
type
(
self
)
is
type
(
other
)
and
getattr
(
return
type
(
self
)
is
type
(
other
)
and
getattr
(
self
,
"output_types_preference"
,
None
self
,
"output_types_preference"
,
None
)
==
getattr
(
other
,
"output_types_preference"
,
None
)
)
==
getattr
(
other
,
"output_types_preference"
,
None
)
return
test
def
__hash__
(
self
):
def
__hash__
(
self
):
return
hash
((
type
(
self
),
getattr
(
self
,
"output_types_preference"
,
0
)))
return
hash
((
type
(
self
),
getattr
(
self
,
"output_types_preference"
,
None
)))
def
__str__
(
self
):
def
__str__
(
self
):
if
hasattr
(
self
,
"name"
)
and
self
.
name
:
if
hasattr
(
self
,
"name"
)
and
self
.
name
:
...
...
tests/scalar/test_basic.py
浏览文件 @
96122d15
...
@@ -8,6 +8,7 @@ from pytensor.compile.mode import Mode
...
@@ -8,6 +8,7 @@ from pytensor.compile.mode import Mode
from
pytensor.graph.fg
import
FunctionGraph
from
pytensor.graph.fg
import
FunctionGraph
from
pytensor.link.c.basic
import
DualLinker
from
pytensor.link.c.basic
import
DualLinker
from
pytensor.scalar.basic
import
(
from
pytensor.scalar.basic
import
(
EQ
,
ComplexError
,
ComplexError
,
Composite
,
Composite
,
InRange
,
InRange
,
...
@@ -543,3 +544,18 @@ def test_grad_log10():
...
@@ -543,3 +544,18 @@ def test_grad_log10():
b_grad
=
pytensor
.
gradient
.
grad
(
b
,
a
)
b_grad
=
pytensor
.
gradient
.
grad
(
b
,
a
)
assert
b
.
dtype
==
"float32"
assert
b
.
dtype
==
"float32"
assert
b_grad
.
dtype
==
"float32"
assert
b_grad
.
dtype
==
"float32"
def
test_scalar_hash_default_output_type_preference
():
# Old hash used `getattr(self, "output_type_preference", 0)`
# whereas equality used `getattr(self, "output_type_preference", None)`.
# Since 27d797076668fbf0617654fd9b91f92ddb6737e6,
# output_type_preference is always present (None if not specified),
# which led to C-caching errors when comparing old cached Ops and fresh Ops,
# as they evaluated equal but hashed differently
new_eq
=
EQ
()
old_eq
=
EQ
()
del
old_eq
.
output_types_preference
# mimic old Op
assert
new_eq
==
old_eq
assert
hash
(
new_eq
)
==
hash
(
old_eq
)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论