Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
5aa17801
提交
5aa17801
authored
11月 01, 2022
作者:
Will Dean
提交者:
Rémi Louf
11月 19, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add name argument to clone methods via kwargs
上级
ac5fb058
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
31 行增加
和
12 行删除
+31
-12
sharedvalue.py
aesara/compile/sharedvalue.py
+3
-2
basic.py
aesara/graph/basic.py
+22
-10
test_basic.py
tests/graph/test_basic.py
+6
-0
没有找到文件。
aesara/compile/sharedvalue.py
浏览文件 @
5aa17801
...
...
@@ -167,9 +167,10 @@ class SharedVariable(Variable):
else
:
self
.
container
.
value
=
0
*
self
.
container
.
value
def
clone
(
self
):
def
clone
(
self
,
**
kwargs
):
name
=
kwargs
.
get
(
"name"
,
self
.
name
)
cp
=
self
.
__class__
(
name
=
self
.
name
,
name
=
name
,
type
=
self
.
type
,
value
=
None
,
strict
=
None
,
...
...
aesara/graph/basic.py
浏览文件 @
5aa17801
...
...
@@ -510,9 +510,14 @@ class Variable(Node, Generic[_TypeType, OptionalApplyType]):
pass
return
"
\n
"
.
join
(
to_print
)
def
clone
(
self
):
def
clone
(
self
,
**
kwargs
):
"""Return a new, un-owned `Variable` like `self`.
Parameters
----------
**kwargs : dict
Optional "name" keyword argument for the copied instance. Same as `self.name` if value not provided.
Returns
-------
Variable instance
...
...
@@ -523,7 +528,8 @@ class Variable(Node, Generic[_TypeType, OptionalApplyType]):
Tags and names are copied to the returned instance.
"""
cp
=
self
.
__class__
(
self
.
type
,
None
,
None
,
self
.
name
)
name
=
kwargs
.
pop
(
"name"
,
self
.
name
)
cp
=
self
.
__class__
(
type
=
self
.
type
,
owner
=
None
,
index
=
None
,
name
=
name
,
**
kwargs
)
cp
.
tag
=
copy
(
self
.
tag
)
return
cp
...
...
@@ -621,8 +627,8 @@ class Variable(Node, Generic[_TypeType, OptionalApplyType]):
class
AtomicVariable
(
Variable
[
_TypeType
,
None
]):
"""A node type that has no ancestors and should never be considered an input to a graph."""
def
__init__
(
self
,
type
:
_TypeType
,
**
kwargs
):
super
()
.
__init__
(
type
,
None
,
Non
e
,
**
kwargs
)
def
__init__
(
self
,
type
:
_TypeType
,
name
:
Optional
[
str
]
=
None
,
**
kwargs
):
super
()
.
__init__
(
type
=
type
,
owner
=
None
,
index
=
None
,
name
=
nam
e
,
**
kwargs
)
@abc.abstractmethod
def
signature
(
self
):
...
...
@@ -656,6 +662,12 @@ class AtomicVariable(Variable[_TypeType, None]):
if
value
is
not
None
:
raise
ValueError
(
"AtomicVariable instances cannot have an index."
)
def
clone
(
self
,
**
kwargs
):
name
=
kwargs
.
pop
(
"name"
,
self
.
name
)
cp
=
self
.
__class__
(
type
=
self
.
type
,
name
=
name
,
**
kwargs
)
cp
.
tag
=
copy
(
self
.
tag
)
return
cp
class
NominalVariable
(
AtomicVariable
[
_TypeType
]):
"""A variable that enables alpha-equivalent comparisons."""
...
...
@@ -682,12 +694,13 @@ class NominalVariable(AtomicVariable[_TypeType]):
return
cls
.
__instances__
[(
typ
,
id
)]
def
__init__
(
self
,
id
:
_IdType
,
typ
:
_TypeType
,
**
kwargs
):
def
__init__
(
self
,
id
:
_IdType
,
typ
:
_TypeType
,
name
:
Optional
[
str
]
=
None
):
self
.
id
=
id
super
()
.
__init__
(
typ
,
**
kwargs
)
super
()
.
__init__
(
typ
e
=
typ
,
name
=
name
)
def
clone
(
self
):
return
self
def
clone
(
self
,
**
kwargs
):
name
=
kwargs
.
pop
(
"name"
,
self
.
name
)
return
self
.
__class__
(
id
=
self
.
id
,
typ
=
self
.
type
,
name
=
name
,
**
kwargs
)
def
__eq__
(
self
,
other
):
if
self
is
other
:
...
...
@@ -744,8 +757,7 @@ class Constant(AtomicVariable[_TypeType]):
name
=
name
[:
10
]
+
"..."
+
name
[
-
10
:]
return
f
"{type(self).__name__}{{{name}}}"
def
clone
(
self
):
"""Return `self`, because there's no reason to clone a constant."""
def
clone
(
self
,
**
kwargs
):
return
self
@property
...
...
tests/graph/test_basic.py
浏览文件 @
5aa17801
...
...
@@ -354,6 +354,12 @@ class TestAutoName:
assert
r1
.
auto_name
==
"auto_"
+
str
(
autoname_id
)
assert
r2
.
auto_name
==
"auto_"
+
str
(
autoname_id
+
1
)
assert
r1
.
name
is
None
and
r1
.
name
is
r2
.
name
r3_name
=
"r3"
r3
=
r1
.
clone
(
name
=
r3_name
)
assert
r3
.
name
==
r3_name
def
test_equal_computations
():
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论