Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
afb9e22c
提交
afb9e22c
authored
2月 04, 2011
作者:
Pascal Lamblin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Indentation and whitespace
上级
a8d0d9c4
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
45 行增加
和
46 行删除
+45
-46
test_module.py
theano/compile/tests/test_module.py
+45
-46
没有找到文件。
theano/compile/tests/test_module.py
浏览文件 @
afb9e22c
...
@@ -24,7 +24,7 @@ class T_module(unittest.TestCase):
...
@@ -24,7 +24,7 @@ class T_module(unittest.TestCase):
super
(
Blah
,
self
)
.
__init__
()
super
(
Blah
,
self
)
.
__init__
()
self
.
stepsize
=
T
.
value
(
stepsize
)
self
.
stepsize
=
T
.
value
(
stepsize
)
x
=
T
.
dscalar
()
x
=
T
.
dscalar
()
self
.
step
=
Method
([
x
],
x
-
self
.
stepsize
)
self
.
step
=
Method
([
x
],
x
-
self
.
stepsize
)
B
=
Blah
(
0.0
)
B
=
Blah
(
0.0
)
...
@@ -80,27 +80,27 @@ class T_module(unittest.TestCase):
...
@@ -80,27 +80,27 @@ class T_module(unittest.TestCase):
m1
.
ly
[
0
],
m1
.
ly
[
0
],
m1
.
lly
[
0
][
0
],
m1
.
lly
[
0
][
0
],
m1
.
tx
[
0
],
#8
m1
.
tx
[
0
],
#8
m1
.
ty
[
0
],
m1
.
tlx
[
0
][
0
],
m1
.
ty
[
0
],
m1
.
tlx
[
0
][
0
],
m1
.
tly
[
0
][
0
],
m1
.
ttx
[
0
][
0
],
m1
.
tty
[
0
][
0
],
m1
.
tdx
[
0
][
'x'
],
m1
.
tly
[
0
][
0
],
m1
.
ttx
[
0
][
0
],
m1
.
tty
[
0
][
0
],
m1
.
tdx
[
0
][
'x'
],
m1
.
tdy
[
0
][
'y'
],
m1
.
dx
[
'x'
],
m1
.
tdy
[
0
][
'y'
],
m1
.
dx
[
'x'
],
m1
.
dy
[
'y'
],
m1
.
dlx
[
'x'
][
0
],
m1
.
dly
[
'y'
][
0
],
m1
.
dy
[
'y'
],
m1
.
dlx
[
'x'
][
0
],
m1
.
dly
[
'y'
][
0
],
m1
.
dtx
[
'x'
][
0
],
m1
.
dty
[
'y'
][
0
],
m1
.
ddx
[
'x'
][
'x'
],
m1
.
dtx
[
'x'
][
0
],
m1
.
dty
[
'y'
][
0
],
m1
.
ddx
[
'x'
][
'x'
],
m1
.
ddy
[
'y'
][
'y'
]]):
m1
.
ddy
[
'y'
][
'y'
]]):
assert
isinstance
(
obj
,(
gof
.
Variable
))
assert
isinstance
(
obj
,(
gof
.
Variable
))
inst
=
m1
.
make
()
inst
=
m1
.
make
()
def
get_l
():
def
get_l
():
return
[
inst
.
lx
,
inst
.
ly
,
inst
.
tx
,
inst
.
ty
,
inst
.
dx
,
inst
.
dy
,
inst
.
llx
,
inst
.
lly
,
inst
.
ltx
,
inst
.
lty
,
inst
.
ldx
,
inst
.
ldy
,
inst
.
tlx
,
inst
.
tly
,
inst
.
ttx
,
inst
.
tty
,
inst
.
tdx
,
inst
.
tdy
,
inst
.
dly
,
inst
.
dlx
,
inst
.
dty
,
inst
.
dtx
,
inst
.
ddy
,
inst
.
ddx
]
return
[
inst
.
lx
,
inst
.
ly
,
inst
.
tx
,
inst
.
ty
,
inst
.
dx
,
inst
.
dy
,
inst
.
llx
,
inst
.
lly
,
inst
.
ltx
,
inst
.
lty
,
inst
.
ldx
,
inst
.
ldy
,
inst
.
tlx
,
inst
.
tly
,
inst
.
ttx
,
inst
.
tty
,
inst
.
tdx
,
inst
.
tdy
,
inst
.
dly
,
inst
.
dlx
,
inst
.
dty
,
inst
.
dtx
,
inst
.
ddy
,
inst
.
ddx
]
def
get_l2
():
def
get_l2
():
# return [inst.lx[0], inst.ly[0], inst.tx[0], inst.ty[0], inst.dx['x'], inst.dy['y'], inst.llx[0][0], inst.lly[0][0], inst.ltx[0][0], inst.lty[0][0], inst.ldx[0]['x'], inst.ldy[0]['y'], inst.tlx[0][0], inst.tly[0][0], inst.ttx[0][0], inst.tty[0][0], inst.tdx, inst.tdy, inst.dly, inst.dlx, inst.dty, inst.dtx, inst.ddy, inst.ddx]
# return [inst.lx[0], inst.ly[0], inst.tx[0], inst.ty[0], inst.dx['x'], inst.dy['y'], inst.llx[0][0], inst.lly[0][0], inst.ltx[0][0], inst.lty[0][0], inst.ldx[0]['x'], inst.ldy[0]['y'], inst.tlx[0][0], inst.tly[0][0], inst.ttx[0][0], inst.tty[0][0], inst.tdx, inst.tdy, inst.dly, inst.dlx, inst.dty, inst.dtx, inst.ddy, inst.ddx]
return
[
inst
.
lx
,
inst
.
ly
,
inst
.
tx
,
inst
.
ty
,
inst
.
llx
[
0
],
inst
.
lly
[
0
],
inst
.
ltx
[
0
],
inst
.
lty
[
0
],
inst
.
ldx
[
0
],
inst
.
ldy
[
0
],
inst
.
tlx
[
0
],
inst
.
tly
[
0
],
inst
.
ttx
[
0
],
inst
.
tty
[
0
],
inst
.
tdx
[
0
],
inst
.
tdy
[
0
],
inst
.
dly
[
'y'
],
inst
.
dlx
[
'x'
],
inst
.
dty
[
'y'
],
inst
.
dtx
[
'x'
]]
#, inst.ddy['y'], inst.ddx['x']]
return
[
inst
.
lx
,
inst
.
ly
,
inst
.
tx
,
inst
.
ty
,
inst
.
llx
[
0
],
inst
.
lly
[
0
],
inst
.
ltx
[
0
],
inst
.
lty
[
0
],
inst
.
ldx
[
0
],
inst
.
ldy
[
0
],
inst
.
tlx
[
0
],
inst
.
tly
[
0
],
inst
.
ttx
[
0
],
inst
.
tty
[
0
],
inst
.
tdx
[
0
],
inst
.
tdy
[
0
],
inst
.
dly
[
'y'
],
inst
.
dlx
[
'x'
],
inst
.
dty
[
'y'
],
inst
.
dtx
[
'x'
]]
#, inst.ddy['y'], inst.ddx['x']]
#test that we can access the data
#test that we can access the data
inst
.
x
inst
.
x
inst
.
y
inst
.
y
for
i
in
get_l
():
for
i
in
get_l
():
assert
i
assert
i
...
@@ -194,7 +194,7 @@ class T_module(unittest.TestCase):
...
@@ -194,7 +194,7 @@ class T_module(unittest.TestCase):
print
'value test'
print
'value test'
local_test
(
lambda
:
T
.
value
(
1
),
lambda
:
T
.
value
(
2
))
local_test
(
lambda
:
T
.
value
(
1
),
lambda
:
T
.
value
(
2
))
def
test_method_in_list_or_dict
(
self
):
def
test_method_in_list_or_dict
(
self
):
"""Test that a Method which is only included via a list or dictionary is still treated as if it
"""Test that a Method which is only included via a list or dictionary is still treated as if it
were a toplevel attribute
were a toplevel attribute
...
@@ -253,7 +253,7 @@ class T_module(unittest.TestCase):
...
@@ -253,7 +253,7 @@ class T_module(unittest.TestCase):
assert
isinstance
(
f
[
0
][
0
],
theano
.
compile
.
function_module
.
Function
)
assert
isinstance
(
f
[
0
][
0
],
theano
.
compile
.
function_module
.
Function
)
for
f
in
inst
.
dly
[
'y'
][
0
],
inst
.
dty
[
'y'
][
0
],
inst
.
dlz
[
'z'
][
0
],
inst
.
dtz
[
'z'
][
0
],
inst
.
ddy
[
'y'
][
'y'
],
inst
.
ddz
[
'z'
][
'z'
]:
for
f
in
inst
.
dly
[
'y'
][
0
],
inst
.
dty
[
'y'
][
0
],
inst
.
dlz
[
'z'
][
0
],
inst
.
dtz
[
'z'
][
0
],
inst
.
ddy
[
'y'
][
'y'
],
inst
.
ddz
[
'z'
][
'z'
]:
assert
isinstance
(
f
,
theano
.
compile
.
function_module
.
Function
)
assert
isinstance
(
f
,
theano
.
compile
.
function_module
.
Function
)
def
test_shared_members
(
self
):
def
test_shared_members
(
self
):
"""Test that under a variety of tricky conditions, the shared-ness of Variables and Members
"""Test that under a variety of tricky conditions, the shared-ness of Variables and Members
is respected."""
is respected."""
...
@@ -302,7 +302,7 @@ class T_module(unittest.TestCase):
...
@@ -302,7 +302,7 @@ class T_module(unittest.TestCase):
assert
f
==
4
assert
f
==
4
def
test_shared_members_N
(
self
):
def
test_shared_members_N
(
self
):
"""Test that Members can be shared an arbitrary number of times between
"""Test that Members can be shared an arbitrary number of times between
many submodules and internal data structures."""
many submodules and internal data structures."""
def
populate_module
(
m
,
x
):
def
populate_module
(
m
,
x
):
m
.
x
=
x
m
.
x
=
x
...
@@ -413,9 +413,9 @@ class T_module(unittest.TestCase):
...
@@ -413,9 +413,9 @@ class T_module(unittest.TestCase):
def
test_member_method_inputs
(
self
):
def
test_member_method_inputs
(
self
):
"""Test that module Members can be named as Method inputs, in which case the function will
"""Test that module Members can be named as Method inputs, in which case the function will
*not* use the storage allocated for the Module's version of that Member.
*not* use the storage allocated for the Module's version of that Member.
"""
"""
# test that explicit Method inputs don't use shared storage
# test that explicit Method inputs don't use shared storage
M
=
Module
()
M
=
Module
()
M
.
x
=
T
.
dscalar
()
M
.
x
=
T
.
dscalar
()
...
@@ -436,14 +436,14 @@ class T_module(unittest.TestCase):
...
@@ -436,14 +436,14 @@ class T_module(unittest.TestCase):
Method inputs"""
Method inputs"""
if
config
.
mode
==
'FAST_COMPILE'
:
if
config
.
mode
==
'FAST_COMPILE'
:
return
return
M
=
Module
()
M
=
Module
()
M
.
x
=
T
.
dvector
()
M
.
x
=
T
.
dvector
()
M
.
y
=
T
.
dvector
()
M
.
y
=
T
.
dvector
()
xval
=
numpy
.
asarray
([
0
,
0.5
])
xval
=
numpy
.
asarray
([
0
,
0.5
])
M
.
f
=
Method
([
io
.
In
(
M
.
x
,
M
.
f
=
Method
([
io
.
In
(
M
.
x
,
mutable
=
True
,
mutable
=
True
,
update
=
(
M
.
x
-
M
.
y
),
update
=
(
M
.
x
-
M
.
y
),
value
=
xval
)],
M
.
x
+
M
.
y
)
value
=
xval
)],
M
.
x
+
M
.
y
)
m
=
M
.
make
()
m
=
M
.
make
()
...
@@ -540,52 +540,52 @@ def test_multiple_references():
...
@@ -540,52 +540,52 @@ def test_multiple_references():
class
A
(
theano
.
Module
):
class
A
(
theano
.
Module
):
def
__init__
(
self
,
sub_module
):
def
__init__
(
self
,
sub_module
):
super
(
A
,
self
)
.
__init__
()
super
(
A
,
self
)
.
__init__
()
self
.
sub_module
=
sub_module
self
.
sub_module
=
sub_module
def
_instance_initialize
(
self
,
obj
):
def
_instance_initialize
(
self
,
obj
):
print
'Initializing A'
print
'Initializing A'
class
B
(
theano
.
Module
):
class
B
(
theano
.
Module
):
def
__init__
(
self
,
sub_module
):
def
__init__
(
self
,
sub_module
):
super
(
B
,
self
)
.
__init__
()
super
(
B
,
self
)
.
__init__
()
self
.
sub_module
=
sub_module
self
.
sub_module
=
sub_module
def
_instance_initialize
(
self
,
obj
):
def
_instance_initialize
(
self
,
obj
):
print
'Initializing B'
print
'Initializing B'
class
C
(
theano
.
Module
):
class
C
(
theano
.
Module
):
def
__init__
(
self
):
def
__init__
(
self
):
super
(
C
,
self
)
.
__init__
()
super
(
C
,
self
)
.
__init__
()
self
.
value
=
theano
.
tensor
.
scalar
()
self
.
value
=
theano
.
tensor
.
scalar
()
def
_instance_initialize
(
self
,
obj
):
def
_instance_initialize
(
self
,
obj
):
print
'Initializing C'
print
'Initializing C'
obj
.
value
=
0
obj
.
value
=
0
def
_instance_set
(
self
,
obj
,
value
):
def
_instance_set
(
self
,
obj
,
value
):
print
'Setting C'
print
'Setting C'
obj
.
value
=
value
obj
.
value
=
value
class
D
(
theano
.
Module
):
class
D
(
theano
.
Module
):
def
__init__
(
self
):
def
__init__
(
self
):
super
(
D
,
self
)
.
__init__
()
super
(
D
,
self
)
.
__init__
()
self
.
c
=
C
()
self
.
c
=
C
()
self
.
a
=
A
(
self
.
c
)
self
.
a
=
A
(
self
.
c
)
self
.
b
=
B
(
self
.
c
)
self
.
b
=
B
(
self
.
c
)
# Workaround for bug exhibited in a previous email.
# Workaround for bug exhibited in a previous email.
self
.
bug
=
theano
.
tensor
.
scalar
()
self
.
bug
=
theano
.
tensor
.
scalar
()
def
_instance_initialize
(
self
,
obj
):
def
_instance_initialize
(
self
,
obj
):
print
'Initializing D'
print
'Initializing D'
obj
.
c
.
set
(
1
)
obj
.
c
.
set
(
1
)
d
=
D
()
d
=
D
()
...
@@ -775,7 +775,7 @@ def test_default_instance_initialize():
...
@@ -775,7 +775,7 @@ def test_default_instance_initialize():
"""
"""
Testing the default _instance_initialize provided by module.
Testing the default _instance_initialize provided by module.
"""
"""
class
M1
(
Module
):
class
M1
(
Module
):
def
__init__
(
self
):
def
__init__
(
self
):
super
(
M1
,
self
)
.
__init__
()
super
(
M1
,
self
)
.
__init__
()
...
@@ -833,4 +833,3 @@ if __name__ == '__main__':
...
@@ -833,4 +833,3 @@ if __name__ == '__main__':
# t.test_shared_members()
# t.test_shared_members()
# tests = unittest.TestLoader().loadTestsFromModule("T_test_module")
# tests = unittest.TestLoader().loadTestsFromModule("T_test_module")
# tests.debug()
# tests.debug()
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论