Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
9805ceaa
提交
9805ceaa
authored
2月 29, 2016
作者:
Olivier Mastropietro
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fixes in test_swap_SharedVariable_with_given() to use the test_cpy. Various…
Fixes in test_swap_SharedVariable_with_given() to use the test_cpy. Various fixes on indentation and comments
上级
4c34df86
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
51 行增加
和
48 行删除
+51
-48
test_function_module.py
theano/compile/tests/test_function_module.py
+51
-47
test_profiling.py
theano/compile/tests/test_profiling.py
+0
-1
没有找到文件。
theano/compile/tests/test_function_module.py
浏览文件 @
9805ceaa
...
@@ -20,7 +20,6 @@ import theano
...
@@ -20,7 +20,6 @@ import theano
import
numpy
as
N
import
numpy
as
N
# PatternOptimizer = lambda p1, p2, ign=True: gof.OpKeyOptimizer(gof.PatternSub(p1, p2), ignore_newtrees=ign)
def
PatternOptimizer
(
p1
,
p2
,
ign
=
True
):
def
PatternOptimizer
(
p1
,
p2
,
ign
=
True
):
return
gof
.
OpKeyOptimizer
(
gof
.
PatternSub
(
p1
,
p2
),
ignore_newtrees
=
ign
)
return
gof
.
OpKeyOptimizer
(
gof
.
PatternSub
(
p1
,
p2
),
ignore_newtrees
=
ign
)
...
@@ -62,59 +61,50 @@ class T_function(unittest.TestCase):
...
@@ -62,59 +61,50 @@ class T_function(unittest.TestCase):
def
fn
():
def
fn
():
x
,
s
=
T
.
scalars
(
'xs'
)
x
,
s
=
T
.
scalars
(
'xs'
)
fn
=
function
([],
[
x
])
function
([],
[
x
])
return
fn
checkfor
(
self
,
fn
,
MissingInputError
)
checkfor
(
self
,
fn
,
MissingInputError
)
def
fn
():
def
fn
():
x
,
s
=
T
.
scalars
(
'xs'
)
x
,
s
=
T
.
scalars
(
'xs'
)
# Ignore unused input s, as it hides the other error
# Ignore unused input s, as it hides the other error
fn
=
function
([
s
],
[
x
],
on_unused_input
=
'ignore'
)
function
([
s
],
[
x
],
on_unused_input
=
'ignore'
)
return
fn
checkfor
(
self
,
fn
,
MissingInputError
)
checkfor
(
self
,
fn
,
MissingInputError
)
def
fn
():
def
fn
():
x
,
s
=
T
.
scalars
(
'xs'
)
x
,
s
=
T
.
scalars
(
'xs'
)
fn
=
function
([
s
],
[
x
])
function
([
s
],
[
x
])
return
fn
checkfor
(
self
,
fn
,
UnusedInputError
)
checkfor
(
self
,
fn
,
UnusedInputError
)
def
fn
():
def
fn
():
x
,
s
=
T
.
scalars
(
'xs'
)
x
,
s
=
T
.
scalars
(
'xs'
)
# Ignore unused input s, as it hides the other error
# Ignore unused input s, as it hides the other error
fn
=
function
([
s
],
x
,
on_unused_input
=
'ignore'
)
function
([
s
],
x
,
on_unused_input
=
'ignore'
)
return
fn
checkfor
(
self
,
fn
,
MissingInputError
)
checkfor
(
self
,
fn
,
MissingInputError
)
def
fn
():
def
fn
():
x
,
s
=
T
.
scalars
(
'xs'
)
x
,
s
=
T
.
scalars
(
'xs'
)
fn
=
function
([
s
],
x
)
function
([
s
],
x
)
return
fn
checkfor
(
self
,
fn
,
UnusedInputError
)
checkfor
(
self
,
fn
,
UnusedInputError
)
def
fn
():
def
fn
():
x
,
s
=
T
.
scalars
(
'xs'
)
x
,
s
=
T
.
scalars
(
'xs'
)
# Ignore unused input s, as it hides the other error
# Ignore unused input s, as it hides the other error
fn
=
function
([
s
],
Out
(
x
),
on_unused_input
=
'ignore'
)
function
([
s
],
Out
(
x
),
on_unused_input
=
'ignore'
)
return
fn
checkfor
(
self
,
fn
,
MissingInputError
)
checkfor
(
self
,
fn
,
MissingInputError
)
def
fn
():
def
fn
():
x
,
s
=
T
.
scalars
(
'xs'
)
x
,
s
=
T
.
scalars
(
'xs'
)
fn
=
function
([
s
],
Out
(
x
))
function
([
s
],
Out
(
x
))
return
fn
checkfor
(
self
,
fn
,
UnusedInputError
)
checkfor
(
self
,
fn
,
UnusedInputError
)
def
fn
():
def
fn
():
x
,
s
=
T
.
scalars
(
'xs'
)
x
,
s
=
T
.
scalars
(
'xs'
)
fn
=
function
([
In
(
x
,
update
=
s
+
x
)],
x
)
function
([
In
(
x
,
update
=
s
+
x
)],
x
)
return
fn
checkfor
(
self
,
fn
,
MissingInputError
)
checkfor
(
self
,
fn
,
MissingInputError
)
def
fn
():
def
fn
():
x
,
s
=
T
.
scalars
(
'xs'
)
x
,
s
=
T
.
scalars
(
'xs'
)
fn
=
function
([
In
(
x
,
update
=
((
s
*
s
)
+
x
))],
x
)
function
([
In
(
x
,
update
=
((
s
*
s
)
+
x
))],
x
)
return
fn
checkfor
(
self
,
fn
,
MissingInputError
)
checkfor
(
self
,
fn
,
MissingInputError
)
def
test_input_anon_singleton
(
self
):
def
test_input_anon_singleton
(
self
):
...
@@ -236,7 +226,9 @@ class T_function(unittest.TestCase):
...
@@ -236,7 +226,9 @@ class T_function(unittest.TestCase):
a
=
T
.
scalar
()
# the a is for 'anonymous' (un-named).
a
=
T
.
scalar
()
# the a is for 'anonymous' (un-named).
x
,
s
=
T
.
scalars
(
'xs'
)
x
,
s
=
T
.
scalars
(
'xs'
)
f
=
function
([
x
,
In
(
a
,
value
=
1.0
,
name
=
'a'
),
In
(
s
,
value
=
0.0
,
update
=
s
+
a
*
x
,
mutable
=
True
)],
s
+
a
*
x
)
f
=
function
([
x
,
In
(
a
,
value
=
1.0
,
name
=
'a'
),
In
(
s
,
value
=
0.0
,
update
=
s
+
a
*
x
,
mutable
=
True
)],
s
+
a
*
x
)
g
=
copy
.
copy
(
f
)
g
=
copy
.
copy
(
f
)
# if they both return, assume that they return equivalent things.
# if they both return, assume that they return equivalent things.
...
@@ -269,17 +261,15 @@ class T_function(unittest.TestCase):
...
@@ -269,17 +261,15 @@ class T_function(unittest.TestCase):
# Test if memories shared
# Test if memories shared
storage_map_ori
=
ori
.
fn
.
storage_map
storage_map_ori
=
ori
.
fn
.
storage_map
storage_map_cpy
=
cpy
.
fn
.
storage_map
storage_map_cpy
=
cpy
.
fn
.
storage_map
# fgraph_ori = ori.maker.fgraph
fgraph_cpy
=
cpy
.
maker
.
fgraph
fgraph_cpy
=
cpy
.
maker
.
fgraph
# Assert intermediate and Constants storages are shared.
# Assert intermediate and Constants storages are shared.
# and output stoarges are not shared
# and output stoarges are not shared
i_o_variables
=
fgraph_cpy
.
inputs
+
fgraph_cpy
.
outputs
i_o_variables
=
fgraph_cpy
.
inputs
+
fgraph_cpy
.
outputs
ori_storages
=
storage_map_ori
.
values
()
ori_storages
=
storage_map_ori
.
values
()
for
key
in
storage_map_cpy
.
keys
():
l
=
[
val
for
key
,
val
in
storage_map_cpy
.
items
()
storage
=
storage_map_cpy
[
key
]
if
key
not
in
i_o_variables
or
isinstance
(
key
,
theano
.
tensor
.
Constant
)]
if
key
not
in
i_o_variables
or
isinstance
(
key
,
theano
.
tensor
.
Constant
):
self
.
assertTrue
(
all
([
val
in
ori_storages
for
val
in
l
]))
self
.
assertTrue
(
any
([
storage
is
s
for
s
in
ori_storages
]))
# Assert storages of SharedVariable without updates are shared
# Assert storages of SharedVariable without updates are shared
for
(
input
,
_1
,
_2
),
here
,
there
in
zip
(
ori
.
indices
,
for
(
input
,
_1
,
_2
),
here
,
there
in
zip
(
ori
.
indices
,
...
@@ -351,10 +341,10 @@ class T_function(unittest.TestCase):
...
@@ -351,10 +341,10 @@ class T_function(unittest.TestCase):
A special testcase for logistic_sgd.py in Deep Learning Tutorial
A special testcase for logistic_sgd.py in Deep Learning Tutorial
This test assert that SharedVariable in different function have same storage
This test assert that SharedVariable in different function have same storage
"""
"""
#
train_x = theano.shared(value=numpy.random.rand(10, 10).astype(config.floatX))
train_x
=
theano
.
shared
(
value
=
numpy
.
random
.
rand
(
10
,
10
)
.
astype
(
config
.
floatX
))
test_x
=
theano
.
shared
(
value
=
numpy
.
random
.
rand
(
10
,
10
)
.
astype
(
config
.
floatX
))
test_x
=
theano
.
shared
(
value
=
numpy
.
random
.
rand
(
10
,
10
)
.
astype
(
config
.
floatX
))
#
train_y = theano.shared(value=numpy.random.rand(10, 1).astype(config.floatX))
train_y
=
theano
.
shared
(
value
=
numpy
.
random
.
rand
(
10
,
1
)
.
astype
(
config
.
floatX
))
test_y
=
theano
.
shared
(
value
=
numpy
.
random
.
rand
(
10
,
1
)
.
astype
(
config
.
floatX
))
test_y
=
theano
.
shared
(
value
=
numpy
.
random
.
rand
(
10
,
1
)
.
astype
(
config
.
floatX
))
i
=
T
.
iscalar
(
'index'
)
i
=
T
.
iscalar
(
'index'
)
...
@@ -362,17 +352,15 @@ class T_function(unittest.TestCase):
...
@@ -362,17 +352,15 @@ class T_function(unittest.TestCase):
y
=
T
.
vector
(
'y'
)
y
=
T
.
vector
(
'y'
)
# this formular has no sense but for a test
# this formular has no sense but for a test
out
=
(
T
.
sum
(
x
)
-
y
)
**
2
out
=
(
T
.
sum
(
x
)
-
y
)
**
2
out2
=
(
T
.
sum
(
x
)
+
y
)
**
2
train
=
theano
.
function
([
i
],
out
,
# train = theano.function([i], out,
givens
=
{
x
:
train_x
[
i
],
y
:
train_y
[
i
]},
# givens={x: train_x[i], y: train_y[i]},
updates
=
{
train_x
:
train_x
+
0.1
})
# updates={train_x: train_x + 0.1})
test_def
=
theano
.
function
([
i
],
out
,
givens
=
{
x
:
test_x
[
i
],
y
:
test_y
[
i
]})
test_def
=
theano
.
function
([
i
],
out
,
givens
=
{
x
:
test_x
[
i
],
y
:
test_y
[
i
]})
test_def2
=
theano
.
function
([
i
],
out2
,
givens
=
{
x
:
test_x
[
i
],
y
:
test_y
[
i
]})
test_cpy
=
train
.
copy
(
swap
=
{
train_x
:
test_x
,
train_y
:
test_y
},
# test_cpy = train.copy(swap={train_x: test_x, train_y: test_y},
delete_updates
=
True
)
# delete_updates=True)
for
in1
,
in2
in
zip
(
test_def
.
maker
.
inputs
,
test_
def2
.
maker
.
inputs
):
for
in1
,
in2
in
zip
(
test_def
.
maker
.
inputs
,
test_
cpy
.
maker
.
inputs
):
assert
in1
.
value
is
in2
.
value
assert
in1
.
value
is
in2
.
value
def
test_copy_delete_updates
(
self
):
def
test_copy_delete_updates
(
self
):
...
@@ -397,8 +385,12 @@ class T_function(unittest.TestCase):
...
@@ -397,8 +385,12 @@ class T_function(unittest.TestCase):
a
=
T
.
scalar
()
# the a is for 'anonymous' (un-named).
a
=
T
.
scalar
()
# the a is for 'anonymous' (un-named).
x
,
s
=
T
.
scalars
(
'xs'
)
x
,
s
=
T
.
scalars
(
'xs'
)
f
=
function
([
x
,
In
(
a
,
value
=
1.0
,
name
=
'a'
),
In
(
s
,
value
=
0.0
,
update
=
s
+
a
*
x
,
mutable
=
True
)],
s
+
a
*
x
)
f
=
function
([
x
,
In
(
a
,
value
=
1.0
,
name
=
'a'
),
g
=
function
([
x
,
In
(
a
,
value
=
1.0
,
name
=
'a'
),
In
(
s
,
value
=
f
.
container
[
s
],
update
=
s
-
a
*
x
,
mutable
=
True
)],
s
+
a
*
x
)
In
(
s
,
value
=
0.0
,
update
=
s
+
a
*
x
,
mutable
=
True
)],
s
+
a
*
x
)
g
=
function
([
x
,
In
(
a
,
value
=
1.0
,
name
=
'a'
),
In
(
s
,
value
=
f
.
container
[
s
],
update
=
s
-
a
*
x
,
mutable
=
True
)],
s
+
a
*
x
)
f
(
1
,
2
)
f
(
1
,
2
)
self
.
assertTrue
(
f
[
s
]
==
2
)
self
.
assertTrue
(
f
[
s
]
==
2
)
...
@@ -411,8 +403,10 @@ class T_function(unittest.TestCase):
...
@@ -411,8 +403,10 @@ class T_function(unittest.TestCase):
a
=
T
.
scalar
()
# the a is for 'anonymous' (un-named).
a
=
T
.
scalar
()
# the a is for 'anonymous' (un-named).
x
,
s
=
T
.
scalars
(
'xs'
)
x
,
s
=
T
.
scalars
(
'xs'
)
f
=
function
([
x
,
In
(
a
,
value
=
1.0
,
name
=
'a'
),
In
(
s
,
value
=
0.0
,
update
=
s
+
a
*
x
,
mutable
=
True
)],
s
+
a
*
x
)
f
=
function
([
x
,
In
(
a
,
value
=
1.0
,
name
=
'a'
),
g
=
function
([
x
,
In
(
a
,
value
=
1.0
,
name
=
'a'
),
In
(
s
,
value
=
f
.
container
[
s
])],
s
+
a
*
x
)
In
(
s
,
value
=
0.0
,
update
=
s
+
a
*
x
,
mutable
=
True
)],
s
+
a
*
x
)
g
=
function
([
x
,
In
(
a
,
value
=
1.0
,
name
=
'a'
),
In
(
s
,
value
=
f
.
container
[
s
])],
s
+
a
*
x
)
f
(
1
,
2
)
f
(
1
,
2
)
self
.
assertTrue
(
f
[
s
]
==
2
)
self
.
assertTrue
(
f
[
s
]
==
2
)
...
@@ -580,7 +574,8 @@ class T_picklefunction(unittest.TestCase):
...
@@ -580,7 +574,8 @@ class T_picklefunction(unittest.TestCase):
a
=
T
.
scalar
()
# the a is for 'anonymous' (un-named).
a
=
T
.
scalar
()
# the a is for 'anonymous' (un-named).
x
,
s
=
T
.
scalars
(
'xs'
)
x
,
s
=
T
.
scalars
(
'xs'
)
f
=
function
([
x
,
In
(
a
,
value
=
1.0
,
name
=
'a'
),
In
(
s
,
value
=
0.0
,
update
=
s
+
a
*
x
,
mutable
=
True
)],
s
+
a
*
x
)
f
=
function
([
x
,
In
(
a
,
value
=
1.0
,
name
=
'a'
),
In
(
s
,
value
=
0.0
,
update
=
s
+
a
*
x
,
mutable
=
True
)],
s
+
a
*
x
)
try
:
try
:
g
=
copy
.
deepcopy
(
f
)
g
=
copy
.
deepcopy
(
f
)
...
@@ -645,7 +640,8 @@ class T_picklefunction(unittest.TestCase):
...
@@ -645,7 +640,8 @@ class T_picklefunction(unittest.TestCase):
a
=
T
.
scalar
()
# the a is for 'anonymous' (un-named).
a
=
T
.
scalar
()
# the a is for 'anonymous' (un-named).
x
,
s
=
T
.
scalars
(
'xs'
)
x
,
s
=
T
.
scalars
(
'xs'
)
f
=
function
([
x
,
In
(
a
,
value
=
1.0
,
name
=
'a'
),
In
(
s
,
value
=
0.0
,
update
=
s
+
a
*
x
,
mutable
=
True
)],
s
+
a
*
x
)
f
=
function
([
x
,
In
(
a
,
value
=
1.0
,
name
=
'a'
),
In
(
s
,
value
=
0.0
,
update
=
s
+
a
*
x
,
mutable
=
True
)],
s
+
a
*
x
)
try
:
try
:
# Note that here we also test protocol 0 on purpose, since it
# Note that here we also test protocol 0 on purpose, since it
...
@@ -730,11 +726,15 @@ class T_picklefunction(unittest.TestCase):
...
@@ -730,11 +726,15 @@ class T_picklefunction(unittest.TestCase):
# some derived thing, whose inputs aren't all in the list
# some derived thing, whose inputs aren't all in the list
list_of_things
.
append
(
a
*
x
+
s
)
list_of_things
.
append
(
a
*
x
+
s
)
f1
=
function
([
x
,
In
(
a
,
value
=
1.0
,
name
=
'a'
),
In
(
s
,
value
=
0.0
,
update
=
s
+
a
*
x
,
mutable
=
True
)],
s
+
a
*
x
)
f1
=
function
([
x
,
In
(
a
,
value
=
1.0
,
name
=
'a'
),
In
(
s
,
value
=
0.0
,
update
=
s
+
a
*
x
,
mutable
=
True
)],
s
+
a
*
x
)
list_of_things
.
append
(
f1
)
list_of_things
.
append
(
f1
)
# now put in a function sharing container with the previous one
# now put in a function sharing container with the previous one
f2
=
function
([
x
,
In
(
a
,
value
=
1.0
,
name
=
'a'
),
In
(
s
,
value
=
f1
.
container
[
s
],
update
=
s
+
a
*
x
,
mutable
=
True
)],
s
+
a
*
x
)
f2
=
function
([
x
,
In
(
a
,
value
=
1.0
,
name
=
'a'
),
In
(
s
,
value
=
f1
.
container
[
s
],
update
=
s
+
a
*
x
,
mutable
=
True
)],
s
+
a
*
x
)
list_of_things
.
append
(
f2
)
list_of_things
.
append
(
f2
)
assert
isinstance
(
f2
.
container
[
s
]
.
storage
,
list
)
assert
isinstance
(
f2
.
container
[
s
]
.
storage
,
list
)
...
@@ -803,7 +803,6 @@ class T_picklefunction(unittest.TestCase):
...
@@ -803,7 +803,6 @@ class T_picklefunction(unittest.TestCase):
def
pers_load
(
id
):
def
pers_load
(
id
):
return
saves
[
id
]
return
saves
[
id
]
# a = numpy.random.rand(4, 5)
b
=
numpy
.
random
.
rand
(
5
,
4
)
b
=
numpy
.
random
.
rand
(
5
,
4
)
x
=
theano
.
tensor
.
matrix
()
x
=
theano
.
tensor
.
matrix
()
...
@@ -826,7 +825,7 @@ class T_picklefunction(unittest.TestCase):
...
@@ -826,7 +825,7 @@ class T_picklefunction(unittest.TestCase):
fp
.
close
()
fp
.
close
()
p
=
pickle
.
Unpickler
(
fp2
)
p
=
pickle
.
Unpickler
(
fp2
)
p
.
persistent_load
=
pers_load
p
.
persistent_load
=
pers_load
# f2 =
p.load()
p
.
load
()
fp2
.
close
()
fp2
.
close
()
def
test_pickle_class_with_functions
(
self
):
def
test_pickle_class_with_functions
(
self
):
...
@@ -862,9 +861,14 @@ class SomethingToPickle(object):
...
@@ -862,9 +861,14 @@ class SomethingToPickle(object):
self
.
e
=
a
*
x
+
s
self
.
e
=
a
*
x
+
s
self
.
f1
=
function
([
x
,
In
(
a
,
value
=
1.0
,
name
=
'a'
),
In
(
s
,
value
=
0.0
,
update
=
s
+
a
*
x
,
mutable
=
True
)],
s
+
a
*
x
)
self
.
f1
=
function
([
x
,
In
(
a
,
value
=
1.0
,
name
=
'a'
),
In
(
s
,
value
=
0.0
,
update
=
s
+
a
*
x
,
mutable
=
True
)],
s
+
a
*
x
)
self
.
f2
=
function
([
x
,
In
(
a
,
value
=
1.0
,
name
=
'a'
),
In
(
s
,
value
=
self
.
f1
.
container
[
s
],
update
=
s
+
a
*
x
,
mutable
=
True
)],
s
+
a
*
x
)
self
.
f2
=
function
([
x
,
In
(
a
,
value
=
1.0
,
name
=
'a'
),
In
(
s
,
value
=
self
.
f1
.
container
[
s
],
update
=
s
+
a
*
x
,
mutable
=
True
)],
s
+
a
*
x
)
def
test_empty_givens_updates
():
def
test_empty_givens_updates
():
...
...
theano/compile/tests/test_profiling.py
浏览文件 @
9805ceaa
...
@@ -100,7 +100,6 @@ class Test_profiling(unittest.TestCase):
...
@@ -100,7 +100,6 @@ class Test_profiling(unittest.TestCase):
big_mat1
=
10
big_mat1
=
10
big_mat2
=
11
big_mat2
=
11
# out = f_ifelse(val1, val2, big_mat1, big_mat2)
f_ifelse
(
val1
,
val2
,
big_mat1
,
big_mat2
)
f_ifelse
(
val1
,
val2
,
big_mat1
,
big_mat2
)
finally
:
finally
:
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论