Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
3076ff52
提交
3076ff52
authored
3月 23, 2017
作者:
amrithasuresh
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Updated numpy as np
上级
10bb500a
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
28 行增加
和
28 行删除
+28
-28
test_rop.py
theano/tests/test_rop.py
+28
-28
没有找到文件。
theano/tests/test_rop.py
浏览文件 @
3076ff52
...
...
@@ -18,7 +18,7 @@ from theano import function
import
theano
from
theano
import
tensor
import
itertools
import
numpy
import
numpy
as
np
from
theano.gof
import
Op
,
Apply
from
theano.gradient
import
grad_undefined
from
theano.tests.unittest_tools
import
SkipTest
...
...
@@ -64,7 +64,7 @@ class RopLop_checker(unittest.TestCase):
# computations using scan
self
.
x
=
tensor
.
vector
(
'x'
)
self
.
v
=
tensor
.
vector
(
'v'
)
self
.
rng
=
n
umpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
self
.
rng
=
n
p
.
random
.
RandomState
(
utt
.
fetch_seed
())
self
.
in_shape
=
(
5
+
self
.
rng
.
randint
(
3
),)
self
.
mx
=
tensor
.
matrix
(
'mx'
)
self
.
mv
=
tensor
.
matrix
(
'mv'
)
...
...
@@ -103,9 +103,9 @@ class RopLop_checker(unittest.TestCase):
If you want to test an Op with an output matrix, add a sum
after the Op you want to test.
"""
vx
=
n
umpy
.
asarray
(
self
.
rng
.
uniform
(
size
=
self
.
mat_in_shape
),
vx
=
n
p
.
asarray
(
self
.
rng
.
uniform
(
size
=
self
.
mat_in_shape
),
theano
.
config
.
floatX
)
vv
=
n
umpy
.
asarray
(
self
.
rng
.
uniform
(
size
=
self
.
mat_in_shape
),
vv
=
n
p
.
asarray
(
self
.
rng
.
uniform
(
size
=
self
.
mat_in_shape
),
theano
.
config
.
floatX
)
yv
=
tensor
.
Rop
(
y
,
self
.
mx
,
self
.
mv
)
rop_f
=
function
([
self
.
mx
,
self
.
mv
],
yv
,
on_unused_input
=
'ignore'
)
...
...
@@ -118,11 +118,11 @@ class RopLop_checker(unittest.TestCase):
v1
=
rop_f
(
vx
,
vv
)
v2
=
scan_f
(
vx
,
vv
)
assert
n
umpy
.
allclose
(
v1
,
v2
),
(
'ROP mismatch:
%
s
%
s'
%
(
v1
,
v2
))
assert
n
p
.
allclose
(
v1
,
v2
),
(
'ROP mismatch:
%
s
%
s'
%
(
v1
,
v2
))
self
.
check_nondiff_rop
(
theano
.
clone
(
y
,
replace
=
{
self
.
mx
:
break_op
(
self
.
mx
)}))
vv
=
n
umpy
.
asarray
(
self
.
rng
.
uniform
(
size
=
out_shape
),
theano
.
config
.
floatX
)
vv
=
n
p
.
asarray
(
self
.
rng
.
uniform
(
size
=
out_shape
),
theano
.
config
.
floatX
)
yv
=
tensor
.
Lop
(
y
,
self
.
mx
,
self
.
v
)
lop_f
=
function
([
self
.
mx
,
self
.
v
],
yv
)
...
...
@@ -131,7 +131,7 @@ class RopLop_checker(unittest.TestCase):
v1
=
lop_f
(
vx
,
vv
)
v2
=
scan_f
(
vx
,
vv
)
assert
n
umpy
.
allclose
(
v1
,
v2
),
(
'LOP mismatch:
%
s
%
s'
%
(
v1
,
v2
))
assert
n
p
.
allclose
(
v1
,
v2
),
(
'LOP mismatch:
%
s
%
s'
%
(
v1
,
v2
))
def
check_rop_lop
(
self
,
y
,
out_shape
):
"""
...
...
@@ -140,9 +140,9 @@ class RopLop_checker(unittest.TestCase):
"""
# TEST ROP
vx
=
n
umpy
.
asarray
(
self
.
rng
.
uniform
(
size
=
self
.
in_shape
),
vx
=
n
p
.
asarray
(
self
.
rng
.
uniform
(
size
=
self
.
in_shape
),
theano
.
config
.
floatX
)
vv
=
n
umpy
.
asarray
(
self
.
rng
.
uniform
(
size
=
self
.
in_shape
),
vv
=
n
p
.
asarray
(
self
.
rng
.
uniform
(
size
=
self
.
in_shape
),
theano
.
config
.
floatX
)
yv
=
tensor
.
Rop
(
y
,
self
.
x
,
self
.
v
)
...
...
@@ -156,7 +156,7 @@ class RopLop_checker(unittest.TestCase):
v1
=
rop_f
(
vx
,
vv
)
v2
=
scan_f
(
vx
,
vv
)
assert
n
umpy
.
allclose
(
v1
,
v2
),
(
'ROP mismatch:
%
s
%
s'
%
(
v1
,
v2
))
assert
n
p
.
allclose
(
v1
,
v2
),
(
'ROP mismatch:
%
s
%
s'
%
(
v1
,
v2
))
known_fail
=
False
try
:
self
.
check_nondiff_rop
(
theano
.
clone
(
y
,
replace
=
{
self
.
x
:
break_op
(
self
.
x
)}))
...
...
@@ -165,9 +165,9 @@ class RopLop_checker(unittest.TestCase):
# TEST LOP
vx
=
n
umpy
.
asarray
(
self
.
rng
.
uniform
(
size
=
self
.
in_shape
),
vx
=
n
p
.
asarray
(
self
.
rng
.
uniform
(
size
=
self
.
in_shape
),
theano
.
config
.
floatX
)
vv
=
n
umpy
.
asarray
(
self
.
rng
.
uniform
(
size
=
out_shape
),
vv
=
n
p
.
asarray
(
self
.
rng
.
uniform
(
size
=
out_shape
),
theano
.
config
.
floatX
)
yv
=
tensor
.
Lop
(
y
,
self
.
x
,
self
.
v
)
...
...
@@ -181,7 +181,7 @@ class RopLop_checker(unittest.TestCase):
v1
=
lop_f
(
vx
,
vv
)
v2
=
scan_f
(
vx
,
vv
)
assert
n
umpy
.
allclose
(
v1
,
v2
),
(
'LOP mismatch:
%
s
%
s'
%
(
v1
,
v2
))
assert
n
p
.
allclose
(
v1
,
v2
),
(
'LOP mismatch:
%
s
%
s'
%
(
v1
,
v2
))
if
known_fail
:
raise
SkipTest
(
'Rop does not handle non-differentiable inputs '
...
...
@@ -213,21 +213,21 @@ class test_RopLop(RopLop_checker):
self
.
check_rop_lop
(
self
.
x
[:
4
],
(
4
,))
def
test_incsubtensor1
(
self
):
tv
=
n
umpy
.
asarray
(
self
.
rng
.
uniform
(
size
=
(
3
,)),
tv
=
n
p
.
asarray
(
self
.
rng
.
uniform
(
size
=
(
3
,)),
theano
.
config
.
floatX
)
t
=
theano
.
shared
(
tv
)
out
=
tensor
.
inc_subtensor
(
self
.
x
[:
3
],
t
)
self
.
check_rop_lop
(
out
,
self
.
in_shape
)
def
test_incsubtensor2
(
self
):
tv
=
n
umpy
.
asarray
(
self
.
rng
.
uniform
(
size
=
(
10
,)),
tv
=
n
p
.
asarray
(
self
.
rng
.
uniform
(
size
=
(
10
,)),
theano
.
config
.
floatX
)
t
=
theano
.
shared
(
tv
)
out
=
tensor
.
inc_subtensor
(
t
[:
4
],
self
.
x
[:
4
])
self
.
check_rop_lop
(
out
,
(
10
,))
def
test_setsubtensor1
(
self
):
tv
=
n
umpy
.
asarray
(
self
.
rng
.
uniform
(
size
=
(
3
,)),
tv
=
n
p
.
asarray
(
self
.
rng
.
uniform
(
size
=
(
3
,)),
theano
.
config
.
floatX
)
t
=
theano
.
shared
(
tv
)
out
=
tensor
.
set_subtensor
(
self
.
x
[:
3
],
t
)
...
...
@@ -238,7 +238,7 @@ class test_RopLop(RopLop_checker):
self
.
check_rop_lop
(
out
,
self
.
in_shape
)
def
test_setsubtensor2
(
self
):
tv
=
n
umpy
.
asarray
(
self
.
rng
.
uniform
(
size
=
(
10
,)),
tv
=
n
p
.
asarray
(
self
.
rng
.
uniform
(
size
=
(
10
,)),
theano
.
config
.
floatX
)
t
=
theano
.
shared
(
tv
)
out
=
tensor
.
set_subtensor
(
t
[:
4
],
self
.
x
[:
4
])
...
...
@@ -258,7 +258,7 @@ class test_RopLop(RopLop_checker):
(
1
,))
def
test_downsample
(
self
):
rng
=
n
umpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
n
p
.
random
.
RandomState
(
utt
.
fetch_seed
())
# ws, shp
examples
=
(
((
2
,),
(
16
,)),
...
...
@@ -296,7 +296,7 @@ class test_RopLop(RopLop_checker):
scan_f
=
function
([],
sy
,
on_unused_input
=
'ignore'
,
mode
=
mode
)
v1
=
rop_f
()
v2
=
scan_f
()
assert
n
umpy
.
allclose
(
v1
,
v2
),
(
"Rop mismatch:
%
s
%
s"
%
(
v1
,
v2
))
assert
n
p
.
allclose
(
v1
,
v2
),
(
"Rop mismatch:
%
s
%
s"
%
(
v1
,
v2
))
def
test_conv
(
self
):
for
conv_op
in
[
conv
.
conv2d
,
conv2d
]:
...
...
@@ -337,16 +337,16 @@ class test_RopLop(RopLop_checker):
scan_f
=
function
([
input
,
filters
,
ev_input
,
ev_filters
],
sy
,
on_unused_input
=
'ignore'
,
mode
=
mode
)
dtype
=
theano
.
config
.
floatX
image_data
=
n
umpy
.
random
.
random
(
image_shape
)
.
astype
(
dtype
)
filter_data
=
n
umpy
.
random
.
random
(
filter_shape
)
.
astype
(
dtype
)
ev_image_data
=
n
umpy
.
random
.
random
(
image_shape
)
.
astype
(
dtype
)
ev_filter_data
=
n
umpy
.
random
.
random
(
filter_shape
)
.
astype
(
dtype
)
image_data
=
n
p
.
random
.
random
(
image_shape
)
.
astype
(
dtype
)
filter_data
=
n
p
.
random
.
random
(
filter_shape
)
.
astype
(
dtype
)
ev_image_data
=
n
p
.
random
.
random
(
image_shape
)
.
astype
(
dtype
)
ev_filter_data
=
n
p
.
random
.
random
(
filter_shape
)
.
astype
(
dtype
)
v1
=
rop_f
(
image_data
,
filter_data
,
ev_image_data
,
ev_filter_data
)
v2
=
scan_f
(
image_data
,
filter_data
,
ev_image_data
,
ev_filter_data
)
assert
n
umpy
.
allclose
(
v1
,
v2
),
(
"Rop mismatch:
%
s
%
s"
%
(
v1
,
v2
))
assert
n
p
.
allclose
(
v1
,
v2
),
(
"Rop mismatch:
%
s
%
s"
%
(
v1
,
v2
))
def
test_join
(
self
):
tv
=
n
umpy
.
asarray
(
self
.
rng
.
uniform
(
size
=
(
10
,)),
tv
=
n
p
.
asarray
(
self
.
rng
.
uniform
(
size
=
(
10
,)),
theano
.
config
.
floatX
)
t
=
theano
.
shared
(
tv
)
out
=
tensor
.
join
(
0
,
self
.
x
,
t
)
...
...
@@ -354,7 +354,7 @@ class test_RopLop(RopLop_checker):
def
test_dot
(
self
):
insh
=
self
.
in_shape
[
0
]
vW
=
n
umpy
.
asarray
(
self
.
rng
.
uniform
(
size
=
(
insh
,
insh
)),
vW
=
n
p
.
asarray
(
self
.
rng
.
uniform
(
size
=
(
insh
,
insh
)),
theano
.
config
.
floatX
)
W
=
theano
.
shared
(
vW
)
self
.
check_rop_lop
(
tensor
.
dot
(
self
.
x
,
W
),
self
.
in_shape
)
...
...
@@ -367,7 +367,7 @@ class test_RopLop(RopLop_checker):
self
.
in_shape
)
def
test_reshape
(
self
):
new_shape
=
tensor
.
constant
(
n
umpy
.
asarray
([
new_shape
=
tensor
.
constant
(
n
p
.
asarray
([
self
.
mat_in_shape
[
0
]
*
self
.
mat_in_shape
[
1
]],
dtype
=
'int64'
))
...
...
@@ -435,6 +435,6 @@ class test_RopLop(RopLop_checker):
# one differentiable path (i.e. there is no gradient wrt to one of
# the inputs).
x
=
tensor
.
arange
(
20.0
)
.
reshape
([
1
,
20
])
v
=
theano
.
shared
(
n
umpy
.
ones
([
20
]))
v
=
theano
.
shared
(
n
p
.
ones
([
20
]))
d
=
tensor
.
dot
(
x
,
v
)
.
sum
()
tensor
.
Rop
(
tensor
.
grad
(
d
,
v
),
v
,
v
)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论