Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
ead4f23e
提交
ead4f23e
authored
2月 23, 2011
作者:
David Warde-Farley
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Make tests PEP 3113 compliant (remove tuple parameter unpacking).
上级
77c20a3b
隐藏空白字符变更
内嵌
并排
正在显示
10 个修改的文件
包含
116 行增加
和
49 行删除
+116
-49
mode.py
theano/compile/mode.py
+8
-3
profilemode.py
theano/compile/profilemode.py
+3
-3
test_debugmode.py
theano/compile/tests/test_debugmode.py
+33
-11
test_inplace_opt_for_value.py
theano/compile/tests/test_inplace_opt_for_value.py
+9
-5
test_cc.py
theano/gof/tests/test_cc.py
+18
-7
test_link.py
theano/gof/tests/test_link.py
+3
-2
test_basic.py
theano/tensor/tests/test_basic.py
+3
-1
test_opt.py
theano/tensor/tests/test_opt.py
+9
-3
test_gradient.py
theano/tests/test_gradient.py
+18
-10
test_tutorial.py
theano/tests/test_tutorial.py
+12
-4
没有找到文件。
theano/compile/mode.py
浏览文件 @
ead4f23e
...
@@ -99,11 +99,15 @@ class OutputGuard(gof.Op):
...
@@ -99,11 +99,15 @@ class OutputGuard(gof.Op):
return
type
(
self
)
==
type
(
other
)
return
type
(
self
)
==
type
(
other
)
def
__hash__
(
self
):
def
__hash__
(
self
):
return
hash
(
type
(
self
))
return
hash
(
type
(
self
))
def
perform
(
self
,
node
,
(
x
,),
(
z
,)):
def
perform
(
self
,
node
,
inp
,
out
):
x
,
=
inp
z
,
=
out
z
[
0
]
=
x
z
[
0
]
=
x
def
__str__
(
self
):
def
__str__
(
self
):
return
'
%
s'
%
self
.
__class__
.
__name__
return
'
%
s'
%
self
.
__class__
.
__name__
def
c_code
(
self
,
node
,
nodename
,
(
x
,),
(
z
,),
sub
):
def
c_code
(
self
,
node
,
nodename
,
inp
,
out
,
sub
):
x
,
=
inp
z
,
=
out
return
"""
return
"""
Py_XDECREF(
%(z)
s);
Py_XDECREF(
%(z)
s);
%(z)
s =
%(x)
s;
%(z)
s =
%(x)
s;
...
@@ -209,7 +213,8 @@ class Mode(object):
...
@@ -209,7 +213,8 @@ class Mode(object):
def
__getstate__
(
self
):
def
__getstate__
(
self
):
return
(
self
.
provided_linker
,
self
.
provided_optimizer
)
return
(
self
.
provided_linker
,
self
.
provided_optimizer
)
def
__setstate__
(
self
,
(
linker
,
optimizer
)):
def
__setstate__
(
self
,
state
):
linker
,
optimizer
=
state
self
.
provided_linker
=
linker
self
.
provided_linker
=
linker
self
.
provided_optimizer
=
optimizer
self
.
provided_optimizer
=
optimizer
if
isinstance
(
linker
,
str
)
or
linker
is
None
:
if
isinstance
(
linker
,
str
)
or
linker
is
None
:
...
...
theano/compile/profilemode.py
浏览文件 @
ead4f23e
...
@@ -59,9 +59,9 @@ class ProfileMode(Mode):
...
@@ -59,9 +59,9 @@ class ProfileMode(Mode):
self
.
op_cimpl
,
self
.
compile_time
,
self
.
fct_call_time
,
self
.
op_cimpl
,
self
.
compile_time
,
self
.
fct_call_time
,
self
.
fct_call
,
self
.
message
,
self
.
outputs_size
)
self
.
fct_call
,
self
.
message
,
self
.
outputs_size
)
def
__setstate__
(
self
,
(
linker
,
optimizer
,
apply_time
,
op_cimpl
,
def
__setstate__
(
self
,
state
):
compile_time
,
fct_call_time
,
fct_call
,
message
,
outputs_size
)):
linker
,
optimizer
,
apply_time
,
op_cimpl
,
compile_time
,
\
fct_call_time
,
fct_call
,
message
,
outputs_size
=
state
self
.
apply_time
=
apply_time
self
.
apply_time
=
apply_time
self
.
op_cimpl
=
op_cimpl
self
.
op_cimpl
=
op_cimpl
self
.
compile_time
=
compile_time
self
.
compile_time
=
compile_time
...
...
theano/compile/tests/test_debugmode.py
浏览文件 @
ead4f23e
...
@@ -31,14 +31,18 @@ class BROKEN_ON_PURPOSE_Add(gof.Op):
...
@@ -31,14 +31,18 @@ class BROKEN_ON_PURPOSE_Add(gof.Op):
r
=
gof
.
Apply
(
self
,
[
a
,
b
],
[
a
.
type
()])
r
=
gof
.
Apply
(
self
,
[
a
,
b
],
[
a
.
type
()])
return
r
return
r
def
perform
(
self
,
node
,
(
a
,
b
),
(
out
,)):
def
perform
(
self
,
node
,
inp
,
out_
):
a
,
b
=
inp
out
,
=
out_
z
=
a
+
b
z
=
a
+
b
#ERROR TO ADD THIS CRAPPY OFFSET
#ERROR TO ADD THIS CRAPPY OFFSET
if
self
.
py_offset
:
if
self
.
py_offset
:
out
[
0
]
=
z
+
0.5
out
[
0
]
=
z
+
0.5
else
:
out
[
0
]
=
z
else
:
out
[
0
]
=
z
def
c_code
(
self
,
node
,
name
,
(
a
,
b
),
(
z
,),
sub
):
def
c_code
(
self
,
node
,
name
,
inp
,
out
,
sub
):
a
,
b
=
inp
z
,
=
out
return
"""
return
"""
if (
%(a)
s->nd != 1) {PyErr_SetString(PyExc_NotImplementedError, "rank(a) != 1");
%(fail)
s;}
if (
%(a)
s->nd != 1) {PyErr_SetString(PyExc_NotImplementedError, "rank(a) != 1");
%(fail)
s;}
if (
%(b)
s->nd != 1) {PyErr_SetString(PyExc_NotImplementedError, "rank(b) != 1");
%(fail)
s;}
if (
%(b)
s->nd != 1) {PyErr_SetString(PyExc_NotImplementedError, "rank(b) != 1");
%(fail)
s;}
...
@@ -100,7 +104,9 @@ class WeirdBrokenOp(gof.Op):
...
@@ -100,7 +104,9 @@ class WeirdBrokenOp(gof.Op):
r
=
gof
.
Apply
(
self
,
[
a_
],
[
a_
.
type
()])
r
=
gof
.
Apply
(
self
,
[
a_
],
[
a_
.
type
()])
return
r
return
r
def
dontuse_perform
(
self
,
node
,
(
a
,),
(
out
,)):
def
dontuse_perform
(
self
,
node
,
inp
,
out_
):
a
,
=
inp
out
,
=
out_
if
self
.
behaviour
==
'times2'
:
if
self
.
behaviour
==
'times2'
:
out
[
0
]
=
a
*
2
out
[
0
]
=
a
*
2
elif
self
.
behaviour
==
'times2_inplace'
:
elif
self
.
behaviour
==
'times2_inplace'
:
...
@@ -113,7 +119,9 @@ class WeirdBrokenOp(gof.Op):
...
@@ -113,7 +119,9 @@ class WeirdBrokenOp(gof.Op):
else
:
else
:
raise
ValueError
(
self
.
behaviour
)
raise
ValueError
(
self
.
behaviour
)
def
c_code
(
self
,
node
,
name
,
(
a
,),
(
z
,),
sub
):
def
c_code
(
self
,
node
,
name
,
inp
,
out
,
sub
):
a
,
=
inp
z
,
=
out
if
"inplace"
in
self
.
behaviour
:
if
"inplace"
in
self
.
behaviour
:
z_code
=
"""
z_code
=
"""
{Py_XDECREF(
%(z)
s);}
{Py_XDECREF(
%(z)
s);}
...
@@ -253,7 +261,9 @@ def test_baddestroymap():
...
@@ -253,7 +261,9 @@ def test_baddestroymap():
def
make_node
(
self
,
a
,
b
):
def
make_node
(
self
,
a
,
b
):
c
=
a
.
type
()
c
=
a
.
type
()
return
gof
.
Apply
(
self
,
[
a
,
b
],
[
c
])
return
gof
.
Apply
(
self
,
[
a
,
b
],
[
c
])
def
perform
(
self
,
node
,
(
a
,
b
),
(
c
,)):
def
perform
(
self
,
node
,
inp
,
out
):
a
,
b
=
inp
c
,
=
out
c
[
0
]
=
a
c
[
0
]
=
a
c
[
0
]
+=
b
c
[
0
]
+=
b
...
@@ -283,14 +293,18 @@ class Test_ViewMap(unittest.TestCase):
...
@@ -283,14 +293,18 @@ class Test_ViewMap(unittest.TestCase):
def
make_node
(
self
,
a
,
b
):
def
make_node
(
self
,
a
,
b
):
c
=
b
.
type
()
c
=
b
.
type
()
return
gof
.
Apply
(
self
,
[
a
,
b
],
[
c
])
return
gof
.
Apply
(
self
,
[
a
,
b
],
[
c
])
def
perform
(
self
,
node
,
(
a
,
b
),
(
c
,)):
def
perform
(
self
,
node
,
inp
,
out
):
a
,
b
=
inp
c
,
=
out
c
[
0
]
=
b
c
[
0
]
=
b
class
BadAddSlice
(
gof
.
Op
):
class
BadAddSlice
(
gof
.
Op
):
def
make_node
(
self
,
a
,
b
):
def
make_node
(
self
,
a
,
b
):
c
=
b
.
type
()
c
=
b
.
type
()
return
gof
.
Apply
(
self
,
[
a
,
b
],
[
c
])
return
gof
.
Apply
(
self
,
[
a
,
b
],
[
c
])
def
perform
(
self
,
node
,
(
a
,
b
),
(
c
,)):
def
perform
(
self
,
node
,
inp
,
out
):
a
,
b
=
inp
c
,
=
out
c
[
0
]
=
b
[
1
:
3
]
c
[
0
]
=
b
[
1
:
3
]
def
test_badviewmap_ref
(
self
):
def
test_badviewmap_ref
(
self
):
...
@@ -343,7 +357,9 @@ class Test_ViewMap(unittest.TestCase):
...
@@ -343,7 +357,9 @@ class Test_ViewMap(unittest.TestCase):
c
=
a
.
type
()
c
=
a
.
type
()
d
=
a
.
type
()
d
=
a
.
type
()
return
gof
.
Apply
(
self
,
[
a
,
b
],
[
c
,
d
])
return
gof
.
Apply
(
self
,
[
a
,
b
],
[
c
,
d
])
def
perform
(
self
,
node
,
(
a
,
b
),
(
c
,
d
)):
def
perform
(
self
,
node
,
inp
,
out
):
a
,
b
=
inp
c
,
d
=
out
c
[
0
]
=
a
c
[
0
]
=
a
d
[
0
]
=
a
[
1
:]
d
[
0
]
=
a
[
1
:]
...
@@ -364,7 +380,9 @@ class Test_ViewMap(unittest.TestCase):
...
@@ -364,7 +380,9 @@ class Test_ViewMap(unittest.TestCase):
c
=
a
.
type
()
c
=
a
.
type
()
d
=
a
.
type
()
d
=
a
.
type
()
return
gof
.
Apply
(
self
,
[
a
,
b
],
[
c
,
d
])
return
gof
.
Apply
(
self
,
[
a
,
b
],
[
c
,
d
])
def
perform
(
self
,
node
,
(
a
,
b
),
(
c
,
d
)):
def
perform
(
self
,
node
,
inp
,
out
):
a
,
b
=
inp
c
,
d
=
out
r
=
a
*
2
r
=
a
*
2
c
[
0
]
=
r
c
[
0
]
=
r
d
[
0
]
=
r
[
1
:]
d
[
0
]
=
r
[
1
:]
...
@@ -387,7 +405,9 @@ class Test_ViewMap(unittest.TestCase):
...
@@ -387,7 +405,9 @@ class Test_ViewMap(unittest.TestCase):
c
=
a
.
type
()
c
=
a
.
type
()
d
=
a
.
type
()
d
=
a
.
type
()
return
gof
.
Apply
(
self
,
[
a
,
b
],
[
c
,
d
])
return
gof
.
Apply
(
self
,
[
a
,
b
],
[
c
,
d
])
def
perform
(
self
,
node
,
(
a
,
b
),
(
c
,
d
)):
def
perform
(
self
,
node
,
inp
,
out
):
a
,
b
=
inp
c
,
d
=
out
r
=
a
*
1
r
=
a
*
1
c
[
0
]
=
r
c
[
0
]
=
r
d
[
0
]
=
r
[
1
:]
d
[
0
]
=
r
[
1
:]
...
@@ -409,7 +429,9 @@ class Test_ViewMap(unittest.TestCase):
...
@@ -409,7 +429,9 @@ class Test_ViewMap(unittest.TestCase):
c
=
a
.
type
()
c
=
a
.
type
()
d
=
a
.
type
()
d
=
a
.
type
()
return
gof
.
Apply
(
self
,
[
a
,
b
],
[
c
,
d
])
return
gof
.
Apply
(
self
,
[
a
,
b
],
[
c
,
d
])
def
perform
(
self
,
node
,
(
a
,
b
),
(
c
,
d
)):
def
perform
(
self
,
node
,
inp
,
out
):
a
,
b
=
inp
c
,
d
=
out
r
=
a
*
1
r
=
a
*
1
c
[
0
]
=
r
[:
-
1
]
c
[
0
]
=
r
[:
-
1
]
d
[
0
]
=
r
[
1
:]
d
[
0
]
=
r
[
1
:]
...
...
theano/compile/tests/test_inplace_opt_for_value.py
浏览文件 @
ead4f23e
...
@@ -104,9 +104,10 @@ class TanhRnn(Op):
...
@@ -104,9 +104,10 @@ class TanhRnn(Op):
z
=
x
.
type
()
#make a new symbolic variable with the same type as x
z
=
x
.
type
()
#make a new symbolic variable with the same type as x
return
Apply
(
self
,
[
x
,
z0
,
A
],
[
z
])
return
Apply
(
self
,
[
x
,
z0
,
A
],
[
z
])
def
perform
(
self
,
node
,
(
x
,
z0
,
A
),
out
):
def
perform
(
self
,
node
,
inp
,
out
):
assert
x
is
not
None
x
,
z0
,
A
=
inp
assert
z0
is
not
None
assert
x
is
not
None
assert
z0
is
not
None
assert
A
is
not
None
assert
A
is
not
None
T
,
M
=
x
.
shape
T
,
M
=
x
.
shape
z
=
N
.
zeros
((
T
+
1
,
M
))
z
=
N
.
zeros
((
T
+
1
,
M
))
...
@@ -115,7 +116,9 @@ class TanhRnn(Op):
...
@@ -115,7 +116,9 @@ class TanhRnn(Op):
z
[
i
+
1
]
=
N
.
tanh
(
N
.
dot
(
z
[
i
],
A
)
+
x
[
i
])
z
[
i
+
1
]
=
N
.
tanh
(
N
.
dot
(
z
[
i
],
A
)
+
x
[
i
])
out
[
0
][
0
]
=
z
out
[
0
][
0
]
=
z
def
grad
(
self
,
(
x
,
z0
,
A
),
(
gz
,)):
def
grad
(
self
,
inp
,
grads
):
x
,
z0
,
A
=
inp
gz
,
=
grads
z
=
tanh_rnn
(
x
,
z0
,
A
)
z
=
tanh_rnn
(
x
,
z0
,
A
)
gz_incl_rnn
,
gx
=
tanh_rnn_grad
(
A
,
z
,
gz
)
gz_incl_rnn
,
gx
=
tanh_rnn_grad
(
A
,
z
,
gz
)
return
[
gx
,
gz_incl_rnn
[
0
],
(
T
.
dot
(
z
[:
-
1
]
.
T
,
gx
))]
return
[
gx
,
gz_incl_rnn
[
0
],
(
T
.
dot
(
z
[:
-
1
]
.
T
,
gx
))]
...
@@ -136,7 +139,8 @@ class TanhRnnGrad(Op):
...
@@ -136,7 +139,8 @@ class TanhRnnGrad(Op):
def
make_node
(
self
,
A
,
z
,
gz
):
def
make_node
(
self
,
A
,
z
,
gz
):
return
Apply
(
self
,
[
A
,
z
,
gz
],
(
z
.
type
(),
gz
.
type
()))
return
Apply
(
self
,
[
A
,
z
,
gz
],
(
z
.
type
(),
gz
.
type
()))
def
perform
(
self
,
node
,
(
A
,
z
,
gz
),
out
):
def
perform
(
self
,
node
,
inp
,
out
):
A
,
z
,
gz
=
inp
Tp1
,
M
=
z
.
shape
Tp1
,
M
=
z
.
shape
T
=
Tp1
-
1
T
=
Tp1
-
1
gx
=
N
.
zeros
((
T
,
M
))
gx
=
N
.
zeros
((
T
,
M
))
...
...
theano/gof/tests/test_cc.py
浏览文件 @
ead4f23e
...
@@ -83,8 +83,9 @@ class MyOp(Op):
...
@@ -83,8 +83,9 @@ class MyOp(Op):
def
__str__
(
self
):
def
__str__
(
self
):
return
self
.
name
return
self
.
name
def
perform
(
self
,
node
,
inputs
,
(
out
,
)):
def
perform
(
self
,
node
,
inputs
,
out_
):
out
,
=
out_
out
[
0
]
=
self
.
impl
(
*
inputs
)
out
[
0
]
=
self
.
impl
(
*
inputs
)
def
c_code_cache_version
(
self
):
def
c_code_cache_version
(
self
):
return
()
return
()
...
@@ -100,28 +101,36 @@ class Binary(MyOp):
...
@@ -100,28 +101,36 @@ class Binary(MyOp):
class
Add
(
Binary
):
class
Add
(
Binary
):
def
c_code
(
self
,
node
,
name
,
(
x
,
y
),
(
z
,
),
sub
):
def
c_code
(
self
,
node
,
name
,
inp
,
out
,
sub
):
x
,
y
=
inp
z
,
=
out
return
"
%(z)
s =
%(x)
s +
%(y)
s;"
%
locals
()
return
"
%(z)
s =
%(x)
s +
%(y)
s;"
%
locals
()
def
impl
(
self
,
x
,
y
):
def
impl
(
self
,
x
,
y
):
return
x
+
y
return
x
+
y
add
=
Add
()
add
=
Add
()
class
Sub
(
Binary
):
class
Sub
(
Binary
):
def
c_code
(
self
,
node
,
name
,
(
x
,
y
),
(
z
,
),
sub
):
def
c_code
(
self
,
node
,
name
,
inp
,
out
,
sub
):
x
,
y
=
inp
z
,
=
out
return
"
%(z)
s =
%(x)
s -
%(y)
s;"
%
locals
()
return
"
%(z)
s =
%(x)
s -
%(y)
s;"
%
locals
()
def
impl
(
self
,
x
,
y
):
def
impl
(
self
,
x
,
y
):
return
-
10
# erroneous (most of the time)
return
-
10
# erroneous (most of the time)
sub
=
Sub
()
sub
=
Sub
()
class
Mul
(
Binary
):
class
Mul
(
Binary
):
def
c_code
(
self
,
node
,
name
,
(
x
,
y
),
(
z
,
),
sub
):
def
c_code
(
self
,
node
,
name
,
inp
,
out
,
sub
):
x
,
y
=
inp
z
,
=
out
return
"
%(z)
s =
%(x)
s *
%(y)
s;"
%
locals
()
return
"
%(z)
s =
%(x)
s *
%(y)
s;"
%
locals
()
def
impl
(
self
,
x
,
y
):
def
impl
(
self
,
x
,
y
):
return
x
*
y
return
x
*
y
mul
=
Mul
()
mul
=
Mul
()
class
Div
(
Binary
):
class
Div
(
Binary
):
def
c_code
(
self
,
node
,
name
,
(
x
,
y
),
(
z
,
),
sub
):
def
c_code
(
self
,
node
,
name
,
inp
,
out
,
sub
):
x
,
y
=
inp
z
,
=
out
return
"
%(z)
s =
%(x)
s /
%(y)
s;"
%
locals
()
return
"
%(z)
s =
%(x)
s /
%(y)
s;"
%
locals
()
def
impl
(
self
,
x
,
y
):
def
impl
(
self
,
x
,
y
):
return
x
/
y
return
x
/
y
...
@@ -256,7 +265,9 @@ def test_duallinker_mismatch():
...
@@ -256,7 +265,9 @@ def test_duallinker_mismatch():
################################
################################
class
AddFail
(
Binary
):
class
AddFail
(
Binary
):
def
c_code
(
self
,
node
,
name
,
(
x
,
y
),
(
z
,
),
sub
):
def
c_code
(
self
,
node
,
name
,
inp
,
out
,
sub
):
x
,
y
=
inp
z
,
=
out
fail
=
sub
[
'fail'
]
fail
=
sub
[
'fail'
]
return
"""
%(z)
s =
%(x)
s +
%(y)
s;
return
"""
%(z)
s =
%(x)
s +
%(y)
s;
PyErr_SetString(PyExc_RuntimeError, "failing here");
PyErr_SetString(PyExc_RuntimeError, "failing here");
...
...
theano/gof/tests/test_link.py
浏览文件 @
ead4f23e
...
@@ -44,8 +44,9 @@ class MyOp(Op):
...
@@ -44,8 +44,9 @@ class MyOp(Op):
def
__str__
(
self
):
def
__str__
(
self
):
return
self
.
name
return
self
.
name
def
perform
(
self
,
node
,
inputs
,
(
out
,
)):
def
perform
(
self
,
node
,
inputs
,
out_
):
out
,
=
out_
out
[
0
]
=
self
.
impl
(
*
inputs
)
out
[
0
]
=
self
.
impl
(
*
inputs
)
add
=
MyOp
(
2
,
'Add'
,
lambda
x
,
y
:
x
+
y
)
add
=
MyOp
(
2
,
'Add'
,
lambda
x
,
y
:
x
+
y
)
...
...
theano/tensor/tests/test_basic.py
浏览文件 @
ead4f23e
...
@@ -2513,7 +2513,9 @@ class test_grad(unittest.TestCase):
...
@@ -2513,7 +2513,9 @@ class test_grad(unittest.TestCase):
inputs
=
[
scalar
(
'a'
),
scalar
(
'c'
)]
inputs
=
[
scalar
(
'a'
),
scalar
(
'c'
)]
outputs
=
[
scalar
(
'b'
),
scalar
(
'd'
)]
outputs
=
[
scalar
(
'b'
),
scalar
(
'd'
)]
return
gof
.
Apply
(
self
,
inputs
,
outputs
)
return
gof
.
Apply
(
self
,
inputs
,
outputs
)
def
grad
(
self
,
(
x0
,
x1
),
(
gz0
,
gz1
)):
def
grad
(
self
,
inp
,
grads
):
x0
,
x1
=
inp
gz0
,
gz1
=
grads
return
self
.
gval0
,
self
.
gval1
return
self
.
gval0
,
self
.
gval1
def
test_1param
(
self
):
def
test_1param
(
self
):
...
...
theano/tensor/tests/test_opt.py
浏览文件 @
ead4f23e
...
@@ -1303,7 +1303,9 @@ class test_shapeoptimizer(unittest.TestCase):
...
@@ -1303,7 +1303,9 @@ class test_shapeoptimizer(unittest.TestCase):
def
make_node
(
self
,
x
):
def
make_node
(
self
,
x
):
x
=
as_tensor_variable
(
x
)
x
=
as_tensor_variable
(
x
)
return
Apply
(
self
,
[
x
],
[
x
.
type
()])
return
Apply
(
self
,
[
x
],
[
x
.
type
()])
def
perform
(
self
,
node
,
(
x
,),
(
out
,)):
def
perform
(
self
,
node
,
inp
,
out_
):
x
,
=
inp
out
,
=
out_
out
[
0
]
=
x
.
copy
()
out
[
0
]
=
x
.
copy
()
#def infer_shape(self, node, (xshp,)):
#def infer_shape(self, node, (xshp,)):
#return [tuple([self.shape_i(i)(r) for i in xrange(r.ndim)])]
#return [tuple([self.shape_i(i)(r) for i in xrange(r.ndim)])]
...
@@ -1314,9 +1316,13 @@ class test_shapeoptimizer(unittest.TestCase):
...
@@ -1314,9 +1316,13 @@ class test_shapeoptimizer(unittest.TestCase):
def
make_node
(
self
,
x
):
def
make_node
(
self
,
x
):
x
=
as_tensor_variable
(
x
)
x
=
as_tensor_variable
(
x
)
return
Apply
(
self
,
[
x
],
[
x
.
type
()])
return
Apply
(
self
,
[
x
],
[
x
.
type
()])
def
perform
(
self
,
node
,
(
x
,),
(
out
,)):
def
perform
(
self
,
node
,
inp
,
out_
):
x
,
=
inp
out
,
=
out_
out
[
0
]
=
x
.
copy
()
out
[
0
]
=
x
.
copy
()
def
infer_shape
(
self
,
node
,
(
xshp
,)):
def
infer_shape
(
self
,
node
,
xshp_
):
# Could also just return.
xshp
,
=
xshp_
return
(
xshp
,)
return
(
xshp
,)
identity_shape
=
IdentityShape
()
identity_shape
=
IdentityShape
()
...
...
theano/tests/test_gradient.py
浏览文件 @
ead4f23e
...
@@ -22,7 +22,9 @@ class test_grad_sources_inputs(unittest.TestCase):
...
@@ -22,7 +22,9 @@ class test_grad_sources_inputs(unittest.TestCase):
inputs
=
[
gof
.
generic
()]
inputs
=
[
gof
.
generic
()]
outputs
=
[
gof
.
generic
()]
outputs
=
[
gof
.
generic
()]
return
gof
.
Apply
(
self
,
inputs
,
outputs
)
return
gof
.
Apply
(
self
,
inputs
,
outputs
)
def
grad
(
self
,
(
x
,
),
(
gz
,
)):
def
grad
(
self
,
inp
,
grads
):
x
,
=
inp
gz
,
=
grads
pass
pass
a
=
retNone
()
.
make_node
()
a
=
retNone
()
.
make_node
()
try
:
try
:
...
@@ -37,7 +39,7 @@ class test_grad_sources_inputs(unittest.TestCase):
...
@@ -37,7 +39,7 @@ class test_grad_sources_inputs(unittest.TestCase):
def
make_node
(
self
,
*
inputs
):
def
make_node
(
self
,
*
inputs
):
outputs
=
[
gof
.
generic
()]
outputs
=
[
gof
.
generic
()]
return
gof
.
Apply
(
self
,
inputs
,
outputs
)
return
gof
.
Apply
(
self
,
inputs
,
outputs
)
def
grad
(
self
,
(
x
,
),
(
gz
,
)
):
def
grad
(
self
,
inp
,
grads
):
return
[
None
]
return
[
None
]
i
=
gof
.
generic
()
i
=
gof
.
generic
()
a
=
retNone
()
.
make_node
(
i
)
a
=
retNone
()
.
make_node
(
i
)
...
@@ -50,7 +52,7 @@ class test_grad_sources_inputs(unittest.TestCase):
...
@@ -50,7 +52,7 @@ class test_grad_sources_inputs(unittest.TestCase):
def
make_node
(
self
,
*
inputs
):
def
make_node
(
self
,
*
inputs
):
outputs
=
[
gof
.
generic
()]
outputs
=
[
gof
.
generic
()]
return
gof
.
Apply
(
self
,
inputs
,
outputs
)
return
gof
.
Apply
(
self
,
inputs
,
outputs
)
def
grad
(
self
,
inputs
,
(
gz
,
)
):
def
grad
(
self
,
inputs
,
grads
):
return
[
None
]
return
[
None
]
i
=
gof
.
generic
()
i
=
gof
.
generic
()
...
@@ -74,7 +76,7 @@ class test_grad_sources_inputs(unittest.TestCase):
...
@@ -74,7 +76,7 @@ class test_grad_sources_inputs(unittest.TestCase):
def
make_node
(
self
,
*
inputs
):
def
make_node
(
self
,
*
inputs
):
outputs
=
[
gof
.
generic
()]
outputs
=
[
gof
.
generic
()]
return
gof
.
Apply
(
self
,
inputs
,
outputs
)
return
gof
.
Apply
(
self
,
inputs
,
outputs
)
def
grad
(
self
,
inputs
,
(
gz
,
)
):
def
grad
(
self
,
inputs
,
grads
):
self
.
tst
.
fail
()
self
.
tst
.
fail
()
i
=
gof
.
generic
()
i
=
gof
.
generic
()
...
@@ -89,7 +91,7 @@ class test_grad_sources_inputs(unittest.TestCase):
...
@@ -89,7 +91,7 @@ class test_grad_sources_inputs(unittest.TestCase):
inputs
=
[
gof
.
generic
()]
inputs
=
[
gof
.
generic
()]
outputs
=
[
gof
.
generic
()]
outputs
=
[
gof
.
generic
()]
return
gof
.
Apply
(
self
,
inputs
,
outputs
)
return
gof
.
Apply
(
self
,
inputs
,
outputs
)
def
grad
(
self
,
(
x
,
),
(
gz
,
)
):
def
grad
(
self
,
inp
,
grads
):
return
gval
,
return
gval
,
a1
=
O
()
.
make_node
()
a1
=
O
()
.
make_node
()
g
=
_grad_sources_inputs
([(
a1
.
outputs
[
0
],
1
)],
None
)
g
=
_grad_sources_inputs
([(
a1
.
outputs
[
0
],
1
)],
None
)
...
@@ -103,7 +105,9 @@ class test_grad_sources_inputs(unittest.TestCase):
...
@@ -103,7 +105,9 @@ class test_grad_sources_inputs(unittest.TestCase):
inputs
=
[
gof
.
generic
()]
inputs
=
[
gof
.
generic
()]
outputs
=
[
gof
.
generic
(),
gof
.
generic
()]
outputs
=
[
gof
.
generic
(),
gof
.
generic
()]
return
gof
.
Apply
(
self
,
inputs
,
outputs
)
return
gof
.
Apply
(
self
,
inputs
,
outputs
)
def
grad
(
self
,
(
x
,
),
(
gz1
,
gz2
)):
def
grad
(
self
,
inp
,
grads
):
inp
,
=
x
gz1
,
gz2
=
grads
return
gval
,
return
gval
,
a1
=
O
()
.
make_node
()
a1
=
O
()
.
make_node
()
g
=
_grad_sources_inputs
([(
a1
.
outputs
[
0
],
1
)],
None
)
g
=
_grad_sources_inputs
([(
a1
.
outputs
[
0
],
1
)],
None
)
...
@@ -117,7 +121,9 @@ class test_grad_sources_inputs(unittest.TestCase):
...
@@ -117,7 +121,9 @@ class test_grad_sources_inputs(unittest.TestCase):
inputs
=
[
gof
.
generic
(),
gof
.
generic
()]
inputs
=
[
gof
.
generic
(),
gof
.
generic
()]
outputs
=
[
gof
.
generic
()]
outputs
=
[
gof
.
generic
()]
return
gof
.
Apply
(
self
,
inputs
,
outputs
)
return
gof
.
Apply
(
self
,
inputs
,
outputs
)
def
grad
(
self
,
(
x0
,
x1
),
(
gz
,
)):
def
grad
(
self
,
inp
,
grads
):
x0
,
x1
=
inp
gz
,
=
grads
return
(
gval0
,
gval1
)
return
(
gval0
,
gval1
)
a1
=
O
()
.
make_node
()
a1
=
O
()
.
make_node
()
g
=
_grad_sources_inputs
([(
a1
.
outputs
[
0
],
1
)],
None
)
g
=
_grad_sources_inputs
([(
a1
.
outputs
[
0
],
1
)],
None
)
...
@@ -132,7 +138,7 @@ class test_grad_sources_inputs(unittest.TestCase):
...
@@ -132,7 +138,7 @@ class test_grad_sources_inputs(unittest.TestCase):
inputs
=
[
gof
.
generic
(),
gof
.
generic
()]
inputs
=
[
gof
.
generic
(),
gof
.
generic
()]
outputs
=
[
gof
.
generic
(),
gof
.
generic
()]
outputs
=
[
gof
.
generic
(),
gof
.
generic
()]
return
gof
.
Apply
(
self
,
inputs
,
outputs
)
return
gof
.
Apply
(
self
,
inputs
,
outputs
)
def
grad
(
self
,
(
x0
,
x1
),
(
gz0
,
gz1
)
):
def
grad
(
self
,
inp
,
grads
):
return
gval0
,
gval1
return
gval0
,
gval1
a1
=
O
()
.
make_node
()
a1
=
O
()
.
make_node
()
g
=
_grad_sources_inputs
([(
a1
.
outputs
[
0
],
1
)],
None
)
g
=
_grad_sources_inputs
([(
a1
.
outputs
[
0
],
1
)],
None
)
...
@@ -189,7 +195,8 @@ class test_grad_sources_inputs(unittest.TestCase):
...
@@ -189,7 +195,8 @@ class test_grad_sources_inputs(unittest.TestCase):
def
make_node
(
self
,
*
inputs
):
def
make_node
(
self
,
*
inputs
):
outputs
=
[
gof
.
generic
(),
gof
.
generic
()]
outputs
=
[
gof
.
generic
(),
gof
.
generic
()]
return
gof
.
Apply
(
self
,
inputs
,
outputs
)
return
gof
.
Apply
(
self
,
inputs
,
outputs
)
def
grad
(
self
,
inputs
,
(
g0
,
g1
)):
def
grad
(
self
,
inputs
,
grads
):
g0
,
g1
=
grads
if
not
self
.
grad_ok
:
if
not
self
.
grad_ok
:
self
.
tst
.
fail
()
self
.
tst
.
fail
()
else
:
else
:
...
@@ -220,7 +227,8 @@ class test_grad_sources_inputs(unittest.TestCase):
...
@@ -220,7 +227,8 @@ class test_grad_sources_inputs(unittest.TestCase):
def
make_node
(
self
,
*
inputs
):
def
make_node
(
self
,
*
inputs
):
outputs
=
[
gof
.
generic
(),
gof
.
generic
()]
outputs
=
[
gof
.
generic
(),
gof
.
generic
()]
return
gof
.
Apply
(
self
,
inputs
,
outputs
)
return
gof
.
Apply
(
self
,
inputs
,
outputs
)
def
grad
(
self
,
inputs
,
(
g0
,
g1
)):
def
grad
(
self
,
inputs
,
grads
):
g0
,
g1
=
grads
if
not
self
.
grad_ok
:
if
not
self
.
grad_ok
:
self
.
tst
.
fail
()
self
.
tst
.
fail
()
else
:
else
:
...
...
theano/tests/test_tutorial.py
浏览文件 @
ead4f23e
...
@@ -147,7 +147,9 @@ class T_extending(unittest.TestCase):
...
@@ -147,7 +147,9 @@ class T_extending(unittest.TestCase):
raise
TypeError
(
'
%
s only works on doubles'
%
self
.
name
)
raise
TypeError
(
'
%
s only works on doubles'
%
self
.
name
)
return
gof
.
Apply
(
self
,
[
x
,
y
],
[
double
()])
return
gof
.
Apply
(
self
,
[
x
,
y
],
[
double
()])
def
perform
(
self
,
node
,
(
x
,
y
),
(
z
,
)):
def
perform
(
self
,
node
,
inp
,
out
):
x
,
y
=
inp
z
,
=
out
z
[
0
]
=
self
.
fn
(
x
,
y
)
z
[
0
]
=
self
.
fn
(
x
,
y
)
def
__str__
(
self
):
def
__str__
(
self
):
...
@@ -214,7 +216,9 @@ class T_extending(unittest.TestCase):
...
@@ -214,7 +216,9 @@ class T_extending(unittest.TestCase):
raise
TypeError
(
'
%
s only works on doubles'
%
self
.
name
)
raise
TypeError
(
'
%
s only works on doubles'
%
self
.
name
)
return
gof
.
Apply
(
self
,
[
x
,
y
],
[
double
()])
return
gof
.
Apply
(
self
,
[
x
,
y
],
[
double
()])
def
perform
(
self
,
node
,
(
x
,
y
),
(
z
,
)):
def
perform
(
self
,
node
,
inp
,
out
):
x
,
y
=
inp
z
,
=
out
z
[
0
]
=
self
.
fn
(
x
,
y
)
z
[
0
]
=
self
.
fn
(
x
,
y
)
def
__str__
(
self
):
def
__str__
(
self
):
...
@@ -360,13 +364,17 @@ class T_extending(unittest.TestCase):
...
@@ -360,13 +364,17 @@ class T_extending(unittest.TestCase):
raise
TypeError
(
'
%
s only works on doubles'
%
self
.
name
)
raise
TypeError
(
'
%
s only works on doubles'
%
self
.
name
)
return
gof
.
Apply
(
self
,
[
x
,
y
],
[
double
()])
return
gof
.
Apply
(
self
,
[
x
,
y
],
[
double
()])
def
perform
(
self
,
node
,
(
x
,
y
),
(
z
,
)):
def
perform
(
self
,
node
,
inp
,
out
):
x
,
y
=
inp
z
,
=
out
z
[
0
]
=
self
.
fn
(
x
,
y
)
z
[
0
]
=
self
.
fn
(
x
,
y
)
def
__str__
(
self
):
def
__str__
(
self
):
return
self
.
name
return
self
.
name
def
c_code
(
self
,
node
,
name
,
(
x
,
y
),
(
z
,
),
sub
):
def
c_code
(
self
,
node
,
name
,
inp
,
out
,
sub
):
x
,
y
=
inp
z
,
=
out
return
self
.
ccode
%
locals
()
return
self
.
ccode
%
locals
()
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论