Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
4fa6c415
提交
4fa6c415
authored
10月 28, 2021
作者:
Brandon T. Willard
提交者:
Brandon T. Willard
11月 18, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Clean up comments and annotations in aesara.scan.utils.safe_new
上级
47cc3474
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
13 行增加
和
10 行删除
+13
-10
utils.py
aesara/scan/utils.py
+13
-10
没有找到文件。
aesara/scan/utils.py
浏览文件 @
4fa6c415
...
@@ -34,11 +34,14 @@ if TYPE_CHECKING:
...
@@ -34,11 +34,14 @@ if TYPE_CHECKING:
_logger
=
logging
.
getLogger
(
"aesara.scan.utils"
)
_logger
=
logging
.
getLogger
(
"aesara.scan.utils"
)
def
safe_new
(
x
,
tag
=
""
,
dtype
=
None
):
def
safe_new
(
"""
x
:
Variable
,
tag
:
str
=
""
,
dtype
:
Optional
[
Union
[
str
,
np
.
dtype
]]
=
None
Internal function that constructs a new variable from x with the same
)
->
Variable
:
"""Clone variables.
Internal function that constructs a new variable from `x` with the same
type, but with a different name (old name + tag). This function is used
type, but with a different name (old name + tag). This function is used
by
gradient
, or the R-op to construct new variables for the inputs of
by
`gradient`
, or the R-op to construct new variables for the inputs of
the inner graph such that there is no interference between the original
the inner graph such that there is no interference between the original
graph and the newly constructed graph.
graph and the newly constructed graph.
...
@@ -51,14 +54,14 @@ def safe_new(x, tag="", dtype=None):
...
@@ -51,14 +54,14 @@ def safe_new(x, tag="", dtype=None):
if
isinstance
(
x
,
Constant
):
if
isinstance
(
x
,
Constant
):
if
dtype
and
x
.
dtype
!=
dtype
:
if
dtype
and
x
.
dtype
!=
dtype
:
casted_x
=
x
.
astype
(
dtype
)
casted_x
=
x
.
astype
(
dtype
)
nwx
=
x
.
__class__
(
casted_x
.
type
,
x
.
data
,
x
.
name
)
nwx
=
type
(
x
)
(
casted_x
.
type
,
x
.
data
,
x
.
name
)
nwx
.
tag
=
copy
.
copy
(
x
.
tag
)
nwx
.
tag
=
copy
.
copy
(
x
.
tag
)
return
nwx
return
nwx
else
:
else
:
return
x
.
clone
()
return
x
.
clone
()
# 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,
#
`TensorScalar` that will require a `ScalarFromTensor` `Op`, making the
#
making the push
out optimization fail
#
push-
out optimization fail
elif
isinstance
(
x
,
aes
.
ScalarVariable
):
elif
isinstance
(
x
,
aes
.
ScalarVariable
):
if
dtype
:
if
dtype
:
nw_x
=
aes
.
get_scalar_type
(
dtype
=
dtype
)()
nw_x
=
aes
.
get_scalar_type
(
dtype
=
dtype
)()
...
@@ -82,13 +85,13 @@ def safe_new(x, tag="", dtype=None):
...
@@ -82,13 +85,13 @@ def safe_new(x, tag="", dtype=None):
# This could happen for example for random states
# This could happen for example for random states
pass
pass
# Cast
x if needed. If x
has a test value, this will also cast it.
# Cast
`x` if needed. If `x`
has a test value, this will also cast it.
if
dtype
and
x
.
dtype
!=
dtype
:
if
dtype
and
x
.
dtype
!=
dtype
:
x
=
x
.
astype
(
dtype
)
x
=
x
.
astype
(
dtype
)
nw_x
=
x
.
type
()
nw_x
=
x
.
type
()
nw_x
.
name
=
nw_name
nw_x
.
name
=
nw_name
# Preserve test values so that the
'compute_test_value'
option can be used.
# Preserve test values so that the
`compute_test_value`
option can be used.
# The test value is deep-copied to ensure there can be no interactions
# The test value is deep-copied to ensure there can be no interactions
# between test values, due to inplace operations for instance. This may
# between test values, due to inplace operations for instance. This may
# not be the most efficient memory-wise, though.
# not be the most efficient memory-wise, though.
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论