Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
c15933f2
提交
c15933f2
authored
10月 16, 2012
作者:
Razvan Pascanu
提交者:
Razvan Pascanu
10月 31, 2012
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
allow providing dtype to safe_new
上级
ee947ae8
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
11 行增加
和
3 行删除
+11
-3
scan_utils.py
theano/scan_module/scan_utils.py
+11
-3
没有找到文件。
theano/scan_module/scan_utils.py
浏览文件 @
c15933f2
...
@@ -33,7 +33,7 @@ from theano.tensor.basic import get_constant_value
...
@@ -33,7 +33,7 @@ from theano.tensor.basic import get_constant_value
_logger
=
logging
.
getLogger
(
'theano.scan_utils'
)
_logger
=
logging
.
getLogger
(
'theano.scan_utils'
)
def
safe_new
(
x
,
tag
=
''
):
def
safe_new
(
x
,
tag
=
''
,
dtype
=
None
):
"""
"""
Internal function that constructs a new variable from x with the same
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
...
@@ -46,12 +46,18 @@ def safe_new(x, tag=''):
...
@@ -46,12 +46,18 @@ def safe_new(x, tag=''):
else
:
else
:
nw_name
=
None
nw_name
=
None
if
isinstance
(
x
,
theano
.
Constant
):
if
isinstance
(
x
,
theano
.
Constant
):
return
x
.
clone
()
if
dtype
and
x
.
dtype
!=
dtype
:
return
tensor
.
cast
(
x
.
clone
(),
dtype
=
dtype
)
else
:
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 pushout optimization fail
# making the pushout optimization fail
elif
isinstance
(
x
,
scalar
.
ScalarVariable
):
elif
isinstance
(
x
,
scalar
.
ScalarVariable
):
nw_x
=
x
.
type
()
if
dtype
:
new_x
=
scalar
.
Scalar
(
dtype
=
dtype
)()
else
:
nw_x
=
x
.
type
()
nw_x
.
name
=
nw_name
nw_x
.
name
=
nw_name
return
nw_x
return
nw_x
else
:
else
:
...
@@ -63,6 +69,8 @@ def safe_new(x, tag=''):
...
@@ -63,6 +69,8 @@ def safe_new(x, tag=''):
# ndarrays
# ndarrays
pass
pass
nw_x
=
x
.
type
()
nw_x
=
x
.
type
()
if
dtype
and
nw_x
.
dtype
!=
dtype
:
nw_x
=
tensor
.
cast
(
nw_x
,
dtype
=
dtype
)
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
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论