Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
78bf69d4
提交
78bf69d4
authored
1月 25, 2017
作者:
Benjamin Scellier
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
file theano/compile/tests/test_function_module.py
上级
e331b68f
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
23 行增加
和
25 行删除
+23
-25
test_function_module.py
theano/compile/tests/test_function_module.py
+23
-25
没有找到文件。
theano/compile/tests/test_function_module.py
浏览文件 @
78bf69d4
from
__future__
import
absolute_import
,
print_function
,
division
import
copy
import
six.moves.cPickle
as
pickle
import
numpy
import
numpy
as
np
import
unittest
...
...
@@ -18,8 +18,6 @@ from theano import tensor
from
theano
import
tensor
as
T
import
theano
import
numpy
as
N
def
PatternOptimizer
(
p1
,
p2
,
ign
=
True
):
return
gof
.
OpKeyOptimizer
(
gof
.
PatternSub
(
p1
,
p2
),
ignore_newtrees
=
ign
)
...
...
@@ -281,7 +279,7 @@ class T_function(unittest.TestCase):
def
test_swap_SharedVariable
(
self
):
i
=
T
.
iscalar
()
x_list
=
theano
.
shared
(
value
=
n
umpy
.
random
.
rand
(
10
)
.
astype
(
config
.
floatX
))
x_list
=
theano
.
shared
(
value
=
n
p
.
random
.
rand
(
10
)
.
astype
(
config
.
floatX
))
x
=
T
.
scalar
(
'x'
)
# SharedVariable for tests, one of them has update
...
...
@@ -343,11 +341,11 @@ class T_function(unittest.TestCase):
A special testcase for logistic_sgd.py in Deep Learning Tutorial
This test assert that SharedVariable in different function have same storage
"""
train_x
=
theano
.
shared
(
value
=
n
umpy
.
random
.
rand
(
10
,
10
)
.
astype
(
config
.
floatX
))
test_x
=
theano
.
shared
(
value
=
n
umpy
.
random
.
rand
(
10
,
10
)
.
astype
(
config
.
floatX
))
train_x
=
theano
.
shared
(
value
=
n
p
.
random
.
rand
(
10
,
10
)
.
astype
(
config
.
floatX
))
test_x
=
theano
.
shared
(
value
=
n
p
.
random
.
rand
(
10
,
10
)
.
astype
(
config
.
floatX
))
train_y
=
theano
.
shared
(
value
=
n
umpy
.
random
.
rand
(
10
,
1
)
.
astype
(
config
.
floatX
))
test_y
=
theano
.
shared
(
value
=
n
umpy
.
random
.
rand
(
10
,
1
)
.
astype
(
config
.
floatX
))
train_y
=
theano
.
shared
(
value
=
n
p
.
random
.
rand
(
10
,
1
)
.
astype
(
config
.
floatX
))
test_y
=
theano
.
shared
(
value
=
n
p
.
random
.
rand
(
10
,
1
)
.
astype
(
config
.
floatX
))
i
=
T
.
iscalar
(
'index'
)
x
=
T
.
vector
(
'x'
)
...
...
@@ -500,42 +498,42 @@ class T_function(unittest.TestCase):
when borrow=True is implemented.
"""
a
=
T
.
dmatrix
()
aval
=
n
umpy
.
random
.
rand
(
3
,
3
)
aval
=
n
p
.
random
.
rand
(
3
,
3
)
# when borrow=False, test that a destroy map cannot alias output to input
f
=
theano
.
function
([
In
(
a
,
borrow
=
False
)],
Out
(
a
+
1
,
borrow
=
True
))
assert
n
umpy
.
all
(
f
(
aval
)
==
aval
+
1
)
assert
not
n
umpy
.
may_share_memory
(
aval
,
f
(
aval
))
assert
n
p
.
all
(
f
(
aval
)
==
aval
+
1
)
assert
not
n
p
.
may_share_memory
(
aval
,
f
(
aval
))
# when borrow=False, test that a viewmap cannot alias output to input
f
=
theano
.
function
([
In
(
a
,
borrow
=
False
)],
Out
(
a
[
0
,
:],
borrow
=
True
))
assert
n
umpy
.
all
(
f
(
aval
)
==
aval
[
0
,
:])
assert
not
n
umpy
.
may_share_memory
(
aval
,
f
(
aval
))
assert
n
p
.
all
(
f
(
aval
)
==
aval
[
0
,
:])
assert
not
n
p
.
may_share_memory
(
aval
,
f
(
aval
))
def
test_borrow_output
(
self
):
a
=
T
.
dmatrix
()
f
=
function
([
a
],
Out
(
a
,
borrow
=
False
))
o
=
N
.
ones
((
3
,
3
))
o
=
np
.
ones
((
3
,
3
))
assert
o
is
not
f
(
o
)
# function no longer permits aliasing outputs to inputs
f
=
function
([
a
],
Out
(
a
*
4
,
borrow
=
False
))
o
=
N
.
ones
((
3
,
3
))
o
=
np
.
ones
((
3
,
3
))
four
=
f
(
o
)
assert
n
umpy
.
all
(
four
==
4
)
assert
n
p
.
all
(
four
==
4
)
f
(
o
+
.
1
)
# should not clobber the memory used to store four
assert
n
umpy
.
all
(
four
==
4
)
assert
n
p
.
all
(
four
==
4
)
f
=
function
([
a
],
Out
(
a
*
4
,
borrow
=
True
),
mode
=
theano
.
Mode
(
'c|py_nogc'
,
'fast_run'
))
o
=
N
.
ones
((
3
,
3
))
o
=
np
.
ones
((
3
,
3
))
four
=
f
(
o
)
assert
n
umpy
.
all
(
four
==
4
)
assert
n
p
.
all
(
four
==
4
)
f
(
o
+
.
1
)
# should clobber the memory used to store four
if
theano
.
config
.
cxx
:
assert
not
n
umpy
.
all
(
four
==
4
)
assert
not
n
p
.
all
(
four
==
4
)
else
:
# The Elemwise.perform method don't reuse memory
# as some numpy version don't support that correctly.
assert
n
umpy
.
all
(
four
==
4
)
assert
n
p
.
all
(
four
==
4
)
def
test_disconnected_input
(
self
):
a
=
T
.
scalar
(
'a'
)
...
...
@@ -753,7 +751,7 @@ class T_picklefunction(unittest.TestCase):
assert
f2
.
container
[
s
]
.
storage
is
f1
.
container
[
s
]
.
storage
# now put in a function with non-scalar
v_value
=
n
umpy
.
asarray
([
2
,
3
,
4.
],
dtype
=
config
.
floatX
)
v_value
=
n
p
.
asarray
([
2
,
3
,
4.
],
dtype
=
config
.
floatX
)
f3
=
function
([
x
,
In
(
v
,
value
=
v_value
)],
x
+
v
)
list_of_things
.
append
(
f3
)
...
...
@@ -800,13 +798,13 @@ class T_picklefunction(unittest.TestCase):
assert
nl
[
5
](
3
)
==
ol
[
5
](
3
)
assert
nl
[
4
]
.
value
[
nl
[
0
]]
==
6
assert
n
umpy
.
all
(
nl
[
6
][
nl
[
2
]]
==
numpy
.
asarray
([
2
,
3.
,
4
]))
assert
n
p
.
all
(
nl
[
6
][
nl
[
2
]]
==
np
.
asarray
([
2
,
3.
,
4
]))
def
test_broken_pickle_with_shared
(
self
):
saves
=
[]
def
pers_save
(
obj
):
if
isinstance
(
obj
,
n
umpy
.
ndarray
):
if
isinstance
(
obj
,
n
p
.
ndarray
):
saves
.
append
(
obj
)
return
len
(
saves
)
-
1
else
:
...
...
@@ -815,7 +813,7 @@ class T_picklefunction(unittest.TestCase):
def
pers_load
(
id
):
return
saves
[
id
]
b
=
n
umpy
.
random
.
rand
(
5
,
4
)
b
=
n
p
.
random
.
rand
(
5
,
4
)
x
=
theano
.
tensor
.
matrix
()
y
=
theano
.
shared
(
b
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论