Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
08a58f7b
提交
08a58f7b
authored
10月 01, 2012
作者:
Frederic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
make theano.get_constant_value() to remove theano/gradient.py dependance on the sparse packages.
上级
42b8b66e
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
20 行增加
和
27 行删除
+20
-27
__init__.py
theano/__init__.py
+19
-0
gradient.py
theano/gradient.py
+1
-27
没有找到文件。
theano/__init__.py
浏览文件 @
08a58f7b
...
@@ -161,3 +161,22 @@ def dot(l, r):
...
@@ -161,3 +161,22 @@ def dot(l, r):
raise
NotImplementedError
(
"Dot failed for the following reasons:"
,
raise
NotImplementedError
(
"Dot failed for the following reasons:"
,
(
e0
,
e1
))
(
e0
,
e1
))
return
rval
return
rval
def
get_constant_value
(
v
):
"""return the constant scalar(0-D) value underlying variable `v`
If v is the output of dimshuffles, fills, allocs, rebroadcasts, cast
this function digs through them.
If theano.sparse is also there, we will look over CSM op.
If `v` is not some view of constant data, then raise a TypeError.
"""
if
hasattr
(
theano
,
'sparse'
)
and
isinstance
(
v
.
type
,
theano
.
sparse
.
SparseType
):
if
v
.
owner
is
not
None
and
isinstance
(
v
.
owner
.
op
,
theano
.
sparse
.
CSM
):
data
=
v
.
owner
.
inputs
[
0
]
return
tensor
.
get_constant_value
(
data
)
return
tensor
.
get_constant_value
(
v
)
theano/gradient.py
浏览文件 @
08a58f7b
...
@@ -804,36 +804,11 @@ def _populate_grad_dict(var_to_node_to_idx,
...
@@ -804,36 +804,11 @@ def _populate_grad_dict(var_to_node_to_idx,
no_constant_value
=
True
no_constant_value
=
True
try
:
try
:
constant_value
=
t
ensor
.
get_constant_value
(
term
)
constant_value
=
t
heano
.
get_constant_value
(
term
)
no_constant_value
=
False
no_constant_value
=
False
except
TypeError
:
except
TypeError
:
pass
pass
extra_msg
=
''
# The above won't work if it's a sparse type, handle sparse
# types here
if
no_constant_value
:
if
isinstance
(
term
.
type
,
theano
.
sparse
.
SparseType
):
if
term
.
owner
is
not
None
and
isinstance
(
term
.
owner
.
op
,
theano
.
sparse
.
CSM
):
data
=
term
.
owner
.
inputs
[
0
]
try
:
constant_value
=
tensor
.
get_constant_value
(
data
)
no_constant_value
=
False
except
TypeError
:
print
theano
.
printing
.
min_informative_str
(
data
)
extra_msg
+=
" It is a CSM, but its data isn't constant."
pass
else
:
extra_msg
+=
" It is a SparseType but theano doesn't know how"
extra_msg
+=
" to turn it into a constant."
#end if CSM
else
:
extra_msg
+=
" It is not a SparseType."
#end if SparseType
#end if no_constant_value
if
no_constant_value
:
if
no_constant_value
:
msg
=
"
%
s.grad returned
%
s of type
%
s for input"
msg
=
"
%
s.grad returned
%
s of type
%
s for input"
msg
+=
"
%
d. This input's only connections to "
msg
+=
"
%
d. This input's only connections to "
...
@@ -844,7 +819,6 @@ def _populate_grad_dict(var_to_node_to_idx,
...
@@ -844,7 +819,6 @@ def _populate_grad_dict(var_to_node_to_idx,
msg
+=
"DisconnectedType and theano can't "
msg
+=
"DisconnectedType and theano can't "
msg
+=
"simplify it to a constant, so it's not "
msg
+=
"simplify it to a constant, so it's not "
msg
+=
"verifiably zeros."
msg
+=
"verifiably zeros."
msg
+=
extra_msg
msg
=
msg
%
(
str
(
node
.
op
),
str
(
term
),
msg
=
msg
%
(
str
(
node
.
op
),
str
(
term
),
str
(
type
(
term
)),
i
)
str
(
type
(
term
)),
i
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论