Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
7092f551
提交
7092f551
authored
8月 27, 2025
作者:
ricardoV94
提交者:
Ricardo Vieira
8月 28, 2025
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Cleanup imports in graph/rewriting/basic.py
上级
2d46d60e
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
11 行增加
和
16 行删除
+11
-16
basic.py
pytensor/graph/rewriting/basic.py
+11
-16
没有找到文件。
pytensor/graph/rewriting/basic.py
浏览文件 @
7092f551
...
...
@@ -13,9 +13,8 @@ from collections import Counter, UserList, defaultdict, deque
from
collections.abc
import
Callable
,
Iterable
,
Sequence
from
functools
import
_compose_mro
,
partial
# type: ignore
from
itertools
import
chain
from
typing
import
TYPE_CHECKING
,
Literal
from
typing
import
Literal
import
pytensor
from
pytensor.configdefaults
import
config
from
pytensor.graph
import
destroyhandler
as
dh
from
pytensor.graph.basic
import
(
...
...
@@ -30,15 +29,12 @@ from pytensor.graph.basic import (
from
pytensor.graph.features
import
AlreadyThere
,
Feature
from
pytensor.graph.fg
import
FunctionGraph
,
Output
from
pytensor.graph.op
import
Op
from
pytensor.graph.rewriting.unify
import
Var
,
convert_strs_to_vars
from
pytensor.graph.utils
import
AssocList
,
InconsistencyError
from
pytensor.misc.ordered_set
import
OrderedSet
from
pytensor.utils
import
flatten
if
TYPE_CHECKING
:
from
pytensor.graph.rewriting.unify
import
Var
_logger
=
logging
.
getLogger
(
"pytensor.graph.rewriting.basic"
)
RemoveKeyType
=
Literal
[
"remove"
]
...
...
@@ -1406,8 +1402,6 @@ class PatternNodeRewriter(NodeRewriter):
frequent `Op`, which will prevent the rewrite from being tried as often.
"""
from
pytensor.graph.rewriting.unify
import
convert_strs_to_vars
var_map
:
dict
[
str
,
Var
]
=
{}
self
.
in_pattern
=
convert_strs_to_vars
(
in_pattern
,
var_map
=
var_map
)
self
.
out_pattern
=
convert_strs_to_vars
(
out_pattern
,
var_map
=
var_map
)
...
...
@@ -1449,9 +1443,6 @@ class PatternNodeRewriter(NodeRewriter):
if
ret
is
not
False
and
ret
is
not
None
:
return
dict
(
zip
(
real_node
.
outputs
,
ret
,
strict
=
True
))
if
node
.
op
!=
self
.
op
:
return
False
if
len
(
node
.
outputs
)
!=
1
:
# PatternNodeRewriter doesn't support replacing multi-output nodes
return
False
...
...
@@ -1480,11 +1471,13 @@ class PatternNodeRewriter(NodeRewriter):
[
old_out
]
=
node
.
outputs
if
not
old_out
.
type
.
is_super
(
ret
.
type
):
from
pytensor.tensor.type
import
TensorType
# Type doesn't match
if
not
(
self
.
allow_cast
and
isinstance
(
old_out
.
type
,
pytensor
.
tensor
.
TensorType
)
and
isinstance
(
ret
.
type
,
pytensor
.
tensor
.
TensorType
)
and
isinstance
(
old_out
.
type
,
TensorType
)
and
isinstance
(
ret
.
type
,
TensorType
)
):
return
False
...
...
@@ -2736,10 +2729,12 @@ def check_stack_trace(f_or_fgraph, ops_to_check="last", bug_print="raise"):
otherwise.
"""
if
isinstance
(
f_or_fgraph
,
pytensor
.
compile
.
function
.
types
.
Function
):
fgraph
=
f_or_fgraph
.
maker
.
fgraph
elif
isinstance
(
f_or_fgraph
,
pytensor
.
graph
.
fg
.
FunctionGraph
):
from
pytensor.compile.function.types
import
Function
if
isinstance
(
f_or_fgraph
,
FunctionGraph
):
fgraph
=
f_or_fgraph
elif
isinstance
(
f_or_fgraph
,
Function
):
fgraph
=
f_or_fgraph
.
maker
.
fgraph
else
:
raise
ValueError
(
"The type of f_or_fgraph is not supported"
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论