Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
16add309
提交
16add309
authored
9月 24, 2012
作者:
nouiz
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #946 from goodfeli/type_check
add some type checking
上级
6657d35b
c509ad31
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
16 行增加
和
2 行删除
+16
-2
op.txt
doc/extending/op.txt
+6
-2
gradient.py
theano/gradient.py
+10
-0
没有找到文件。
doc/extending/op.txt
浏览文件 @
16add309
...
@@ -109,7 +109,7 @@ following methods:
...
@@ -109,7 +109,7 @@ following methods:
elements of inputs[input_idx] have an effect on the elements of
elements of inputs[input_idx] have an effect on the elements of
outputs[output_idx].
outputs[output_idx].
The ``node
''
parameter is needed to determine the number of
The ``node
``
parameter is needed to determine the number of
inputs. Some ops such as Subtensor take a variable number of
inputs. Some ops such as Subtensor take a variable number of
inputs.
inputs.
...
@@ -159,7 +159,11 @@ following methods:
...
@@ -159,7 +159,11 @@ following methods:
If the output is not differentiable with respect to an input
If the output is not differentiable with respect to an input
then this method should be defined to return a variable of type
then this method should be defined to return a variable of type
NullType for that input.
NullType for that input. Likewise, if you have not implemented the
grad computation for some input, you may return a variable of type
NullType for that input. theano.gradient contains convenience methods
that can construct the variable for you: :func:`theano.gradient.grad_undefined` and
:func:`theano.gradient.grad_not_implemented`, respectively.
If an element of output_gradient is of type theano.gradient.DisconnectedType,
If an element of output_gradient is of type theano.gradient.DisconnectedType,
it means that the cost is not a function of this output. If any of the
it means that the cost is not a function of this output. If any of the
...
...
theano/gradient.py
浏览文件 @
16add309
...
@@ -446,11 +446,21 @@ def grad(cost, wrt, g_cost=None, consider_constant=None,
...
@@ -446,11 +446,21 @@ def grad(cost, wrt, g_cost=None, consider_constant=None,
raise
TypeError
(
'Elements of consider_constant must be '
raise
TypeError
(
'Elements of consider_constant must be '
'variables, but got '
+
str
(
type
(
elem
)))
'variables, but got '
+
str
(
type
(
elem
)))
if
isinstance
(
wrt
,
set
):
raise
TypeError
(
"wrt must not be a set. sets have no defined "
"iteration order, so we can't return gradients in a matching"
" order."
)
using_list
=
isinstance
(
wrt
,
list
)
using_list
=
isinstance
(
wrt
,
list
)
using_tuple
=
isinstance
(
wrt
,
tuple
)
using_tuple
=
isinstance
(
wrt
,
tuple
)
if
not
using_list
and
not
using_tuple
:
if
not
using_list
and
not
using_tuple
:
wrt
=
[
wrt
]
wrt
=
[
wrt
]
for
elem
in
wrt
:
if
not
isinstance
(
elem
,
Variable
):
raise
TypeError
(
"Expected Variable, got "
+
str
(
elem
)
+
" of type "
+
str
(
type
(
elem
)))
var_to_node_to_idx
=
_populate_var_to_node_to_idx
([
cost
],
wrt
)
var_to_node_to_idx
=
_populate_var_to_node_to_idx
([
cost
],
wrt
)
# build a dict mapping var to the gradient of cost with respect to var
# build a dict mapping var to the gradient of cost with respect to var
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论