Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
2d13ec42
提交
2d13ec42
authored
5月 02, 2016
作者:
Frederic Bastien
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Better test error message.
上级
9ba08fd0
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
63 行增加
和
64 行删除
+63
-64
test_opt.py
theano/tensor/tests/test_opt.py
+63
-64
没有找到文件。
theano/tensor/tests/test_opt.py
浏览文件 @
2d13ec42
...
...
@@ -564,7 +564,7 @@ class test_canonize(unittest.TestCase):
mode
=
mode
)
out
=
f
(
*
val_inputs
)
assert
(
out_dtype
==
out
.
dtype
)
assert
numpy
.
allclose
(
out
,
val_inputs
[
1
])
utt
.
assert_
allclose
(
out
,
val_inputs
[
1
])
topo
=
f
.
maker
.
fgraph
.
toposort
()
if
topo
and
not
(
len
(
topo
)
==
1
and
topo
[
0
]
.
op
==
deep_copy_op
):
for
node
in
topo
[:
-
1
]:
...
...
@@ -587,7 +587,7 @@ class test_canonize(unittest.TestCase):
f
=
compile
.
function
(
list
(
sym_inputs
),
g
,
mode
=
mode
)
out
=
f
(
*
val_inputs
)
assert
numpy
.
allclose
(
out
,
(
1
/
val_inputs
[
1
]))
utt
.
assert_
allclose
(
out
,
(
1
/
val_inputs
[
1
]))
topo
=
f
.
maker
.
fgraph
.
toposort
()
elem
=
[
t
for
t
in
topo
if
isinstance
(
t
.
op
,
T
.
Elemwise
)]
assert
len
(
elem
)
==
nb_elemwise
...
...
@@ -612,7 +612,7 @@ class test_canonize(unittest.TestCase):
f
=
compile
.
function
(
list
(
sym_inputs
),
g
,
mode
=
mode
)
out
=
f
(
*
val_inputs
)
assert
numpy
.
allclose
(
out
,
(
val_inputs
[
0
]
/
val_inputs
[
3
]))
utt
.
assert_
allclose
(
out
,
(
val_inputs
[
0
]
/
val_inputs
[
3
]))
topo
=
f
.
maker
.
fgraph
.
toposort
()
assert
len
(
topo
)
==
1
assert
isinstance
(
topo
[
0
]
.
op
,
(
T
.
Elemwise
,
))
...
...
@@ -636,7 +636,7 @@ class test_canonize(unittest.TestCase):
f
=
compile
.
function
(
list
(
sym_inputs
),
g
,
mode
=
mode
)
out
=
f
(
*
val_inputs
)
assert
numpy
.
allclose
(
out
,
(
0.5
*
utt
.
assert_
allclose
(
out
,
(
0.5
*
val_inputs
[
0
]
/
val_inputs
[
1
]))
topo
=
f
.
maker
.
fgraph
.
toposort
()
assert
len
(
topo
)
==
2
...
...
@@ -662,7 +662,7 @@ class test_canonize(unittest.TestCase):
f
=
compile
.
function
(
list
(
sym_inputs
),
g
,
mode
=
mode
)
out
=
f
(
*
val_inputs
)
assert
numpy
.
allclose
(
out
,
val_inputs
[
0
])
utt
.
assert_
allclose
(
out
,
val_inputs
[
0
])
topo
=
f
.
maker
.
fgraph
.
toposort
()
assert
len
(
topo
)
==
1
topo
[
0
]
.
op
==
deep_copy_op
...
...
@@ -681,7 +681,7 @@ class test_canonize(unittest.TestCase):
mode
=
mode
)
out
=
f
(
*
val_inputs
)
assert
numpy
.
all
(
numpy
.
isfinite
(
out
))
assert
numpy
.
allclose
(
out
,
numpy
.
sign
(
val_inputs
[
0
]))
utt
.
assert_
allclose
(
out
,
numpy
.
sign
(
val_inputs
[
0
]))
assert
(
out_dtype
==
out
.
dtype
)
assert
len
(
f
.
maker
.
fgraph
.
toposort
())
==
1
...
...
@@ -705,7 +705,7 @@ class test_canonize(unittest.TestCase):
topo
=
f
.
maker
.
fgraph
.
toposort
()
out
=
f
(
*
val_inputs
)
assert
numpy
.
all
(
numpy
.
isfinite
(
out
))
assert
numpy
.
allclose
(
out
,
numpy
.
sign
(
val_inputs
[
0
])
*
2
/
3
)
utt
.
assert_
allclose
(
out
,
numpy
.
sign
(
val_inputs
[
0
])
*
2
/
3
)
assert
(
out_dtype
==
out
.
dtype
)
def
test_abs_mul_div
(
self
):
...
...
@@ -781,7 +781,7 @@ class test_canonize(unittest.TestCase):
f
=
compile
.
function
(
list
(
sym_inputs
),
g
,
mode
=
mode
)
out
=
f
(
*
val_inputs
)
assert
numpy
.
allclose
(
out
,
val_inputs
[
0
]
/
utt
.
assert_
allclose
(
out
,
val_inputs
[
0
]
/
val_inputs
[
1
]
/
val_inputs
[
2
])
topo
=
f
.
maker
.
fgraph
.
toposort
()
assert
len
(
topo
)
==
2
...
...
@@ -799,7 +799,7 @@ class test_canonize(unittest.TestCase):
f
=
compile
.
function
(
list
(
sym_inputs
),
g
,
mode
=
mode
)
out
=
f
(
*
val_inputs
)
assert
numpy
.
allclose
(
out
,
val_inputs
[
0
]
/
(
utt
.
assert_
allclose
(
out
,
val_inputs
[
0
]
/
(
val_inputs
[
1
]
/
val_inputs
[
2
]))
topo
=
f
.
maker
.
fgraph
.
toposort
()
assert
len
(
topo
)
==
2
...
...
@@ -905,7 +905,7 @@ def test_const_type_in_mul_canonizer():
betaval
=
numpy
.
random
.
rand
(
5
)
aval
=
numpy
.
random
.
rand
(
5
)
assert
numpy
.
allclose
(
utt
.
assert_
allclose
(
f2
(
ival
,
wval
,
visbval
,
hidbval
,
betaval
,
aval
),
f1
(
ival
,
wval
,
visbval
,
hidbval
,
betaval
,
aval
))
...
...
@@ -1608,11 +1608,11 @@ def test_log_add():
f
([
10000
],
[
10000
])
# causes overflow if handled incorrectly
assert
numpy
.
isfinite
(
f
([
10000
],
[
10000
]))
assert
numpy
.
allclose
(
f
([
10000
],
[
10000
]),
10000
+
numpy
.
log1p
(
1
))
utt
.
assert_
allclose
(
f
([
10000
],
[
10000
]),
10000
+
numpy
.
log1p
(
1
))
# test that it give the same result when it don't overflow
f
([
10
],
[
10
])
# don't causes overflow
assert
numpy
.
allclose
(
f
([
10
],
[
10
]),
10
+
numpy
.
log1p
(
1
))
utt
.
assert_
allclose
(
f
([
10
],
[
10
]),
10
+
numpy
.
log1p
(
1
))
# test that it also works with more than two args, (this currently fails)
x
=
dvector
()
...
...
@@ -1622,7 +1622,7 @@ def test_log_add():
try
:
f
([
10000
],
[
10000
])
# causes overflow if handled incorrectly
assert
numpy
.
allclose
(
f
([
10000
],
[
10000
]),
20000
)
utt
.
assert_
allclose
(
f
([
10000
],
[
10000
]),
20000
)
except
AssertionError
:
raise
SkipTest
(
"log(add(exp)) is not stabilized when adding "
"more than 2 elements, see #623"
)
...
...
@@ -2734,7 +2734,7 @@ class test_local_adv_sub1_adv_inc_sub1(unittest.TestCase):
f
=
theano
.
function
([
x
,
y
,
idx
],
o
,
self
.
mode_no_assert
)
res
=
f
(
dx
,
dy
,
didx
)
assert
numpy
.
allclose
(
dy
,
res
)
utt
.
assert_
allclose
(
dy
,
res
)
topo
=
f
.
maker
.
fgraph
.
toposort
()
if
opt
:
assert
len
(
topo
)
==
1
...
...
@@ -2748,7 +2748,7 @@ class test_local_adv_sub1_adv_inc_sub1(unittest.TestCase):
f
=
theano
.
function
([
x
,
y
,
idx
],
o
,
self
.
mode_no_assert
)
res
=
f
(
dx
,
dy
,
didx
)
assert
numpy
.
allclose
((
dx
[
didx
]
+
dy
),
res
)
utt
.
assert_
allclose
((
dx
[
didx
]
+
dy
),
res
)
topo
=
f
.
maker
.
fgraph
.
toposort
()
len
(
topo
)
==
2
...
...
@@ -2758,7 +2758,7 @@ class test_local_adv_sub1_adv_inc_sub1(unittest.TestCase):
f
=
theano
.
function
([
x
,
y
,
idx
],
o
,
self
.
mode_no_assert
)
res
=
f
(
dx
,
dy
,
didx
)
assert
numpy
.
allclose
(
dy
,
res
)
utt
.
assert_
allclose
(
dy
,
res
)
topo
=
f
.
maker
.
fgraph
.
toposort
()
if
opt
:
assert
len
(
topo
)
==
1
...
...
@@ -4178,22 +4178,22 @@ def test_local_pow_specialize():
f
=
function
([
v
],
v
**
0
,
mode
=
mode
)
nodes
=
[
node
.
op
for
node
in
f
.
maker
.
fgraph
.
toposort
()]
assert
nodes
==
[
Shape_i
(
0
),
T
.
alloc
]
assert
numpy
.
allclose
(
f
(
val
),
val
**
0
)
utt
.
assert_
allclose
(
f
(
val
),
val
**
0
)
f
=
function
([
v
],
v
**
1
,
mode
=
mode
)
nodes
=
[
node
.
op
for
node
in
f
.
maker
.
fgraph
.
toposort
()]
nodes
==
[
deep_copy_op
]
assert
numpy
.
allclose
(
f
(
val
),
val
**
1
)
utt
.
assert_
allclose
(
f
(
val
),
val
**
1
)
f
=
function
([
v
],
v
**
(
-
1
),
mode
=
mode
)
nodes
=
[
node
.
op
for
node
in
f
.
maker
.
fgraph
.
toposort
()]
assert
nodes
==
[
T
.
inv
]
assert
numpy
.
allclose
(
f
(
val_no0
),
val_no0
**
(
-
1
))
utt
.
assert_
allclose
(
f
(
val_no0
),
val_no0
**
(
-
1
))
f
=
function
([
v
],
v
**
2
,
mode
=
mode
)
nodes
=
[
node
.
op
for
node
in
f
.
maker
.
fgraph
.
toposort
()]
assert
nodes
==
[
T
.
sqr
]
assert
numpy
.
allclose
(
f
(
val
),
val
**
2
)
utt
.
assert_
allclose
(
f
(
val
),
val
**
2
)
f
=
function
([
v
],
v
**
(
-
2
),
mode
=
mode
)
nodes
=
[
node
.
op
for
node
in
f
.
maker
.
fgraph
.
toposort
()]
...
...
@@ -4201,12 +4201,12 @@ def test_local_pow_specialize():
assert
nodes
[
0
]
==
T
.
sqr
assert
isinstance
(
nodes
[
1
]
.
scalar_op
,
theano
.
scalar
.
basic
.
Inv
)
# assert nodes == [T.sqr,T.inv]#Why this don't work?
assert
numpy
.
allclose
(
f
(
val_no0
),
val_no0
**
(
-
2
))
utt
.
assert_
allclose
(
f
(
val_no0
),
val_no0
**
(
-
2
))
f
=
function
([
v
],
v
**
(
.
5
),
mode
=
mode
)
nodes
=
[
node
.
op
for
node
in
f
.
maker
.
fgraph
.
toposort
()]
assert
nodes
==
[
T
.
sqrt
]
assert
numpy
.
allclose
(
f
(
val
),
val
**
(
.
5
))
utt
.
assert_
allclose
(
f
(
val
),
val
**
(
.
5
))
f
=
function
([
v
],
v
**
(
-.
5
),
mode
=
mode
)
nodes
=
[
node
.
op
for
node
in
f
.
maker
.
fgraph
.
toposort
()]
...
...
@@ -4214,7 +4214,7 @@ def test_local_pow_specialize():
assert
nodes
[
0
]
==
T
.
sqrt
assert
isinstance
(
nodes
[
1
]
.
scalar_op
,
theano
.
scalar
.
basic
.
Inv
)
# assert nodes == [T.sqrt,T.inv]#Why this don't work?
assert
numpy
.
allclose
(
f
(
val_no0
),
val_no0
**
(
-.
5
))
utt
.
assert_
allclose
(
f
(
val_no0
),
val_no0
**
(
-.
5
))
def
test_local_pow_specialize_device_more_aggressive_on_cpu
():
...
...
@@ -4232,7 +4232,7 @@ def test_local_pow_specialize_device_more_aggressive_on_cpu():
assert
len
(
nodes
)
==
1
assert
len
(
f
.
maker
.
fgraph
.
toposort
()[
0
]
.
op
.
scalar_op
.
fgraph
.
apply_nodes
)
==
6
assert
isinstance
(
nodes
[
0
]
.
scalar_op
,
theano
.
scalar
.
Composite
)
assert
numpy
.
allclose
(
f
(
val
),
val
**
15
)
utt
.
assert_
allclose
(
f
(
val
),
val
**
15
)
f
=
function
([
v
],
v
**
(
-
15
),
mode
=
mode
)
nodes
=
[
node
.
op
for
node
in
f
.
maker
.
fgraph
.
toposort
()]
...
...
@@ -4240,14 +4240,14 @@ def test_local_pow_specialize_device_more_aggressive_on_cpu():
assert
len
(
f
.
maker
.
fgraph
.
toposort
()[
0
]
.
op
.
scalar_op
.
fgraph
.
apply_nodes
)
==
6
assert
isinstance
(
nodes
[
0
]
.
scalar_op
,
theano
.
scalar
.
Composite
)
assert
isinstance
(
nodes
[
-
1
]
.
scalar_op
,
theano
.
scalar
.
basic
.
Inv
)
assert
numpy
.
allclose
(
f
(
val_no0
),
val_no0
**
(
-
15
))
utt
.
assert_
allclose
(
f
(
val_no0
),
val_no0
**
(
-
15
))
f
=
function
([
v
],
v
**
(
16
),
mode
=
mode
)
nodes
=
[
node
.
op
for
node
in
f
.
maker
.
fgraph
.
toposort
()]
assert
len
(
nodes
)
==
1
assert
len
(
f
.
maker
.
fgraph
.
toposort
()[
0
]
.
op
.
scalar_op
.
fgraph
.
apply_nodes
)
==
4
assert
isinstance
(
nodes
[
0
]
.
scalar_op
,
theano
.
scalar
.
Composite
)
assert
numpy
.
allclose
(
f
(
val
),
val
**
16
)
utt
.
assert_
allclose
(
f
(
val
),
val
**
16
)
f
=
function
([
v
],
v
**
(
-
16
),
mode
=
mode
)
nodes
=
[
node
.
op
for
node
in
f
.
maker
.
fgraph
.
toposort
()]
...
...
@@ -4255,7 +4255,7 @@ def test_local_pow_specialize_device_more_aggressive_on_cpu():
assert
len
(
f
.
maker
.
fgraph
.
toposort
()[
0
]
.
op
.
scalar_op
.
fgraph
.
apply_nodes
)
==
4
assert
isinstance
(
nodes
[
0
]
.
scalar_op
,
theano
.
scalar
.
Composite
)
assert
isinstance
(
nodes
[
-
1
]
.
scalar_op
,
theano
.
scalar
.
basic
.
Inv
)
assert
numpy
.
allclose
(
f
(
val_no0
),
val_no0
**
(
-
16
))
utt
.
assert_
allclose
(
f
(
val_no0
),
val_no0
**
(
-
16
))
class
T_Rebroadcast
(
unittest
.
TestCase
):
...
...
@@ -5146,26 +5146,26 @@ class T_local_sum_prod(unittest.TestCase):
# test sum
f
=
theano
.
function
([
a
],
a
.
sum
(),
mode
=
self
.
mode
)
assert
len
(
f
.
maker
.
fgraph
.
apply_nodes
)
==
1
assert
numpy
.
allclose
(
f
(
input
),
input
.
sum
())
utt
.
assert_
allclose
(
f
(
input
),
input
.
sum
())
# test prod
f
=
theano
.
function
([
a
],
a
.
prod
(),
mode
=
self
.
mode
)
assert
len
(
f
.
maker
.
fgraph
.
apply_nodes
)
==
1
assert
numpy
.
allclose
(
f
(
input
),
input
.
prod
())
utt
.
assert_
allclose
(
f
(
input
),
input
.
prod
())
# test sum
f
=
theano
.
function
([
a
],
a
.
sum
([
0
,
1
,
2
]),
mode
=
self
.
mode
)
assert
len
(
f
.
maker
.
fgraph
.
apply_nodes
)
==
1
assert
numpy
.
allclose
(
f
(
input
),
input
.
sum
())
utt
.
assert_
allclose
(
f
(
input
),
input
.
sum
())
# test prod
f
=
theano
.
function
([
a
],
a
.
prod
([
0
,
1
,
2
]),
mode
=
self
.
mode
)
assert
len
(
f
.
maker
.
fgraph
.
apply_nodes
)
==
1
assert
numpy
.
allclose
(
f
(
input
),
input
.
prod
())
utt
.
assert_
allclose
(
f
(
input
),
input
.
prod
())
backup
=
config
.
warn
.
sum_sum_bug
config
.
warn
.
sum_sum_bug
=
False
try
:
f
=
theano
.
function
([
a
],
a
.
sum
(
0
)
.
sum
(
0
)
.
sum
(
0
),
mode
=
self
.
mode
)
assert
len
(
f
.
maker
.
fgraph
.
apply_nodes
)
==
1
assert
numpy
.
allclose
(
f
(
input
),
input
.
sum
())
utt
.
assert_
allclose
(
f
(
input
),
input
.
sum
())
finally
:
config
.
warn
.
sum_sum_bug
=
backup
...
...
@@ -5216,19 +5216,19 @@ class T_local_sum_prod(unittest.TestCase):
for
d
,
dd
in
dims
:
expected
=
my_sum
(
input
,
d
,
dd
)
f
=
theano
.
function
([
a
],
a
.
sum
(
d
)
.
sum
(
dd
),
mode
=
self
.
mode
)
assert
numpy
.
allclose
(
f
(
input
),
expected
)
utt
.
assert_
allclose
(
f
(
input
),
expected
)
assert
len
(
f
.
maker
.
fgraph
.
apply_nodes
)
==
1
for
d
,
dd
in
dims
[:
6
]:
f
=
theano
.
function
([
a
],
a
.
sum
(
d
)
.
sum
(
dd
)
.
sum
(
0
),
mode
=
self
.
mode
)
assert
numpy
.
allclose
(
f
(
input
),
input
.
sum
(
d
)
.
sum
(
dd
)
.
sum
(
0
))
utt
.
assert_
allclose
(
f
(
input
),
input
.
sum
(
d
)
.
sum
(
dd
)
.
sum
(
0
))
assert
len
(
f
.
maker
.
fgraph
.
apply_nodes
)
==
1
for
d
in
[
0
,
1
,
2
]:
f
=
theano
.
function
([
a
],
a
.
sum
(
d
)
.
sum
(
None
),
mode
=
self
.
mode
)
assert
numpy
.
allclose
(
f
(
input
),
input
.
sum
(
d
)
.
sum
())
utt
.
assert_
allclose
(
f
(
input
),
input
.
sum
(
d
)
.
sum
())
assert
len
(
f
.
maker
.
fgraph
.
apply_nodes
)
==
1
f
=
theano
.
function
([
a
],
a
.
sum
(
None
)
.
sum
(),
mode
=
self
.
mode
)
assert
numpy
.
allclose
(
f
(
input
),
input
.
sum
())
utt
.
assert_
allclose
(
f
(
input
),
input
.
sum
())
assert
len
(
f
.
maker
.
fgraph
.
apply_nodes
)
==
1
finally
:
config
.
warn
.
sum_sum_bug
=
backup
...
...
@@ -5237,41 +5237,40 @@ class T_local_sum_prod(unittest.TestCase):
for
d
,
dd
in
dims
:
expected
=
my_prod
(
input
,
d
,
dd
)
f
=
theano
.
function
([
a
],
a
.
prod
(
d
)
.
prod
(
dd
),
mode
=
self
.
mode
)
assert
numpy
.
allclose
(
f
(
input
),
expected
)
utt
.
assert_
allclose
(
f
(
input
),
expected
)
assert
len
(
f
.
maker
.
fgraph
.
apply_nodes
)
==
1
for
d
,
dd
in
dims
[:
6
]:
f
=
theano
.
function
([
a
],
a
.
prod
(
d
)
.
prod
(
dd
)
.
prod
(
0
),
mode
=
self
.
mode
)
assert
numpy
.
allclose
(
f
(
input
),
input
.
prod
(
d
)
.
prod
(
dd
)
.
prod
(
0
))
utt
.
assert_
allclose
(
f
(
input
),
input
.
prod
(
d
)
.
prod
(
dd
)
.
prod
(
0
))
assert
len
(
f
.
maker
.
fgraph
.
apply_nodes
)
==
1
for
d
in
[
0
,
1
,
2
]:
f
=
theano
.
function
([
a
],
a
.
prod
(
d
)
.
prod
(
None
),
mode
=
self
.
mode
)
assert
numpy
.
allclose
(
f
(
input
),
input
.
prod
(
d
)
.
prod
())
utt
.
assert_
allclose
(
f
(
input
),
input
.
prod
(
d
)
.
prod
())
assert
len
(
f
.
maker
.
fgraph
.
apply_nodes
)
==
1
f
=
theano
.
function
([
a
],
a
.
prod
(
None
)
.
prod
(),
mode
=
self
.
mode
)
assert
numpy
.
allclose
(
f
(
input
),
input
.
prod
())
utt
.
assert_
allclose
(
f
(
input
),
input
.
prod
())
assert
len
(
f
.
maker
.
fgraph
.
apply_nodes
)
==
1
# test sum prod don't get opt.
for
d
,
dd
in
dims
:
expected
=
my_sum_prod
(
input
,
d
,
dd
)
f
=
theano
.
function
([
a
],
a
.
sum
(
d
)
.
prod
(
dd
),
mode
=
self
.
mode
)
assert
numpy
.
allclose
(
f
(
input
),
expected
)
utt
.
assert_
allclose
(
f
(
input
),
expected
)
assert
len
(
f
.
maker
.
fgraph
.
apply_nodes
)
==
2
for
d
,
dd
in
dims
[:
6
]:
f
=
theano
.
function
([
a
],
a
.
sum
(
d
)
.
prod
(
dd
)
.
prod
(
0
),
mode
=
self
.
mode
)
assert
numpy
.
allclose
(
f
(
input
),
input
.
sum
(
d
)
.
prod
(
dd
)
.
prod
(
0
))
utt
.
assert_
allclose
(
f
(
input
),
input
.
sum
(
d
)
.
prod
(
dd
)
.
prod
(
0
))
assert
len
(
f
.
maker
.
fgraph
.
apply_nodes
)
==
2
for
d
in
[
0
,
1
,
2
]:
f
=
theano
.
function
([
a
],
a
.
sum
(
d
)
.
prod
(
None
),
mode
=
self
.
mode
)
assert
numpy
.
allclose
(
f
(
input
),
input
.
sum
(
d
)
.
prod
())
utt
.
assert_
allclose
(
f
(
input
),
input
.
sum
(
d
)
.
prod
())
assert
len
(
f
.
maker
.
fgraph
.
apply_nodes
)
==
2
f
=
theano
.
function
([
a
],
a
.
sum
(
None
)
.
prod
(),
mode
=
self
.
mode
)
assert
numpy
.
allclose
(
f
(
input
),
input
.
sum
())
utt
.
assert_allclosey
(
f
(
input
),
input
.
sum
())
assert
len
(
f
.
maker
.
fgraph
.
apply_nodes
)
==
1
def
test_local_sum_prod_alloc
(
self
):
a
=
T
.
dtensor3
()
input
=
numpy
.
asarray
(
numpy
.
arange
(
2
*
3
*
4
)
.
reshape
(
2
,
3
,
4
),
...
...
@@ -5283,23 +5282,23 @@ class T_local_sum_prod(unittest.TestCase):
# test sum
f
=
theano
.
function
([
a
],
t_like
(
a
)
.
sum
(
None
),
mode
=
mode
)
assert
numpy
.
allclose
(
f
(
input
),
n_like
(
input
)
.
sum
())
utt
.
assert_
allclose
(
f
(
input
),
n_like
(
input
)
.
sum
())
assert
len
(
f
.
maker
.
fgraph
.
apply_nodes
)
==
nb_nodes
[
0
]
f
=
theano
.
function
([
a
],
t_like
(
a
)
.
sum
([
0
,
1
,
2
]),
mode
=
mode
)
assert
numpy
.
allclose
(
f
(
input
),
n_like
(
input
)
.
sum
())
utt
.
assert_
allclose
(
f
(
input
),
n_like
(
input
)
.
sum
())
assert
len
(
f
.
maker
.
fgraph
.
apply_nodes
)
==
nb_nodes
[
0
]
for
d
in
xrange
(
3
):
f
=
theano
.
function
([
a
],
t_like
(
a
)
.
sum
(
d
),
mode
=
mode
)
assert
numpy
.
allclose
(
f
(
input
),
n_like
(
input
)
.
sum
(
d
))
utt
.
assert_
allclose
(
f
(
input
),
n_like
(
input
)
.
sum
(
d
))
assert
len
(
f
.
maker
.
fgraph
.
apply_nodes
)
==
nb_nodes
[
1
]
topo
=
f
.
maker
.
fgraph
.
toposort
()
assert
topo
[
-
1
]
.
op
==
T
.
alloc
assert
not
any
([
isinstance
(
node
.
op
,
T
.
Sum
)
for
node
in
topo
])
for
i
in
xrange
(
3
):
f
=
theano
.
function
([
a
],
t_like
(
a
)
.
sum
(
i
),
mode
=
mode
)
assert
numpy
.
allclose
(
f
(
input
),
n_like
(
input
)
.
sum
(
i
))
utt
.
assert_
allclose
(
f
(
input
),
n_like
(
input
)
.
sum
(
i
))
assert
len
(
f
.
maker
.
fgraph
.
apply_nodes
)
==
nb_nodes
[
2
]
topo
=
f
.
maker
.
fgraph
.
toposort
()
assert
topo
[
-
1
]
.
op
==
T
.
alloc
...
...
@@ -5307,23 +5306,23 @@ class T_local_sum_prod(unittest.TestCase):
# test prod
f
=
theano
.
function
([
a
],
t_like
(
a
)
.
prod
(
None
),
mode
=
mode
)
assert
numpy
.
allclose
(
f
(
input
),
n_like
(
input
)
.
prod
())
utt
.
assert_
allclose
(
f
(
input
),
n_like
(
input
)
.
prod
())
#assert len(f.maker.fgraph.apply_nodes) == nb_nodes[0]
f
=
theano
.
function
([
a
],
t_like
(
a
)
.
prod
([
0
,
1
,
2
]),
mode
=
mode
)
assert
numpy
.
allclose
(
f
(
input
),
n_like
(
input
)
.
prod
())
utt
.
assert_
allclose
(
f
(
input
),
n_like
(
input
)
.
prod
())
#assert len(f.maker.fgraph.apply_nodes) == nb_nodes[0]
for
d
in
range
(
3
):
f
=
theano
.
function
([
a
],
t_like
(
a
)
.
prod
(
d
),
mode
=
mode
)
assert
numpy
.
allclose
(
f
(
input
),
n_like
(
input
)
.
prod
(
d
))
utt
.
assert_
allclose
(
f
(
input
),
n_like
(
input
)
.
prod
(
d
))
#assert len(f.maker.fgraph.apply_nodes) == nb_nodes[1]
topo
=
f
.
maker
.
fgraph
.
toposort
()
assert
topo
[
-
1
]
.
op
==
T
.
alloc
assert
not
any
([
isinstance
(
node
.
op
,
T
.
elemwise
.
Prod
)
for
node
in
topo
])
for
i
in
range
(
3
):
f
=
theano
.
function
([
a
],
t_like
(
a
)
.
prod
(
i
),
mode
=
mode
)
assert
numpy
.
allclose
(
f
(
input
),
n_like
(
input
)
.
prod
(
i
))
utt
.
assert_
allclose
(
f
(
input
),
n_like
(
input
)
.
prod
(
i
))
#assert len(f.maker.fgraph.apply_nodes) == nb_nodes[2]
topo
=
f
.
maker
.
fgraph
.
toposort
()
assert
topo
[
-
1
]
.
op
==
T
.
alloc
...
...
@@ -5335,7 +5334,7 @@ class T_local_sum_prod(unittest.TestCase):
for
d
,
dd
in
[(
0
,
0
),
(
1
,
0
),
(
2
,
0
),
(
0
,
1
),
(
1
,
1
),
(
2
,
1
)]:
f
=
theano
.
function
([
a
],
t_like
(
a
)
.
sum
(
d
)
.
sum
(
dd
),
mode
=
mode
)
assert
numpy
.
allclose
(
f
(
input
),
utt
.
assert_
allclose
(
f
(
input
),
n_like
(
input
)
.
sum
(
d
)
.
sum
(
dd
))
assert
len
(
f
.
maker
.
fgraph
.
apply_nodes
)
==
nb_nodes
[
3
]
topo
=
f
.
maker
.
fgraph
.
toposort
()
...
...
@@ -5459,7 +5458,7 @@ class T_local_reduce(unittest.TestCase):
A
=
theano
.
shared
(
numpy
.
array
([
1
,
2
,
3
,
4
,
5
],
dtype
=
'int64'
))
f
=
theano
.
function
([],
T
.
sum
(
T
.
stack
([
A
,
A
]),
axis
=
0
),
mode
=
self
.
mode
)
assert
numpy
.
allclose
(
f
(),
[
2
,
4
,
6
,
8
,
10
])
utt
.
assert_
allclose
(
f
(),
[
2
,
4
,
6
,
8
,
10
])
topo
=
f
.
maker
.
fgraph
.
toposort
()
assert
isinstance
(
topo
[
-
1
]
.
op
,
T
.
Elemwise
)
...
...
@@ -5471,7 +5470,7 @@ class T_local_reduce(unittest.TestCase):
mode
=
self
.
mode
)
finally
:
theano
.
config
.
warn
.
reduce_join
=
old
assert
numpy
.
allclose
(
f
(),
[
15
,
15
])
utt
.
assert_
allclose
(
f
(),
[
15
,
15
])
topo
=
f
.
maker
.
fgraph
.
toposort
()
assert
not
isinstance
(
topo
[
-
1
]
.
op
,
T
.
Elemwise
)
...
...
@@ -5479,14 +5478,14 @@ class T_local_reduce(unittest.TestCase):
A
=
theano
.
shared
(
numpy
.
array
([
1
,
2
,
3
,
4
,
5
])
.
reshape
(
5
,
1
))
f
=
theano
.
function
([],
T
.
sum
(
T
.
concatenate
((
A
,
A
),
axis
=
1
),
axis
=
1
),
mode
=
self
.
mode
)
assert
numpy
.
allclose
(
f
(),
[
2
,
4
,
6
,
8
,
10
])
utt
.
assert_
allclose
(
f
(),
[
2
,
4
,
6
,
8
,
10
])
topo
=
f
.
maker
.
fgraph
.
toposort
()
assert
not
isinstance
(
topo
[
-
1
]
.
op
,
T
.
Elemwise
)
A
=
theano
.
shared
(
numpy
.
array
([
1
,
2
,
3
,
4
,
5
])
.
reshape
(
5
,
1
))
f
=
theano
.
function
([],
T
.
sum
(
T
.
concatenate
((
A
,
A
),
axis
=
1
),
axis
=
0
),
mode
=
self
.
mode
)
assert
numpy
.
allclose
(
f
(),
[
15
,
15
])
utt
.
assert_
allclose
(
f
(),
[
15
,
15
])
topo
=
f
.
maker
.
fgraph
.
toposort
()
assert
not
isinstance
(
topo
[
-
1
]
.
op
,
T
.
Elemwise
)
...
...
@@ -5718,7 +5717,7 @@ class TestMakeVector(utt.InferShapeTester):
if
dtype
.
startswith
(
'int'
):
# The gradient should be 0
assert
numpy
.
allclose
(
g_val
,
0
)
utt
.
assert_
allclose
(
g_val
,
0
)
else
:
for
var
,
grval
in
zip
((
b
,
i
,
d
),
g_val
):
float_inputs
=
[]
...
...
@@ -5977,7 +5976,7 @@ def test_local_div_to_inv():
f
=
theano
.
function
([
num_len_s
,
denom_s
],
out
)
out_val
=
f
(
3
,
2.
)
assert
out_val
.
shape
==
(
1
,
3
)
assert
numpy
.
allclose
(
out_val
,
0.5
)
utt
.
assert_
allclose
(
out_val
,
0.5
)
def
test_local_useless_split
():
...
...
@@ -6129,14 +6128,14 @@ class TestShape_i(utt.InferShapeTester):
advec_val
=
numpy
.
random
.
rand
(
3
)
.
astype
(
config
.
floatX
)
f
=
function
([
advec
],
Shape_i
(
0
)(
advec
))
out
=
f
(
advec_val
)
assert
numpy
.
allclose
(
out
,
advec_val
.
shape
[
0
])
utt
.
assert_
allclose
(
out
,
advec_val
.
shape
[
0
])
admat
=
matrix
()
admat_val
=
numpy
.
random
.
rand
(
4
,
3
)
.
astype
(
config
.
floatX
)
for
i
in
xrange
(
2
):
f
=
function
([
admat
],
Shape_i
(
i
)(
admat
))
out
=
f
(
admat_val
)
assert
numpy
.
allclose
(
out
,
admat_val
.
shape
[
i
])
utt
.
assert_
allclose
(
out
,
admat_val
.
shape
[
i
])
def
test_infer_shape
(
self
):
admat
=
matrix
()
...
...
@@ -6289,7 +6288,7 @@ def test_local_sumsqr2dot():
f_val
=
f
(
w_val
,
g_val
)
f_test
=
numpy
.
dot
(
numpy
.
square
(
g_val
),
numpy
.
square
(
w_val
)
.
sum
(
axis
=
0
))
assert
numpy
.
allclose
(
f_val
,
f_test
)
utt
.
assert_
allclose
(
f_val
,
f_test
)
assert
any
(
isinstance
(
n
.
op
,
(
tensor
.
basic
.
Dot
,
tensor
.
blas
.
Dot22
,
tensor
.
blas
.
Gemv
,
tensor
.
blas_c
.
CGemv
))
for
n
in
f
.
maker
.
fgraph
.
toposort
())
...
...
@@ -6312,7 +6311,7 @@ def test_local_expm1():
f_val
=
f
(
x_val
)
f_test
=
function
([
x
],
T
.
expm1
(
x
),
mode
=
MODE
)
assert
numpy
.
allclose
(
f_val
,
f_test
(
x_val
))
utt
.
assert_
allclose
(
f_val
,
f_test
(
x_val
))
assert
any
(
isinstance
(
n
.
op
,
T
.
Elemwise
)
and
isinstance
(
n
.
op
.
scalar_op
,
theano
.
scalar
.
basic
.
Expm1
)
for
n
in
f
.
maker
.
fgraph
.
toposort
())
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论