Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
3ce065e3
提交
3ce065e3
authored
8月 28, 2012
作者:
Ian Goodfellow
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
got rid of generics in gradient tests, only types with a zeros_like are
supported now
上级
c811c88f
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
35 行增加
和
35 行删除
+35
-35
test_gradient.py
theano/tests/test_gradient.py
+35
-35
没有找到文件。
theano/tests/test_gradient.py
浏览文件 @
3ce065e3
...
@@ -21,8 +21,8 @@ class test_grad_sources_inputs(unittest.TestCase):
...
@@ -21,8 +21,8 @@ class test_grad_sources_inputs(unittest.TestCase):
"""Test that it is not ok to return None from op.grad()"""
"""Test that it is not ok to return None from op.grad()"""
class
retNone
(
gof
.
op
.
Op
):
class
retNone
(
gof
.
op
.
Op
):
def
make_node
(
self
):
def
make_node
(
self
):
inputs
=
[
gof
.
generic
()]
inputs
=
[
theano
.
tensor
.
vector
()]
outputs
=
[
gof
.
generic
()]
outputs
=
[
theano
.
tensor
.
vector
()]
return
gof
.
Apply
(
self
,
inputs
,
outputs
)
return
gof
.
Apply
(
self
,
inputs
,
outputs
)
def
grad
(
self
,
inp
,
grads
):
def
grad
(
self
,
inp
,
grads
):
x
,
=
inp
x
,
=
inp
...
@@ -39,11 +39,11 @@ class test_grad_sources_inputs(unittest.TestCase):
...
@@ -39,11 +39,11 @@ class test_grad_sources_inputs(unittest.TestCase):
"""Test that it is ok to return [None] from op.grad()"""
"""Test that it is ok to return [None] from op.grad()"""
class
retNone
(
gof
.
op
.
Op
):
class
retNone
(
gof
.
op
.
Op
):
def
make_node
(
self
,
*
inputs
):
def
make_node
(
self
,
*
inputs
):
outputs
=
[
gof
.
generic
()]
outputs
=
[
theano
.
tensor
.
matrix
()]
return
gof
.
Apply
(
self
,
inputs
,
outputs
)
return
gof
.
Apply
(
self
,
inputs
,
outputs
)
def
grad
(
self
,
inp
,
grads
):
def
grad
(
self
,
inp
,
grads
):
return
[
None
]
return
[
None
]
i
=
gof
.
generic
()
i
=
theano
.
tensor
.
matrix
()
a
=
retNone
()
.
make_node
(
i
)
a
=
retNone
()
.
make_node
(
i
)
g
=
_grad_sources_inputs
([(
a
.
out
,
1
)],
None
)
g
=
_grad_sources_inputs
([(
a
.
out
,
1
)],
None
)
self
.
assertTrue
(
not
i
in
g
)
self
.
assertTrue
(
not
i
in
g
)
...
@@ -52,13 +52,13 @@ class test_grad_sources_inputs(unittest.TestCase):
...
@@ -52,13 +52,13 @@ class test_grad_sources_inputs(unittest.TestCase):
"""Test that it is not ok to return the wrong number of gradients"""
"""Test that it is not ok to return the wrong number of gradients"""
class
retNone
(
gof
.
op
.
Op
):
class
retNone
(
gof
.
op
.
Op
):
def
make_node
(
self
,
*
inputs
):
def
make_node
(
self
,
*
inputs
):
outputs
=
[
gof
.
generic
()]
outputs
=
[
theano
.
tensor
.
vector
()]
return
gof
.
Apply
(
self
,
inputs
,
outputs
)
return
gof
.
Apply
(
self
,
inputs
,
outputs
)
def
grad
(
self
,
inputs
,
grads
):
def
grad
(
self
,
inputs
,
grads
):
return
[
None
]
return
[
None
]
i
=
gof
.
generic
()
i
=
theano
.
tensor
.
vector
()
j
=
gof
.
generic
()
j
=
theano
.
tensor
.
vector
()
a1
=
retNone
()
.
make_node
(
i
)
a1
=
retNone
()
.
make_node
(
i
)
g
=
_grad_sources_inputs
([(
a1
.
out
,
1
)],
None
)
g
=
_grad_sources_inputs
([(
a1
.
out
,
1
)],
None
)
a2
=
retNone
()
.
make_node
(
i
,
j
)
a2
=
retNone
()
.
make_node
(
i
,
j
)
...
@@ -71,11 +71,11 @@ class test_grad_sources_inputs(unittest.TestCase):
...
@@ -71,11 +71,11 @@ class test_grad_sources_inputs(unittest.TestCase):
def
test_1in_1out
(
self
):
def
test_1in_1out
(
self
):
"""Test grad is called correctly for a 1-to-1 op"""
"""Test grad is called correctly for a 1-to-1 op"""
gval
=
gof
.
generic
()
gval
=
theano
.
tensor
.
matrix
()
class
O
(
gof
.
op
.
Op
):
class
O
(
gof
.
op
.
Op
):
def
make_node
(
self
):
def
make_node
(
self
):
inputs
=
[
gof
.
generic
()]
inputs
=
[
theano
.
tensor
.
matrix
()]
outputs
=
[
gof
.
generic
()]
outputs
=
[
theano
.
tensor
.
matrix
()]
return
gof
.
Apply
(
self
,
inputs
,
outputs
)
return
gof
.
Apply
(
self
,
inputs
,
outputs
)
def
grad
(
self
,
inp
,
grads
):
def
grad
(
self
,
inp
,
grads
):
return
gval
,
return
gval
,
...
@@ -85,11 +85,11 @@ class test_grad_sources_inputs(unittest.TestCase):
...
@@ -85,11 +85,11 @@ class test_grad_sources_inputs(unittest.TestCase):
def
test_1in_Nout
(
self
):
def
test_1in_Nout
(
self
):
"""Test grad is called correctly for a 1-to-many op"""
"""Test grad is called correctly for a 1-to-many op"""
gval
=
gof
.
generic
()
gval
=
theano
.
tensor
.
matrix
()
class
O
(
gof
.
op
.
Op
):
class
O
(
gof
.
op
.
Op
):
def
make_node
(
self
):
def
make_node
(
self
):
inputs
=
[
gof
.
generic
()]
inputs
=
[
theano
.
tensor
.
matrix
()]
outputs
=
[
gof
.
generic
(),
gof
.
generic
()]
outputs
=
[
theano
.
tensor
.
scalar
(),
theano
.
tensor
.
scalar
()]
return
gof
.
Apply
(
self
,
inputs
,
outputs
)
return
gof
.
Apply
(
self
,
inputs
,
outputs
)
def
grad
(
self
,
inp
,
grads
):
def
grad
(
self
,
inp
,
grads
):
x
,
=
inp
x
,
=
inp
...
@@ -101,12 +101,12 @@ class test_grad_sources_inputs(unittest.TestCase):
...
@@ -101,12 +101,12 @@ class test_grad_sources_inputs(unittest.TestCase):
def
test_Nin_1out
(
self
):
def
test_Nin_1out
(
self
):
"""Test grad is called correctly for a many-to-1 op"""
"""Test grad is called correctly for a many-to-1 op"""
gval0
=
gof
.
generic
()
gval0
=
theano
.
tensor
.
scalar
()
gval1
=
gof
.
generic
()
gval1
=
theano
.
tensor
.
scalar
()
class
O
(
gof
.
op
.
Op
):
class
O
(
gof
.
op
.
Op
):
def
make_node
(
self
):
def
make_node
(
self
):
inputs
=
[
gof
.
generic
(),
gof
.
generic
()]
inputs
=
[
theano
.
tensor
.
scalar
(),
theano
.
tensor
.
scalar
()]
outputs
=
[
gof
.
generic
()]
outputs
=
[
theano
.
tensor
.
matrix
()]
return
gof
.
Apply
(
self
,
inputs
,
outputs
)
return
gof
.
Apply
(
self
,
inputs
,
outputs
)
def
grad
(
self
,
inp
,
grads
):
def
grad
(
self
,
inp
,
grads
):
x0
,
x1
=
inp
x0
,
x1
=
inp
...
@@ -119,12 +119,12 @@ class test_grad_sources_inputs(unittest.TestCase):
...
@@ -119,12 +119,12 @@ class test_grad_sources_inputs(unittest.TestCase):
def
test_Nin_Nout
(
self
):
def
test_Nin_Nout
(
self
):
"""Test grad is called correctly for a many-to-many op"""
"""Test grad is called correctly for a many-to-many op"""
gval0
=
gof
.
generic
()
gval0
=
theano
.
tensor
.
matrix
()
gval1
=
gof
.
generic
()
gval1
=
theano
.
tensor
.
matrix
()
class
O
(
gof
.
op
.
Op
):
class
O
(
gof
.
op
.
Op
):
def
make_node
(
self
):
def
make_node
(
self
):
inputs
=
[
gof
.
generic
(),
gof
.
generic
()]
inputs
=
[
theano
.
tensor
.
matrix
(),
theano
.
tensor
.
matrix
()]
outputs
=
[
gof
.
generic
(),
gof
.
generic
()]
outputs
=
[
theano
.
tensor
.
matrix
(),
theano
.
tensor
.
matrix
()]
return
gof
.
Apply
(
self
,
inputs
,
outputs
)
return
gof
.
Apply
(
self
,
inputs
,
outputs
)
def
grad
(
self
,
inp
,
grads
):
def
grad
(
self
,
inp
,
grads
):
return
gval0
,
gval1
return
gval0
,
gval1
...
@@ -139,11 +139,11 @@ class test_grad_sources_inputs(unittest.TestCase):
...
@@ -139,11 +139,11 @@ class test_grad_sources_inputs(unittest.TestCase):
def
__init__
(
self
,
tst
):
def
__init__
(
self
,
tst
):
self
.
tst
=
tst
self
.
tst
=
tst
def
make_node
(
self
,
*
inputs
):
def
make_node
(
self
,
*
inputs
):
outputs
=
[
gof
.
generic
(),
gof
.
generic
()]
outputs
=
[
theano
.
tensor
.
matrix
(),
theano
.
tensor
.
matrix
()]
return
gof
.
Apply
(
self
,
inputs
,
outputs
)
return
gof
.
Apply
(
self
,
inputs
,
outputs
)
def
grad
(
self
,
inputs
,
g_out
):
def
grad
(
self
,
inputs
,
g_out
):
return
[
1
]
return
[
1
]
i
=
gof
.
generic
()
i
=
theano
.
tensor
.
matrix
()
a1
=
O
(
self
)
.
make_node
(
i
)
a1
=
O
(
self
)
.
make_node
(
i
)
g
=
grad_sources_inputs
([(
a1
.
outputs
[
0
],
1
)],
None
,
warn_type
=
False
)
g
=
grad_sources_inputs
([(
a1
.
outputs
[
0
],
1
)],
None
,
warn_type
=
False
)
self
.
assertTrue
(
g
[
i
]
is
1
)
self
.
assertTrue
(
g
[
i
]
is
1
)
...
@@ -155,16 +155,16 @@ class test_grad_sources_inputs(unittest.TestCase):
...
@@ -155,16 +155,16 @@ class test_grad_sources_inputs(unittest.TestCase):
self
.
tst
=
tst
self
.
tst
=
tst
self
.
grad_ok
=
grad_ok
self
.
grad_ok
=
grad_ok
def
make_node
(
self
,
*
inputs
):
def
make_node
(
self
,
*
inputs
):
outputs
=
[
gof
.
generic
(),
gof
.
generic
()]
outputs
=
[
theano
.
tensor
.
matrix
(),
theano
.
tensor
.
matrix
()]
return
gof
.
Apply
(
self
,
inputs
,
outputs
)
return
gof
.
Apply
(
self
,
inputs
,
outputs
)
def
grad
(
self
,
inputs
,
g_out
):
def
grad
(
self
,
inputs
,
g_out
):
if
not
self
.
grad_ok
:
if
not
self
.
grad_ok
:
self
.
tst
.
fail
()
self
.
tst
.
fail
()
else
:
else
:
return
[
1
,
None
]
return
[
1
,
None
]
i
=
gof
.
generic
()
i
=
theano
.
tensor
.
matrix
()
j
=
gof
.
generic
()
j
=
theano
.
tensor
.
matrix
()
k
=
gof
.
generic
()
k
=
theano
.
tensor
.
matrix
()
a1
=
O
(
self
,
True
)
.
make_node
(
i
,
j
)
a1
=
O
(
self
,
True
)
.
make_node
(
i
,
j
)
a2
=
O
(
self
,
True
)
.
make_node
(
a1
.
outputs
[
1
],
k
)
a2
=
O
(
self
,
True
)
.
make_node
(
a1
.
outputs
[
1
],
k
)
g
=
grad_sources_inputs
([(
a2
.
outputs
[
0
],
1
)],
None
,
warn_type
=
False
)
g
=
grad_sources_inputs
([(
a2
.
outputs
[
0
],
1
)],
None
,
warn_type
=
False
)
...
@@ -182,7 +182,7 @@ class test_grad_sources_inputs(unittest.TestCase):
...
@@ -182,7 +182,7 @@ class test_grad_sources_inputs(unittest.TestCase):
self
.
tst
=
tst
self
.
tst
=
tst
self
.
grad_ok
=
grad_ok
self
.
grad_ok
=
grad_ok
def
make_node
(
self
,
*
inputs
):
def
make_node
(
self
,
*
inputs
):
outputs
=
[
gof
.
generic
(),
gof
.
generic
()]
outputs
=
[
theano
.
tensor
.
matrix
(),
theano
.
tensor
.
matrix
()]
return
gof
.
Apply
(
self
,
inputs
,
outputs
)
return
gof
.
Apply
(
self
,
inputs
,
outputs
)
def
grad
(
self
,
inputs
,
grads
):
def
grad
(
self
,
inputs
,
grads
):
g0
,
g1
=
grads
g0
,
g1
=
grads
...
@@ -193,9 +193,9 @@ class test_grad_sources_inputs(unittest.TestCase):
...
@@ -193,9 +193,9 @@ class test_grad_sources_inputs(unittest.TestCase):
return
[
g0
,
g0
+
g1
]
return
[
g0
,
g0
+
g1
]
else
:
else
:
return
[
g0
,
g0
]
return
[
g0
,
g0
]
i
=
gof
.
generic
()
i
=
theano
.
tensor
.
matrix
()
j
=
gof
.
generic
()
j
=
theano
.
tensor
.
matrix
()
k
=
gof
.
generic
()
k
=
theano
.
tensor
.
matrix
()
a1
=
O
(
self
,
True
)
.
make_node
(
i
,
j
)
a1
=
O
(
self
,
True
)
.
make_node
(
i
,
j
)
a2
=
O
(
self
,
True
)
.
make_node
(
k
,
a1
.
outputs
[
1
])
a2
=
O
(
self
,
True
)
.
make_node
(
k
,
a1
.
outputs
[
1
])
g
=
_grad_sources_inputs
([(
a2
.
outputs
[
0
],
1
),
(
a1
.
outputs
[
1
],
4
),
g
=
_grad_sources_inputs
([(
a2
.
outputs
[
0
],
1
),
(
a1
.
outputs
[
1
],
4
),
...
@@ -214,7 +214,7 @@ class test_grad_sources_inputs(unittest.TestCase):
...
@@ -214,7 +214,7 @@ class test_grad_sources_inputs(unittest.TestCase):
self
.
tst
=
tst
self
.
tst
=
tst
self
.
grad_ok
=
grad_ok
self
.
grad_ok
=
grad_ok
def
make_node
(
self
,
*
inputs
):
def
make_node
(
self
,
*
inputs
):
outputs
=
[
gof
.
generic
(),
gof
.
generic
()]
outputs
=
[
theano
.
tensor
.
matrix
(),
theano
.
tensor
.
matrix
()]
return
gof
.
Apply
(
self
,
inputs
,
outputs
)
return
gof
.
Apply
(
self
,
inputs
,
outputs
)
def
grad
(
self
,
inputs
,
grads
):
def
grad
(
self
,
inputs
,
grads
):
g0
,
g1
=
grads
g0
,
g1
=
grads
...
@@ -225,9 +225,9 @@ class test_grad_sources_inputs(unittest.TestCase):
...
@@ -225,9 +225,9 @@ class test_grad_sources_inputs(unittest.TestCase):
return
[
g0
,
g0
+
g1
]
return
[
g0
,
g0
+
g1
]
else
:
else
:
return
[
g0
,
g0
]
return
[
g0
,
g0
]
i
=
gof
.
generic
()
i
=
theano
.
tensor
.
matrix
()
j
=
gof
.
generic
()
j
=
theano
.
tensor
.
matrix
()
k
=
gof
.
generic
()
k
=
theano
.
tensor
.
matrix
()
a1
=
O
(
self
,
True
)
.
make_node
(
i
,
j
)
a1
=
O
(
self
,
True
)
.
make_node
(
i
,
j
)
a2
=
O
(
self
,
True
)
.
make_node
(
k
,
a1
.
outputs
[
1
])
a2
=
O
(
self
,
True
)
.
make_node
(
k
,
a1
.
outputs
[
1
])
g
=
_grad_sources_inputs
([(
a2
.
outputs
[
0
],
1
),
(
a1
.
outputs
[
1
],
4
),
g
=
_grad_sources_inputs
([(
a2
.
outputs
[
0
],
1
),
(
a1
.
outputs
[
1
],
4
),
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论