Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
d03c8431
提交
d03c8431
authored
2月 11, 2022
作者:
Brandon T. Willard
提交者:
Brandon T. Willard
2月 22, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Stop some unnecessary Constant cloning
上级
dd6da53d
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
6 行增加
和
19 行删除
+6
-19
basic.py
aesara/graph/basic.py
+2
-9
utils.py
aesara/scan/utils.py
+2
-8
test_basic.py
tests/graph/test_basic.py
+2
-2
没有找到文件。
aesara/graph/basic.py
浏览文件 @
d03c8431
...
@@ -603,15 +603,8 @@ class Constant(Variable):
...
@@ -603,15 +603,8 @@ class Constant(Variable):
return
f
"{type(self).__name__}{{{name}}}"
return
f
"{type(self).__name__}{{{name}}}"
def
clone
(
self
):
def
clone
(
self
):
"""Create a shallow clone.
"""Return `self`, because there's no reason to clone a constant."""
return
self
We clone this object, but we don't clone the data to lower memory
requirement. We suppose that the data will never change.
"""
cp
=
self
.
__class__
(
self
.
type
,
self
.
data
,
self
.
name
)
cp
.
tag
=
copy
(
self
.
tag
)
return
cp
def
__set_owner
(
self
,
value
):
def
__set_owner
(
self
,
value
):
"""Prevent the :prop:`owner` property from being set.
"""Prevent the :prop:`owner` property from being set.
...
...
aesara/scan/utils.py
浏览文件 @
d03c8431
...
@@ -61,7 +61,7 @@ def safe_new(
...
@@ -61,7 +61,7 @@ def safe_new(
nwx
.
tag
=
copy
.
copy
(
x
.
tag
)
nwx
.
tag
=
copy
.
copy
(
x
.
tag
)
return
nwx
return
nwx
else
:
else
:
return
x
.
clone
()
return
x
# Note, `as_tensor_variable` will convert the `Scalar` into a
# Note, `as_tensor_variable` will convert the `Scalar` into a
# `TensorScalar` that will require a `ScalarFromTensor` `Op`, making the
# `TensorScalar` that will require a `ScalarFromTensor` `Op`, making the
# push-out optimization fail
# push-out optimization fail
...
@@ -697,14 +697,8 @@ def reconstruct_graph(inputs, outputs, tag=None):
...
@@ -697,14 +697,8 @@ def reconstruct_graph(inputs, outputs, tag=None):
if
tag
is
None
:
if
tag
is
None
:
tag
=
""
tag
=
""
nw_inputs
=
[
safe_new
(
x
,
tag
)
for
x
in
inputs
]
nw_inputs
=
[
safe_new
(
x
,
tag
)
for
x
in
inputs
]
givens
=
OrderedDict
()
for
nw_x
,
x
in
zip
(
nw_inputs
,
inputs
):
givens
[
x
]
=
nw_x
allinputs
=
list
(
graph_inputs
(
outputs
))
for
inp
in
allinputs
:
if
isinstance
(
inp
,
Constant
):
givens
[
inp
]
=
inp
.
clone
()
givens
=
{
x
:
nw_x
for
nw_x
,
x
in
zip
(
nw_inputs
,
inputs
)}
nw_outputs
=
clone_replace
(
outputs
,
replace
=
givens
)
nw_outputs
=
clone_replace
(
outputs
,
replace
=
givens
)
return
(
nw_inputs
,
nw_outputs
)
return
(
nw_inputs
,
nw_outputs
)
...
...
tests/graph/test_basic.py
浏览文件 @
d03c8431
...
@@ -200,13 +200,13 @@ class TestClone(X):
...
@@ -200,13 +200,13 @@ class TestClone(X):
c1
=
at
.
constant
(
1.5
)
c1
=
at
.
constant
(
1.5
)
i
,
o
=
clone
([
c1
],
[
c1
])
i
,
o
=
clone
([
c1
],
[
c1
])
assert
i
[
0
]
is
not
c1
and
o
[
0
]
is
not
c1
assert
i
[
0
]
is
c1
and
o
[
0
]
is
c1
i
,
o
=
clone
([
c1
],
[
c1
],
False
)
i
,
o
=
clone
([
c1
],
[
c1
],
False
)
assert
i
[
0
]
is
c1
and
o
[
0
]
is
c1
assert
i
[
0
]
is
c1
and
o
[
0
]
is
c1
i
,
o
=
clone
([
c1
],
[
c1
],
True
,
False
)
i
,
o
=
clone
([
c1
],
[
c1
],
True
,
False
)
assert
i
[
0
]
is
not
c1
and
o
[
0
]
is
not
c1
assert
i
[
0
]
is
c1
and
o
[
0
]
is
c1
i
,
o
=
clone
([
c1
],
[
c1
],
False
,
True
)
i
,
o
=
clone
([
c1
],
[
c1
],
False
,
True
)
assert
i
[
0
]
is
c1
and
o
[
0
]
is
c1
assert
i
[
0
]
is
c1
and
o
[
0
]
is
c1
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论