Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
dded8355
提交
dded8355
authored
3月 23, 2017
作者:
Frédéric Bastien
提交者:
GitHub
3月 23, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #5752 from Amrithasuresh/master
Updated numpy as np #4218 #5640
上级
954ee18a
74421e0b
显示空白字符变更
内嵌
并排
正在显示
9 个修改的文件
包含
193 行增加
和
193 行删除
+193
-193
breakpoint.py
theano/tests/breakpoint.py
+2
-2
diverse_tests.py
theano/tests/diverse_tests.py
+3
-3
test_2nd_order_grads.py
theano/tests/test_2nd_order_grads.py
+37
-37
test_breakpoint.py
theano/tests/test_breakpoint.py
+9
-9
test_ifelse.py
theano/tests/test_ifelse.py
+79
-79
test_pickle_unpickle_theano_fn.py
theano/tests/test_pickle_unpickle_theano_fn.py
+9
-9
test_printing.py
theano/tests/test_printing.py
+3
-3
test_rop.py
theano/tests/test_rop.py
+28
-28
unittest_tools.py
theano/tests/unittest_tools.py
+23
-23
没有找到文件。
theano/tests/breakpoint.py
浏览文件 @
dded8355
from
__future__
import
absolute_import
,
print_function
,
division
from
__future__
import
absolute_import
,
print_function
,
division
import
numpy
import
numpy
as
np
import
pdb
import
pdb
import
theano
import
theano
...
@@ -102,7 +102,7 @@ class PdbBreakpoint(Op):
...
@@ -102,7 +102,7 @@ class PdbBreakpoint(Op):
if
condition
:
if
condition
:
try
:
try
:
monitored
=
[
n
umpy
.
asarray
(
inp
)
for
inp
in
inputs
[
1
:]]
monitored
=
[
n
p
.
asarray
(
inp
)
for
inp
in
inputs
[
1
:]]
except
:
except
:
raise
ValueError
(
"Some of the inputs to the PdbBreakpoint op "
raise
ValueError
(
"Some of the inputs to the PdbBreakpoint op "
"'
%
s' could not be casted to NumPy arrays"
%
"'
%
s' could not be casted to NumPy arrays"
%
...
...
theano/tests/diverse_tests.py
浏览文件 @
dded8355
from
__future__
import
absolute_import
,
print_function
,
division
from
__future__
import
absolute_import
,
print_function
,
division
import
unittest
import
unittest
import
numpy
import
numpy
as
np
import
numpy.random
import
numpy.random
import
theano
import
theano
...
@@ -28,7 +28,7 @@ class T_scipy(unittest.TestCase):
...
@@ -28,7 +28,7 @@ class T_scipy(unittest.TestCase):
a
=
theano
.
tensor
.
vector
(
'a'
)
# declare variable
a
=
theano
.
tensor
.
vector
(
'a'
)
# declare variable
b
=
a
+
a
**
10
# build expression
b
=
a
+
a
**
10
# build expression
f
=
theano
.
function
([
a
],
b
)
# compile function
f
=
theano
.
function
([
a
],
b
)
# compile function
assert
n
umpy
.
all
(
f
([
0
,
1
,
2
])
==
numpy
.
array
([
0
,
2
,
1026
]))
assert
n
p
.
all
(
f
([
0
,
1
,
2
])
==
np
.
array
([
0
,
2
,
1026
]))
def
test_scipy_paper_example2
(
self
):
def
test_scipy_paper_example2
(
self
):
''' This just sees if things compile well and if they run '''
''' This just sees if things compile well and if they run '''
...
@@ -45,7 +45,7 @@ class T_scipy(unittest.TestCase):
...
@@ -45,7 +45,7 @@ class T_scipy(unittest.TestCase):
x
=
T
.
matrix
()
x
=
T
.
matrix
()
y
=
T
.
vector
()
y
=
T
.
vector
()
w
=
shared
(
rng
.
randn
(
100
))
w
=
shared
(
rng
.
randn
(
100
))
b
=
shared
(
n
umpy
.
zeros
(()))
b
=
shared
(
n
p
.
zeros
(()))
# Construct Theano expression graph
# Construct Theano expression graph
p_1
=
1
/
(
1
+
T
.
exp
(
-
T
.
dot
(
x
,
w
)
-
b
))
p_1
=
1
/
(
1
+
T
.
exp
(
-
T
.
dot
(
x
,
w
)
-
b
))
...
...
theano/tests/test_2nd_order_grads.py
浏览文件 @
dded8355
...
@@ -6,7 +6,7 @@ from six.moves import xrange
...
@@ -6,7 +6,7 @@ from six.moves import xrange
from
theano.tests
import
unittest_tools
as
utt
from
theano.tests
import
unittest_tools
as
utt
import
theano
import
theano
from
theano
import
tensor
from
theano
import
tensor
import
numpy
import
numpy
as
np
utt
.
seed_rng
()
utt
.
seed_rng
()
...
@@ -14,27 +14,27 @@ utt.seed_rng()
...
@@ -14,27 +14,27 @@ utt.seed_rng()
def
test001_jacobian_vector
():
def
test001_jacobian_vector
():
x
=
tensor
.
vector
()
x
=
tensor
.
vector
()
y
=
x
*
2
y
=
x
*
2
rng
=
n
umpy
.
random
.
RandomState
(
seed
=
utt
.
fetch_seed
())
rng
=
n
p
.
random
.
RandomState
(
seed
=
utt
.
fetch_seed
())
# test when the jacobian is called with a tensor as wrt
# test when the jacobian is called with a tensor as wrt
Jx
=
tensor
.
jacobian
(
y
,
x
)
Jx
=
tensor
.
jacobian
(
y
,
x
)
f
=
theano
.
function
([
x
],
Jx
)
f
=
theano
.
function
([
x
],
Jx
)
vx
=
rng
.
uniform
(
size
=
(
10
,))
.
astype
(
theano
.
config
.
floatX
)
vx
=
rng
.
uniform
(
size
=
(
10
,))
.
astype
(
theano
.
config
.
floatX
)
assert
n
umpy
.
allclose
(
f
(
vx
),
numpy
.
eye
(
10
)
*
2
)
assert
n
p
.
allclose
(
f
(
vx
),
np
.
eye
(
10
)
*
2
)
# test when the jacobian is called with a tuple as wrt
# test when the jacobian is called with a tuple as wrt
Jx
=
tensor
.
jacobian
(
y
,
(
x
,))
Jx
=
tensor
.
jacobian
(
y
,
(
x
,))
assert
isinstance
(
Jx
,
tuple
)
assert
isinstance
(
Jx
,
tuple
)
f
=
theano
.
function
([
x
],
Jx
[
0
])
f
=
theano
.
function
([
x
],
Jx
[
0
])
vx
=
rng
.
uniform
(
size
=
(
10
,))
.
astype
(
theano
.
config
.
floatX
)
vx
=
rng
.
uniform
(
size
=
(
10
,))
.
astype
(
theano
.
config
.
floatX
)
assert
n
umpy
.
allclose
(
f
(
vx
),
numpy
.
eye
(
10
)
*
2
)
assert
n
p
.
allclose
(
f
(
vx
),
np
.
eye
(
10
)
*
2
)
# test when the jacobian is called with a list as wrt
# test when the jacobian is called with a list as wrt
Jx
=
tensor
.
jacobian
(
y
,
[
x
])
Jx
=
tensor
.
jacobian
(
y
,
[
x
])
assert
isinstance
(
Jx
,
list
)
assert
isinstance
(
Jx
,
list
)
f
=
theano
.
function
([
x
],
Jx
[
0
])
f
=
theano
.
function
([
x
],
Jx
[
0
])
vx
=
rng
.
uniform
(
size
=
(
10
,))
.
astype
(
theano
.
config
.
floatX
)
vx
=
rng
.
uniform
(
size
=
(
10
,))
.
astype
(
theano
.
config
.
floatX
)
assert
n
umpy
.
allclose
(
f
(
vx
),
numpy
.
eye
(
10
)
*
2
)
assert
n
p
.
allclose
(
f
(
vx
),
np
.
eye
(
10
)
*
2
)
# test when the jacobian is called with a list of two elements
# test when the jacobian is called with a list of two elements
z
=
tensor
.
vector
()
z
=
tensor
.
vector
()
...
@@ -44,19 +44,19 @@ def test001_jacobian_vector():
...
@@ -44,19 +44,19 @@ def test001_jacobian_vector():
vx
=
rng
.
uniform
(
size
=
(
10
,))
.
astype
(
theano
.
config
.
floatX
)
vx
=
rng
.
uniform
(
size
=
(
10
,))
.
astype
(
theano
.
config
.
floatX
)
vz
=
rng
.
uniform
(
size
=
(
10
,))
.
astype
(
theano
.
config
.
floatX
)
vz
=
rng
.
uniform
(
size
=
(
10
,))
.
astype
(
theano
.
config
.
floatX
)
vJs
=
f
(
vx
,
vz
)
vJs
=
f
(
vx
,
vz
)
evx
=
n
umpy
.
zeros
((
10
,
10
))
evx
=
n
p
.
zeros
((
10
,
10
))
evz
=
n
umpy
.
zeros
((
10
,
10
))
evz
=
n
p
.
zeros
((
10
,
10
))
n
umpy
.
fill_diagonal
(
evx
,
vx
)
n
p
.
fill_diagonal
(
evx
,
vx
)
n
umpy
.
fill_diagonal
(
evz
,
vz
)
n
p
.
fill_diagonal
(
evz
,
vz
)
assert
n
umpy
.
allclose
(
vJs
[
0
],
evz
)
assert
n
p
.
allclose
(
vJs
[
0
],
evz
)
assert
n
umpy
.
allclose
(
vJs
[
1
],
evx
)
assert
n
p
.
allclose
(
vJs
[
1
],
evx
)
def
test002_jacobian_matrix
():
def
test002_jacobian_matrix
():
x
=
tensor
.
matrix
()
x
=
tensor
.
matrix
()
y
=
2
*
x
.
sum
(
axis
=
0
)
y
=
2
*
x
.
sum
(
axis
=
0
)
rng
=
n
umpy
.
random
.
RandomState
(
seed
=
utt
.
fetch_seed
())
rng
=
n
p
.
random
.
RandomState
(
seed
=
utt
.
fetch_seed
())
ev
=
n
umpy
.
zeros
((
10
,
10
,
10
))
ev
=
n
p
.
zeros
((
10
,
10
,
10
))
for
dx
in
xrange
(
10
):
for
dx
in
xrange
(
10
):
ev
[
dx
,
:,
dx
]
=
2.
ev
[
dx
,
:,
dx
]
=
2.
...
@@ -64,21 +64,21 @@ def test002_jacobian_matrix():
...
@@ -64,21 +64,21 @@ def test002_jacobian_matrix():
Jx
=
tensor
.
jacobian
(
y
,
x
)
Jx
=
tensor
.
jacobian
(
y
,
x
)
f
=
theano
.
function
([
x
],
Jx
)
f
=
theano
.
function
([
x
],
Jx
)
vx
=
rng
.
uniform
(
size
=
(
10
,
10
))
.
astype
(
theano
.
config
.
floatX
)
vx
=
rng
.
uniform
(
size
=
(
10
,
10
))
.
astype
(
theano
.
config
.
floatX
)
assert
n
umpy
.
allclose
(
f
(
vx
),
ev
)
assert
n
p
.
allclose
(
f
(
vx
),
ev
)
# test when the jacobian is called with a tuple as wrt
# test when the jacobian is called with a tuple as wrt
Jx
=
tensor
.
jacobian
(
y
,
(
x
,))
Jx
=
tensor
.
jacobian
(
y
,
(
x
,))
assert
isinstance
(
Jx
,
tuple
)
assert
isinstance
(
Jx
,
tuple
)
f
=
theano
.
function
([
x
],
Jx
[
0
])
f
=
theano
.
function
([
x
],
Jx
[
0
])
vx
=
rng
.
uniform
(
size
=
(
10
,
10
))
.
astype
(
theano
.
config
.
floatX
)
vx
=
rng
.
uniform
(
size
=
(
10
,
10
))
.
astype
(
theano
.
config
.
floatX
)
assert
n
umpy
.
allclose
(
f
(
vx
),
ev
)
assert
n
p
.
allclose
(
f
(
vx
),
ev
)
# test when the jacobian is called with a list as wrt
# test when the jacobian is called with a list as wrt
Jx
=
tensor
.
jacobian
(
y
,
[
x
])
Jx
=
tensor
.
jacobian
(
y
,
[
x
])
assert
isinstance
(
Jx
,
list
)
assert
isinstance
(
Jx
,
list
)
f
=
theano
.
function
([
x
],
Jx
[
0
])
f
=
theano
.
function
([
x
],
Jx
[
0
])
vx
=
rng
.
uniform
(
size
=
(
10
,
10
))
.
astype
(
theano
.
config
.
floatX
)
vx
=
rng
.
uniform
(
size
=
(
10
,
10
))
.
astype
(
theano
.
config
.
floatX
)
assert
n
umpy
.
allclose
(
f
(
vx
),
ev
)
assert
n
p
.
allclose
(
f
(
vx
),
ev
)
# test when the jacobian is called with a list of two elements
# test when the jacobian is called with a list of two elements
z
=
tensor
.
matrix
()
z
=
tensor
.
matrix
()
...
@@ -88,51 +88,51 @@ def test002_jacobian_matrix():
...
@@ -88,51 +88,51 @@ def test002_jacobian_matrix():
vx
=
rng
.
uniform
(
size
=
(
10
,
10
))
.
astype
(
theano
.
config
.
floatX
)
vx
=
rng
.
uniform
(
size
=
(
10
,
10
))
.
astype
(
theano
.
config
.
floatX
)
vz
=
rng
.
uniform
(
size
=
(
10
,
10
))
.
astype
(
theano
.
config
.
floatX
)
vz
=
rng
.
uniform
(
size
=
(
10
,
10
))
.
astype
(
theano
.
config
.
floatX
)
vJs
=
f
(
vx
,
vz
)
vJs
=
f
(
vx
,
vz
)
evx
=
n
umpy
.
zeros
((
10
,
10
,
10
))
evx
=
n
p
.
zeros
((
10
,
10
,
10
))
evz
=
n
umpy
.
zeros
((
10
,
10
,
10
))
evz
=
n
p
.
zeros
((
10
,
10
,
10
))
for
dx
in
xrange
(
10
):
for
dx
in
xrange
(
10
):
evx
[
dx
,
dx
,
:]
=
vx
[
dx
,
:]
evx
[
dx
,
dx
,
:]
=
vx
[
dx
,
:]
evz
[
dx
,
dx
,
:]
=
vz
[
dx
,
:]
evz
[
dx
,
dx
,
:]
=
vz
[
dx
,
:]
assert
n
umpy
.
allclose
(
vJs
[
0
],
evz
)
assert
n
p
.
allclose
(
vJs
[
0
],
evz
)
assert
n
umpy
.
allclose
(
vJs
[
1
],
evx
)
assert
n
p
.
allclose
(
vJs
[
1
],
evx
)
def
test003_jacobian_scalar
():
def
test003_jacobian_scalar
():
x
=
tensor
.
scalar
()
x
=
tensor
.
scalar
()
y
=
x
*
2
y
=
x
*
2
rng
=
n
umpy
.
random
.
RandomState
(
seed
=
utt
.
fetch_seed
())
rng
=
n
p
.
random
.
RandomState
(
seed
=
utt
.
fetch_seed
())
# test when the jacobian is called with a tensor as wrt
# test when the jacobian is called with a tensor as wrt
Jx
=
tensor
.
jacobian
(
y
,
x
)
Jx
=
tensor
.
jacobian
(
y
,
x
)
f
=
theano
.
function
([
x
],
Jx
)
f
=
theano
.
function
([
x
],
Jx
)
vx
=
n
umpy
.
cast
[
theano
.
config
.
floatX
](
rng
.
uniform
())
vx
=
n
p
.
cast
[
theano
.
config
.
floatX
](
rng
.
uniform
())
assert
n
umpy
.
allclose
(
f
(
vx
),
2
)
assert
n
p
.
allclose
(
f
(
vx
),
2
)
# test when the jacobian is called with a tuple as wrt
# test when the jacobian is called with a tuple as wrt
Jx
=
tensor
.
jacobian
(
y
,
(
x
,))
Jx
=
tensor
.
jacobian
(
y
,
(
x
,))
assert
isinstance
(
Jx
,
tuple
)
assert
isinstance
(
Jx
,
tuple
)
f
=
theano
.
function
([
x
],
Jx
[
0
])
f
=
theano
.
function
([
x
],
Jx
[
0
])
vx
=
n
umpy
.
cast
[
theano
.
config
.
floatX
](
rng
.
uniform
())
vx
=
n
p
.
cast
[
theano
.
config
.
floatX
](
rng
.
uniform
())
assert
n
umpy
.
allclose
(
f
(
vx
),
2
)
assert
n
p
.
allclose
(
f
(
vx
),
2
)
# test when the jacobian is called with a list as wrt
# test when the jacobian is called with a list as wrt
Jx
=
tensor
.
jacobian
(
y
,
[
x
])
Jx
=
tensor
.
jacobian
(
y
,
[
x
])
assert
isinstance
(
Jx
,
list
)
assert
isinstance
(
Jx
,
list
)
f
=
theano
.
function
([
x
],
Jx
[
0
])
f
=
theano
.
function
([
x
],
Jx
[
0
])
vx
=
n
umpy
.
cast
[
theano
.
config
.
floatX
](
rng
.
uniform
())
vx
=
n
p
.
cast
[
theano
.
config
.
floatX
](
rng
.
uniform
())
assert
n
umpy
.
allclose
(
f
(
vx
),
2
)
assert
n
p
.
allclose
(
f
(
vx
),
2
)
# test when the jacobian is called with a list of two elements
# test when the jacobian is called with a list of two elements
z
=
tensor
.
scalar
()
z
=
tensor
.
scalar
()
y
=
x
*
z
y
=
x
*
z
Jx
=
tensor
.
jacobian
(
y
,
[
x
,
z
])
Jx
=
tensor
.
jacobian
(
y
,
[
x
,
z
])
f
=
theano
.
function
([
x
,
z
],
Jx
)
f
=
theano
.
function
([
x
,
z
],
Jx
)
vx
=
n
umpy
.
cast
[
theano
.
config
.
floatX
](
rng
.
uniform
())
vx
=
n
p
.
cast
[
theano
.
config
.
floatX
](
rng
.
uniform
())
vz
=
n
umpy
.
cast
[
theano
.
config
.
floatX
](
rng
.
uniform
())
vz
=
n
p
.
cast
[
theano
.
config
.
floatX
](
rng
.
uniform
())
vJx
=
f
(
vx
,
vz
)
vJx
=
f
(
vx
,
vz
)
assert
n
umpy
.
allclose
(
vJx
[
0
],
vz
)
assert
n
p
.
allclose
(
vJx
[
0
],
vz
)
assert
n
umpy
.
allclose
(
vJx
[
1
],
vx
)
assert
n
p
.
allclose
(
vJx
[
1
],
vx
)
def
test004_hessian
():
def
test004_hessian
():
...
@@ -140,8 +140,8 @@ def test004_hessian():
...
@@ -140,8 +140,8 @@ def test004_hessian():
y
=
tensor
.
sum
(
x
**
2
)
y
=
tensor
.
sum
(
x
**
2
)
Hx
=
tensor
.
hessian
(
y
,
x
)
Hx
=
tensor
.
hessian
(
y
,
x
)
f
=
theano
.
function
([
x
],
Hx
)
f
=
theano
.
function
([
x
],
Hx
)
vx
=
n
umpy
.
arange
(
10
)
.
astype
(
theano
.
config
.
floatX
)
vx
=
n
p
.
arange
(
10
)
.
astype
(
theano
.
config
.
floatX
)
assert
n
umpy
.
allclose
(
f
(
vx
),
numpy
.
eye
(
10
)
*
2
)
assert
n
p
.
allclose
(
f
(
vx
),
np
.
eye
(
10
)
*
2
)
def
test_jacobian_disconnected_inputs
():
def
test_jacobian_disconnected_inputs
():
...
@@ -152,12 +152,12 @@ def test_jacobian_disconnected_inputs():
...
@@ -152,12 +152,12 @@ def test_jacobian_disconnected_inputs():
v2
=
tensor
.
vector
()
v2
=
tensor
.
vector
()
jacobian_v
=
theano
.
gradient
.
jacobian
(
1
+
v1
,
v2
,
disconnected_inputs
=
'ignore'
)
jacobian_v
=
theano
.
gradient
.
jacobian
(
1
+
v1
,
v2
,
disconnected_inputs
=
'ignore'
)
func_v
=
theano
.
function
([
v1
,
v2
],
jacobian_v
)
func_v
=
theano
.
function
([
v1
,
v2
],
jacobian_v
)
val
=
n
umpy
.
arange
(
4.0
)
.
astype
(
theano
.
config
.
floatX
)
val
=
n
p
.
arange
(
4.0
)
.
astype
(
theano
.
config
.
floatX
)
assert
n
umpy
.
allclose
(
func_v
(
val
,
val
),
numpy
.
zeros
((
4
,
4
)))
assert
n
p
.
allclose
(
func_v
(
val
,
val
),
np
.
zeros
((
4
,
4
)))
s1
=
tensor
.
scalar
()
s1
=
tensor
.
scalar
()
s2
=
tensor
.
scalar
()
s2
=
tensor
.
scalar
()
jacobian_s
=
theano
.
gradient
.
jacobian
(
1
+
s1
,
s2
,
disconnected_inputs
=
'ignore'
)
jacobian_s
=
theano
.
gradient
.
jacobian
(
1
+
s1
,
s2
,
disconnected_inputs
=
'ignore'
)
func_s
=
theano
.
function
([
s2
],
jacobian_s
)
func_s
=
theano
.
function
([
s2
],
jacobian_s
)
val
=
n
umpy
.
array
(
1.0
)
.
astype
(
theano
.
config
.
floatX
)
val
=
n
p
.
array
(
1.0
)
.
astype
(
theano
.
config
.
floatX
)
assert
n
umpy
.
allclose
(
func_s
(
val
),
numpy
.
zeros
(
1
))
assert
n
p
.
allclose
(
func_s
(
val
),
np
.
zeros
(
1
))
theano/tests/test_breakpoint.py
浏览文件 @
dded8355
from
__future__
import
absolute_import
,
print_function
,
division
from
__future__
import
absolute_import
,
print_function
,
division
import
numpy
import
numpy
as
np
import
theano
import
theano
import
theano.tensor
as
T
import
theano.tensor
as
T
from
theano.tests
import
unittest_tools
as
utt
from
theano.tests
import
unittest_tools
as
utt
...
@@ -30,7 +30,7 @@ class TestPdbBreakpoint(utt.InferShapeTester):
...
@@ -30,7 +30,7 @@ class TestPdbBreakpoint(utt.InferShapeTester):
def
test_infer_shape
(
self
):
def
test_infer_shape
(
self
):
input1_value
=
n
umpy
.
arange
(
6
)
.
reshape
(
2
,
3
)
.
astype
(
"float32"
)
input1_value
=
n
p
.
arange
(
6
)
.
reshape
(
2
,
3
)
.
astype
(
"float32"
)
input2_value
=
10.0
input2_value
=
10.0
self
.
_compile_and_check
([
self
.
input1
,
self
.
input2
],
self
.
_compile_and_check
([
self
.
input1
,
self
.
input2
],
...
@@ -42,7 +42,7 @@ class TestPdbBreakpoint(utt.InferShapeTester):
...
@@ -42,7 +42,7 @@ class TestPdbBreakpoint(utt.InferShapeTester):
def
test_grad
(
self
):
def
test_grad
(
self
):
input1_value
=
n
umpy
.
arange
(
9
)
.
reshape
(
3
,
3
)
.
astype
(
"float32"
)
input1_value
=
n
p
.
arange
(
9
)
.
reshape
(
3
,
3
)
.
astype
(
"float32"
)
input2_value
=
10.0
input2_value
=
10.0
grads
=
[
T
.
grad
(
self
.
monitored_input1
.
sum
(),
self
.
input1
),
grads
=
[
T
.
grad
(
self
.
monitored_input1
.
sum
(),
self
.
input1
),
...
@@ -56,22 +56,22 @@ class TestPdbBreakpoint(utt.InferShapeTester):
...
@@ -56,22 +56,22 @@ class TestPdbBreakpoint(utt.InferShapeTester):
gradients
=
fct
(
input1_value
,
input2_value
)[:
-
1
]
gradients
=
fct
(
input1_value
,
input2_value
)[:
-
1
]
expected_gradients
=
[
n
umpy
.
ones
((
3
,
3
),
dtype
=
"float32"
),
expected_gradients
=
[
n
p
.
ones
((
3
,
3
),
dtype
=
"float32"
),
n
umpy
.
array
(
1.
,
dtype
=
"float32"
)]
n
p
.
array
(
1.
,
dtype
=
"float32"
)]
for
i
in
range
(
len
(
gradients
)):
for
i
in
range
(
len
(
gradients
)):
n
umpy
.
testing
.
assert_allclose
(
gradients
[
i
],
expected_gradients
[
i
])
n
p
.
testing
.
assert_allclose
(
gradients
[
i
],
expected_gradients
[
i
])
def
test_fprop
(
self
):
def
test_fprop
(
self
):
input1_value
=
n
umpy
.
arange
(
9
)
.
reshape
(
3
,
3
)
.
astype
(
"float32"
)
input1_value
=
n
p
.
arange
(
9
)
.
reshape
(
3
,
3
)
.
astype
(
"float32"
)
input2_value
=
10.0
input2_value
=
10.0
fct
=
theano
.
function
([
self
.
input1
,
self
.
input2
],
fct
=
theano
.
function
([
self
.
input1
,
self
.
input2
],
[
self
.
monitored_input1
,
self
.
monitored_input2
])
[
self
.
monitored_input1
,
self
.
monitored_input2
])
output
=
fct
(
input1_value
,
input2_value
)
output
=
fct
(
input1_value
,
input2_value
)
n
umpy
.
testing
.
assert_allclose
(
output
[
0
],
input1_value
)
n
p
.
testing
.
assert_allclose
(
output
[
0
],
input1_value
)
n
umpy
.
testing
.
assert_allclose
(
output
[
1
],
input2_value
)
n
p
.
testing
.
assert_allclose
(
output
[
1
],
input2_value
)
def
test_connection_pattern
(
self
):
def
test_connection_pattern
(
self
):
...
...
theano/tests/test_ifelse.py
浏览文件 @
dded8355
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
from
__future__
import
absolute_import
,
print_function
,
division
from
__future__
import
absolute_import
,
print_function
,
division
import
unittest
import
unittest
import
numpy
import
numpy
as
np
from
nose.plugins.skip
import
SkipTest
from
nose.plugins.skip
import
SkipTest
from
six.moves
import
reduce
from
six.moves
import
reduce
...
@@ -42,16 +42,16 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin):
...
@@ -42,16 +42,16 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin):
c
=
tensor
.
iscalar
(
'c'
)
c
=
tensor
.
iscalar
(
'c'
)
f
=
theano
.
function
([
c
,
x
,
y
],
ifelse
(
c
,
x
,
y
),
mode
=
self
.
mode
)
f
=
theano
.
function
([
c
,
x
,
y
],
ifelse
(
c
,
x
,
y
),
mode
=
self
.
mode
)
self
.
assertFunctionContains1
(
f
,
self
.
get_ifelse
(
1
))
self
.
assertFunctionContains1
(
f
,
self
.
get_ifelse
(
1
))
rng
=
n
umpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
n
p
.
random
.
RandomState
(
utt
.
fetch_seed
())
xlen
=
rng
.
randint
(
200
)
xlen
=
rng
.
randint
(
200
)
ylen
=
rng
.
randint
(
200
)
ylen
=
rng
.
randint
(
200
)
vx
=
n
umpy
.
asarray
(
rng
.
uniform
(
size
=
(
xlen
,)),
self
.
dtype
)
vx
=
n
p
.
asarray
(
rng
.
uniform
(
size
=
(
xlen
,)),
self
.
dtype
)
vy
=
n
umpy
.
asarray
(
rng
.
uniform
(
size
=
(
ylen
,)),
self
.
dtype
)
vy
=
n
p
.
asarray
(
rng
.
uniform
(
size
=
(
ylen
,)),
self
.
dtype
)
assert
n
umpy
.
allclose
(
vx
,
f
(
1
,
vx
,
vy
))
assert
n
p
.
allclose
(
vx
,
f
(
1
,
vx
,
vy
))
assert
n
umpy
.
allclose
(
vy
,
f
(
0
,
vx
,
vy
))
assert
n
p
.
allclose
(
vy
,
f
(
0
,
vx
,
vy
))
def
test_not_lazy_if_inplace
(
self
):
def
test_not_lazy_if_inplace
(
self
):
# Tests that if the outputs are scalars and the graph is big,
# Tests that if the outputs are scalars and the graph is big,
...
@@ -71,16 +71,16 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin):
...
@@ -71,16 +71,16 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin):
if
isinstance
(
n
.
op
,
IfElse
)]
if
isinstance
(
n
.
op
,
IfElse
)]
assert
len
(
ifnode
)
==
1
assert
len
(
ifnode
)
==
1
assert
not
ifnode
[
0
]
.
op
.
as_view
assert
not
ifnode
[
0
]
.
op
.
as_view
rng
=
n
umpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
n
p
.
random
.
RandomState
(
utt
.
fetch_seed
())
xlen
=
rng
.
randint
(
200
)
xlen
=
rng
.
randint
(
200
)
ylen
=
rng
.
randint
(
200
)
ylen
=
rng
.
randint
(
200
)
vx
=
n
umpy
.
asarray
(
rng
.
uniform
(
size
=
(
xlen
,)),
self
.
dtype
)
vx
=
n
p
.
asarray
(
rng
.
uniform
(
size
=
(
xlen
,)),
self
.
dtype
)
vy
=
n
umpy
.
asarray
(
rng
.
uniform
(
size
=
(
ylen
,)),
self
.
dtype
)
vy
=
n
p
.
asarray
(
rng
.
uniform
(
size
=
(
ylen
,)),
self
.
dtype
)
assert
n
umpy
.
allclose
(
vx
,
f
(
1
,
vx
,
vy
))
assert
n
p
.
allclose
(
vx
,
f
(
1
,
vx
,
vy
))
assert
n
umpy
.
allclose
(
vy
+
sum
(
range
(
200
)),
f
(
0
,
vx
,
vy
))
assert
n
p
.
allclose
(
vy
+
sum
(
range
(
200
)),
f
(
0
,
vx
,
vy
))
def
test_mixed_dtype
(
self
):
def
test_mixed_dtype
(
self
):
x1
=
tensor
.
vector
(
'x1'
,
dtype
=
'int32'
)
x1
=
tensor
.
vector
(
'x1'
,
dtype
=
'int32'
)
...
@@ -91,23 +91,23 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin):
...
@@ -91,23 +91,23 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin):
f
=
theano
.
function
([
c
,
x1
,
x2
,
y1
,
y2
],
f
=
theano
.
function
([
c
,
x1
,
x2
,
y1
,
y2
],
ifelse
(
c
,
(
x1
,
x2
),
(
y1
,
y2
)),
mode
=
self
.
mode
)
ifelse
(
c
,
(
x1
,
x2
),
(
y1
,
y2
)),
mode
=
self
.
mode
)
self
.
assertFunctionContains1
(
f
,
self
.
get_ifelse
(
2
))
self
.
assertFunctionContains1
(
f
,
self
.
get_ifelse
(
2
))
rng
=
n
umpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
n
p
.
random
.
RandomState
(
utt
.
fetch_seed
())
xlen
=
rng
.
randint
(
200
)
xlen
=
rng
.
randint
(
200
)
ylen
=
rng
.
randint
(
200
)
ylen
=
rng
.
randint
(
200
)
vx1
=
n
umpy
.
asarray
(
rng
.
uniform
(
size
=
(
xlen
,))
*
3
,
'int32'
)
vx1
=
n
p
.
asarray
(
rng
.
uniform
(
size
=
(
xlen
,))
*
3
,
'int32'
)
vx2
=
n
umpy
.
asarray
(
rng
.
uniform
(
size
=
(
xlen
,)),
self
.
dtype
)
vx2
=
n
p
.
asarray
(
rng
.
uniform
(
size
=
(
xlen
,)),
self
.
dtype
)
vy1
=
n
umpy
.
asarray
(
rng
.
uniform
(
size
=
(
ylen
,))
*
3
,
'int32'
)
vy1
=
n
p
.
asarray
(
rng
.
uniform
(
size
=
(
ylen
,))
*
3
,
'int32'
)
vy2
=
n
umpy
.
asarray
(
rng
.
uniform
(
size
=
(
ylen
,)),
self
.
dtype
)
vy2
=
n
p
.
asarray
(
rng
.
uniform
(
size
=
(
ylen
,)),
self
.
dtype
)
o1
,
o2
=
f
(
1
,
vx1
,
vx2
,
vy1
,
vy2
)
o1
,
o2
=
f
(
1
,
vx1
,
vx2
,
vy1
,
vy2
)
assert
n
umpy
.
allclose
(
vx1
,
o1
)
assert
n
p
.
allclose
(
vx1
,
o1
)
assert
n
umpy
.
allclose
(
vx2
,
o2
)
assert
n
p
.
allclose
(
vx2
,
o2
)
o1
,
o2
=
f
(
0
,
vx1
,
vx2
,
vy1
,
vy2
)
o1
,
o2
=
f
(
0
,
vx1
,
vx2
,
vy1
,
vy2
)
assert
n
umpy
.
allclose
(
vy1
,
o1
)
assert
n
p
.
allclose
(
vy1
,
o1
)
assert
n
umpy
.
allclose
(
vy2
,
o2
)
assert
n
p
.
allclose
(
vy2
,
o2
)
def
test_lazy_if_on_generics
(
self
):
def
test_lazy_if_on_generics
(
self
):
x
=
theano
.
generic
()
x
=
theano
.
generic
()
...
@@ -134,24 +134,24 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin):
...
@@ -134,24 +134,24 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin):
# There is only 2 of the 3 ifelse that are moved on the GPU.
# There is only 2 of the 3 ifelse that are moved on the GPU.
# The one that stay on the CPU is for the shape.
# The one that stay on the CPU is for the shape.
self
.
assertFunctionContains
(
f
,
self
.
get_ifelse
(
1
),
min
=
2
,
max
=
3
)
self
.
assertFunctionContains
(
f
,
self
.
get_ifelse
(
1
),
min
=
2
,
max
=
3
)
rng
=
n
umpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
n
p
.
random
.
RandomState
(
utt
.
fetch_seed
())
xlen
=
rng
.
randint
(
200
)
xlen
=
rng
.
randint
(
200
)
ylen
=
rng
.
randint
(
200
)
ylen
=
rng
.
randint
(
200
)
vx
=
n
umpy
.
asarray
(
rng
.
uniform
(
size
=
(
xlen
,)),
self
.
dtype
)
vx
=
n
p
.
asarray
(
rng
.
uniform
(
size
=
(
xlen
,)),
self
.
dtype
)
vy
=
n
umpy
.
asarray
(
rng
.
uniform
(
size
=
(
ylen
,)),
self
.
dtype
)
vy
=
n
p
.
asarray
(
rng
.
uniform
(
size
=
(
ylen
,)),
self
.
dtype
)
gx0
,
gy0
=
f
(
1
,
vx
,
vy
)
gx0
,
gy0
=
f
(
1
,
vx
,
vy
)
assert
n
umpy
.
allclose
(
gx0
.
shape
,
vx
.
shape
)
assert
n
p
.
allclose
(
gx0
.
shape
,
vx
.
shape
)
assert
n
umpy
.
allclose
(
gy0
.
shape
,
vy
.
shape
)
assert
n
p
.
allclose
(
gy0
.
shape
,
vy
.
shape
)
assert
n
umpy
.
all
(
numpy
.
asarray
(
gx0
)
==
1.
)
assert
n
p
.
all
(
np
.
asarray
(
gx0
)
==
1.
)
assert
n
umpy
.
all
(
numpy
.
asarray
(
gy0
)
==
0.
)
assert
n
p
.
all
(
np
.
asarray
(
gy0
)
==
0.
)
gx0
,
gy0
=
f
(
0
,
vx
,
vy
)
gx0
,
gy0
=
f
(
0
,
vx
,
vy
)
assert
n
umpy
.
allclose
(
gx0
.
shape
,
vx
.
shape
)
assert
n
p
.
allclose
(
gx0
.
shape
,
vx
.
shape
)
assert
n
umpy
.
allclose
(
gy0
.
shape
,
vy
.
shape
)
assert
n
p
.
allclose
(
gy0
.
shape
,
vy
.
shape
)
assert
n
umpy
.
all
(
numpy
.
asarray
(
gx0
)
==
0.
)
assert
n
p
.
all
(
np
.
asarray
(
gx0
)
==
0.
)
assert
n
umpy
.
all
(
numpy
.
asarray
(
gy0
)
==
1.
)
assert
n
p
.
all
(
np
.
asarray
(
gy0
)
==
1.
)
def
test_grad_cast_input
(
self
):
def
test_grad_cast_input
(
self
):
# Tests the gradient when both inputs are on the GPU.
# Tests the gradient when both inputs are on the GPU.
...
@@ -178,24 +178,24 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin):
...
@@ -178,24 +178,24 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin):
if
isinstance
(
x
.
op
,
IfElse
)][
0
]
if
isinstance
(
x
.
op
,
IfElse
)][
0
]
assert
len
(
ifnode
.
outputs
)
==
2
assert
len
(
ifnode
.
outputs
)
==
2
rng
=
n
umpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
n
p
.
random
.
RandomState
(
utt
.
fetch_seed
())
x1len
=
rng
.
randint
(
200
)
x1len
=
rng
.
randint
(
200
)
x2len
=
rng
.
randint
(
200
)
x2len
=
rng
.
randint
(
200
)
y1len
=
rng
.
randint
(
200
)
y1len
=
rng
.
randint
(
200
)
y2len
=
rng
.
randint
(
200
)
y2len
=
rng
.
randint
(
200
)
vx1
=
n
umpy
.
asarray
(
rng
.
uniform
(
size
=
(
x1len
,)),
self
.
dtype
)
vx1
=
n
p
.
asarray
(
rng
.
uniform
(
size
=
(
x1len
,)),
self
.
dtype
)
vx2
=
n
umpy
.
asarray
(
rng
.
uniform
(
size
=
(
x2len
,)),
self
.
dtype
)
vx2
=
n
p
.
asarray
(
rng
.
uniform
(
size
=
(
x2len
,)),
self
.
dtype
)
vy1
=
n
umpy
.
asarray
(
rng
.
uniform
(
size
=
(
y1len
,)),
self
.
dtype
)
vy1
=
n
p
.
asarray
(
rng
.
uniform
(
size
=
(
y1len
,)),
self
.
dtype
)
vy2
=
n
umpy
.
asarray
(
rng
.
uniform
(
size
=
(
y2len
,)),
self
.
dtype
)
vy2
=
n
p
.
asarray
(
rng
.
uniform
(
size
=
(
y2len
,)),
self
.
dtype
)
ovx1
,
ovx2
=
f
(
1
,
vx1
,
vx2
,
vy1
,
vy2
)
ovx1
,
ovx2
=
f
(
1
,
vx1
,
vx2
,
vy1
,
vy2
)
ovy1
,
ovy2
=
f
(
0
,
vx1
,
vx2
,
vy1
,
vy2
)
ovy1
,
ovy2
=
f
(
0
,
vx1
,
vx2
,
vy1
,
vy2
)
assert
n
umpy
.
allclose
(
vx1
,
ovx1
)
assert
n
p
.
allclose
(
vx1
,
ovx1
)
assert
n
umpy
.
allclose
(
vy1
,
ovy1
)
assert
n
p
.
allclose
(
vy1
,
ovy1
)
assert
n
umpy
.
allclose
(
vx2
,
ovx2
)
assert
n
p
.
allclose
(
vx2
,
ovx2
)
assert
n
umpy
.
allclose
(
vy2
,
ovy2
)
assert
n
p
.
allclose
(
vy2
,
ovy2
)
def
test_multiple_out_grad
(
self
):
def
test_multiple_out_grad
(
self
):
# Tests that we can compute the gradients through lazy if
# Tests that we can compute the gradients through lazy if
...
@@ -209,34 +209,34 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin):
...
@@ -209,34 +209,34 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin):
[
x1
,
x2
,
y1
,
y2
])
[
x1
,
x2
,
y1
,
y2
])
f
=
theano
.
function
([
c
,
x1
,
x2
,
y1
,
y2
],
grads
)
f
=
theano
.
function
([
c
,
x1
,
x2
,
y1
,
y2
],
grads
)
rng
=
n
umpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
n
p
.
random
.
RandomState
(
utt
.
fetch_seed
())
lens
=
[
rng
.
randint
(
200
)
for
i
in
range
(
4
)]
lens
=
[
rng
.
randint
(
200
)
for
i
in
range
(
4
)]
values
=
[
n
umpy
.
asarray
(
rng
.
uniform
(
size
=
(
l
,)),
theano
.
config
.
floatX
)
values
=
[
n
p
.
asarray
(
rng
.
uniform
(
size
=
(
l
,)),
theano
.
config
.
floatX
)
for
l
in
lens
]
for
l
in
lens
]
outs_1
=
f
(
1
,
*
values
)
outs_1
=
f
(
1
,
*
values
)
assert
all
([
x
.
shape
[
0
]
==
y
for
x
,
y
in
zip
(
outs_1
,
lens
)])
assert
all
([
x
.
shape
[
0
]
==
y
for
x
,
y
in
zip
(
outs_1
,
lens
)])
assert
n
umpy
.
all
(
outs_1
[
0
]
==
1.
)
assert
n
p
.
all
(
outs_1
[
0
]
==
1.
)
assert
n
umpy
.
all
(
outs_1
[
1
]
==
1.
)
assert
n
p
.
all
(
outs_1
[
1
]
==
1.
)
assert
n
umpy
.
all
(
outs_1
[
2
]
==
0.
)
assert
n
p
.
all
(
outs_1
[
2
]
==
0.
)
assert
n
umpy
.
all
(
outs_1
[
3
]
==
0.
)
assert
n
p
.
all
(
outs_1
[
3
]
==
0.
)
outs_0
=
f
(
0
,
*
values
)
outs_0
=
f
(
0
,
*
values
)
assert
all
([
x
.
shape
[
0
]
==
y
for
x
,
y
in
zip
(
outs_1
,
lens
)])
assert
all
([
x
.
shape
[
0
]
==
y
for
x
,
y
in
zip
(
outs_1
,
lens
)])
assert
n
umpy
.
all
(
outs_0
[
0
]
==
0.
)
assert
n
p
.
all
(
outs_0
[
0
]
==
0.
)
assert
n
umpy
.
all
(
outs_0
[
1
]
==
0.
)
assert
n
p
.
all
(
outs_0
[
1
]
==
0.
)
assert
n
umpy
.
all
(
outs_0
[
2
]
==
1.
)
assert
n
p
.
all
(
outs_0
[
2
]
==
1.
)
assert
n
umpy
.
all
(
outs_0
[
3
]
==
1.
)
assert
n
p
.
all
(
outs_0
[
3
]
==
1.
)
def
test_multiple_out_crash
(
self
):
def
test_multiple_out_crash
(
self
):
# This test failed up to commit 2faeb62c38
# This test failed up to commit 2faeb62c38
p0
=
self
.
shared
(
n
umpy
.
asarray
(
numpy
.
random
.
random
([
4
,
8
]),
p0
=
self
.
shared
(
n
p
.
asarray
(
np
.
random
.
random
([
4
,
8
]),
dtype
=
self
.
dtype
))
dtype
=
self
.
dtype
))
p1
=
self
.
shared
(
n
umpy
.
asarray
(
numpy
.
random
.
random
(
8
),
p1
=
self
.
shared
(
n
p
.
asarray
(
np
.
random
.
random
(
8
),
dtype
=
self
.
dtype
))
dtype
=
self
.
dtype
))
p2
=
self
.
shared
(
n
umpy
.
asarray
(
numpy
.
random
.
random
([
8
,
3
]),
p2
=
self
.
shared
(
n
p
.
asarray
(
np
.
random
.
random
([
8
,
3
]),
dtype
=
self
.
dtype
))
dtype
=
self
.
dtype
))
p3
=
self
.
shared
(
n
umpy
.
asarray
(
numpy
.
random
.
random
(
3
),
p3
=
self
.
shared
(
n
p
.
asarray
(
np
.
random
.
random
(
3
),
dtype
=
self
.
dtype
))
dtype
=
self
.
dtype
))
p
=
[
p0
,
p1
,
p2
,
p3
]
p
=
[
p0
,
p1
,
p2
,
p3
]
...
@@ -264,15 +264,15 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin):
...
@@ -264,15 +264,15 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin):
updates
=
new_updates
,
mode
=
self
.
mode
)
updates
=
new_updates
,
mode
=
self
.
mode
)
self
.
assertFunctionContains1
(
f
,
self
.
get_ifelse
(
4
))
self
.
assertFunctionContains1
(
f
,
self
.
get_ifelse
(
4
))
i1
=
n
umpy
.
asarray
(
numpy
.
random
.
random
([
19
,
4
,
8
]),
dtype
=
self
.
dtype
)
i1
=
n
p
.
asarray
(
np
.
random
.
random
([
19
,
4
,
8
]),
dtype
=
self
.
dtype
)
i2
=
n
umpy
.
asarray
(
numpy
.
random
.
random
([
19
,
8
]),
dtype
=
self
.
dtype
)
i2
=
n
p
.
asarray
(
np
.
random
.
random
([
19
,
8
]),
dtype
=
self
.
dtype
)
i3
=
n
umpy
.
asarray
(
numpy
.
random
.
random
([
19
,
8
,
3
]),
dtype
=
self
.
dtype
)
i3
=
n
p
.
asarray
(
np
.
random
.
random
([
19
,
8
,
3
]),
dtype
=
self
.
dtype
)
i4
=
n
umpy
.
asarray
(
numpy
.
random
.
random
([
19
,
3
]),
dtype
=
self
.
dtype
)
i4
=
n
p
.
asarray
(
np
.
random
.
random
([
19
,
3
]),
dtype
=
self
.
dtype
)
f
(
i1
,
i2
,
i3
,
i4
)
f
(
i1
,
i2
,
i3
,
i4
)
def
test_dtype_mismatch
(
self
):
def
test_dtype_mismatch
(
self
):
rng
=
n
umpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
n
p
.
random
.
RandomState
(
utt
.
fetch_seed
())
data
=
rng
.
rand
(
5
)
.
astype
(
self
.
dtype
)
data
=
rng
.
rand
(
5
)
.
astype
(
self
.
dtype
)
x
=
self
.
shared
(
data
)
x
=
self
.
shared
(
data
)
y
=
tensor
.
cast
(
x
*
10
,
'int8'
)
y
=
tensor
.
cast
(
x
*
10
,
'int8'
)
...
@@ -282,7 +282,7 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin):
...
@@ -282,7 +282,7 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin):
self
.
assertRaises
(
TypeError
,
ifelse
,
cond
,
y
,
x
)
self
.
assertRaises
(
TypeError
,
ifelse
,
cond
,
y
,
x
)
def
test_ndim_mismatch
(
self
):
def
test_ndim_mismatch
(
self
):
rng
=
n
umpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
n
p
.
random
.
RandomState
(
utt
.
fetch_seed
())
data
=
rng
.
rand
(
5
)
.
astype
(
self
.
dtype
)
data
=
rng
.
rand
(
5
)
.
astype
(
self
.
dtype
)
x
=
self
.
shared
(
data
)
x
=
self
.
shared
(
data
)
y
=
tensor
.
col
(
'y'
,
self
.
dtype
)
y
=
tensor
.
col
(
'y'
,
self
.
dtype
)
...
@@ -292,7 +292,7 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin):
...
@@ -292,7 +292,7 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin):
self
.
assertRaises
(
TypeError
,
ifelse
,
cond
,
y
,
x
)
self
.
assertRaises
(
TypeError
,
ifelse
,
cond
,
y
,
x
)
def
test_broadcast_mismatch
(
self
):
def
test_broadcast_mismatch
(
self
):
rng
=
n
umpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
n
p
.
random
.
RandomState
(
utt
.
fetch_seed
())
data
=
rng
.
rand
(
5
)
.
astype
(
self
.
dtype
)
data
=
rng
.
rand
(
5
)
.
astype
(
self
.
dtype
)
x
=
self
.
shared
(
data
)
x
=
self
.
shared
(
data
)
# print x.broadcastable
# print x.broadcastable
...
@@ -307,7 +307,7 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin):
...
@@ -307,7 +307,7 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin):
import
theano.sparse
import
theano.sparse
if
not
theano
.
sparse
.
enable_sparse
:
if
not
theano
.
sparse
.
enable_sparse
:
raise
SkipTest
(
"Optimization temporarily disabled"
)
raise
SkipTest
(
"Optimization temporarily disabled"
)
rng
=
n
umpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
n
p
.
random
.
RandomState
(
utt
.
fetch_seed
())
data
=
rng
.
rand
(
2
,
3
)
.
astype
(
self
.
dtype
)
data
=
rng
.
rand
(
2
,
3
)
.
astype
(
self
.
dtype
)
x
=
self
.
shared
(
data
)
x
=
self
.
shared
(
data
)
y
=
theano
.
sparse
.
matrix
(
'csc'
,
dtype
=
self
.
dtype
,
name
=
'y'
)
y
=
theano
.
sparse
.
matrix
(
'csc'
,
dtype
=
self
.
dtype
,
name
=
'y'
)
...
@@ -375,7 +375,7 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin):
...
@@ -375,7 +375,7 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin):
f
=
theano
.
function
([
x1
,
x2
,
y1
,
y2
,
w1
,
w2
,
c
],
out
,
f
=
theano
.
function
([
x1
,
x2
,
y1
,
y2
,
w1
,
w2
,
c
],
out
,
allow_input_downcast
=
True
)
allow_input_downcast
=
True
)
assert
isinstance
(
f
.
maker
.
fgraph
.
toposort
()[
-
1
]
.
op
,
IfElse
)
assert
isinstance
(
f
.
maker
.
fgraph
.
toposort
()[
-
1
]
.
op
,
IfElse
)
rng
=
n
umpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
n
p
.
random
.
RandomState
(
utt
.
fetch_seed
())
vx1
=
rng
.
uniform
()
vx1
=
rng
.
uniform
()
vx2
=
rng
.
uniform
()
vx2
=
rng
.
uniform
()
vy1
=
rng
.
uniform
()
vy1
=
rng
.
uniform
()
...
@@ -383,9 +383,9 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin):
...
@@ -383,9 +383,9 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin):
vw1
=
rng
.
uniform
()
vw1
=
rng
.
uniform
()
vw2
=
rng
.
uniform
()
vw2
=
rng
.
uniform
()
assert
n
umpy
.
allclose
(
f
(
vx1
,
vx2
,
vy1
,
vy2
,
vw1
,
vw2
,
1
),
assert
n
p
.
allclose
(
f
(
vx1
,
vx2
,
vy1
,
vy2
,
vw1
,
vw2
,
1
),
vx1
*
vy1
*
vw1
)
vx1
*
vy1
*
vw1
)
assert
n
umpy
.
allclose
(
f
(
vx1
,
vx2
,
vy1
,
vy2
,
vw1
,
vw2
,
0
),
assert
n
p
.
allclose
(
f
(
vx1
,
vx2
,
vy1
,
vy2
,
vw1
,
vw2
,
0
),
vx2
*
vy2
*
vw2
)
vx2
*
vy2
*
vw2
)
def
test_pushout3
(
self
):
def
test_pushout3
(
self
):
...
@@ -394,23 +394,23 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin):
...
@@ -394,23 +394,23 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin):
y1
=
tensor
.
scalar
(
'x2'
)
y1
=
tensor
.
scalar
(
'x2'
)
y2
=
tensor
.
scalar
(
'y2'
)
y2
=
tensor
.
scalar
(
'y2'
)
c
=
tensor
.
iscalar
(
'c'
)
c
=
tensor
.
iscalar
(
'c'
)
two
=
n
umpy
.
asarray
(
2
,
dtype
=
theano
.
config
.
floatX
)
two
=
n
p
.
asarray
(
2
,
dtype
=
theano
.
config
.
floatX
)
x
,
y
=
ifelse
(
c
,
(
x1
,
y1
),
(
two
,
y2
),
name
=
'f1'
)
x
,
y
=
ifelse
(
c
,
(
x1
,
y1
),
(
two
,
y2
),
name
=
'f1'
)
o3
=
n
umpy
.
asarray
(
0.3
,
dtype
=
theano
.
config
.
floatX
)
o3
=
n
p
.
asarray
(
0.3
,
dtype
=
theano
.
config
.
floatX
)
o2
=
n
umpy
.
asarray
(
0.2
,
dtype
=
theano
.
config
.
floatX
)
o2
=
n
p
.
asarray
(
0.2
,
dtype
=
theano
.
config
.
floatX
)
z
=
ifelse
(
c
,
o3
,
o2
,
name
=
'f2'
)
z
=
ifelse
(
c
,
o3
,
o2
,
name
=
'f2'
)
out
=
x
*
z
*
y
out
=
x
*
z
*
y
f
=
theano
.
function
([
x1
,
y1
,
y2
,
c
],
out
,
f
=
theano
.
function
([
x1
,
y1
,
y2
,
c
],
out
,
allow_input_downcast
=
True
)
allow_input_downcast
=
True
)
assert
isinstance
(
f
.
maker
.
fgraph
.
toposort
()[
-
1
]
.
op
,
IfElse
)
assert
isinstance
(
f
.
maker
.
fgraph
.
toposort
()[
-
1
]
.
op
,
IfElse
)
rng
=
n
umpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
n
p
.
random
.
RandomState
(
utt
.
fetch_seed
())
vx1
=
rng
.
uniform
()
vx1
=
rng
.
uniform
()
vy1
=
rng
.
uniform
()
vy1
=
rng
.
uniform
()
vy2
=
rng
.
uniform
()
vy2
=
rng
.
uniform
()
assert
n
umpy
.
allclose
(
f
(
vx1
,
vy1
,
vy2
,
1
),
vx1
*
vy1
*
0.3
)
assert
n
p
.
allclose
(
f
(
vx1
,
vy1
,
vy2
,
1
),
vx1
*
vy1
*
0.3
)
assert
n
umpy
.
allclose
(
f
(
vx1
,
vy1
,
vy2
,
0
),
2
*
vy2
*
0.2
)
assert
n
p
.
allclose
(
f
(
vx1
,
vy1
,
vy2
,
0
),
2
*
vy2
*
0.2
)
def
test_pushout2
(
self
):
def
test_pushout2
(
self
):
raise
SkipTest
(
"Optimization temporarily disabled"
)
raise
SkipTest
(
"Optimization temporarily disabled"
)
...
@@ -428,7 +428,7 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin):
...
@@ -428,7 +428,7 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin):
f
=
theano
.
function
([
x1
,
x2
,
y1
,
y2
,
w1
,
w2
,
c
],
out
,
f
=
theano
.
function
([
x1
,
x2
,
y1
,
y2
,
w1
,
w2
,
c
],
out
,
allow_input_downcast
=
True
)
allow_input_downcast
=
True
)
assert
isinstance
(
f
.
maker
.
fgraph
.
toposort
()[
-
1
]
.
op
,
IfElse
)
assert
isinstance
(
f
.
maker
.
fgraph
.
toposort
()[
-
1
]
.
op
,
IfElse
)
rng
=
n
umpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
n
p
.
random
.
RandomState
(
utt
.
fetch_seed
())
vx1
=
rng
.
uniform
()
vx1
=
rng
.
uniform
()
vx2
=
rng
.
uniform
()
vx2
=
rng
.
uniform
()
vy1
=
rng
.
uniform
()
vy1
=
rng
.
uniform
()
...
@@ -439,14 +439,14 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin):
...
@@ -439,14 +439,14 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin):
vw
=
vw1
vw
=
vw1
else
:
else
:
vw
=
vw2
vw
=
vw2
assert
n
umpy
.
allclose
(
f
(
vx1
,
vx2
,
vy1
,
vy2
,
vw1
,
vw2
,
1
),
assert
n
p
.
allclose
(
f
(
vx1
,
vx2
,
vy1
,
vy2
,
vw1
,
vw2
,
1
),
vx1
*
vy1
*
vw
)
vx1
*
vy1
*
vw
)
if
vx2
>
vy2
:
if
vx2
>
vy2
:
vw
=
vw1
vw
=
vw1
else
:
else
:
vw
=
vw2
vw
=
vw2
assert
n
umpy
.
allclose
(
f
(
vx1
,
vx2
,
vy1
,
vy2
,
vw1
,
vw2
,
0
),
assert
n
p
.
allclose
(
f
(
vx1
,
vx2
,
vy1
,
vy2
,
vw1
,
vw2
,
0
),
vx2
*
vy2
*
vw
)
vx2
*
vy2
*
vw
)
def
test_merge_ifs_true_false
(
self
):
def
test_merge_ifs_true_false
(
self
):
...
@@ -467,16 +467,16 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin):
...
@@ -467,16 +467,16 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin):
assert
len
([
x
for
x
in
f
.
maker
.
fgraph
.
toposort
()
assert
len
([
x
for
x
in
f
.
maker
.
fgraph
.
toposort
()
if
isinstance
(
x
.
op
,
IfElse
)])
==
1
if
isinstance
(
x
.
op
,
IfElse
)])
==
1
rng
=
n
umpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
n
p
.
random
.
RandomState
(
utt
.
fetch_seed
())
vx1
=
rng
.
uniform
()
vx1
=
rng
.
uniform
()
vx2
=
rng
.
uniform
()
vx2
=
rng
.
uniform
()
vy1
=
rng
.
uniform
()
vy1
=
rng
.
uniform
()
vy2
=
rng
.
uniform
()
vy2
=
rng
.
uniform
()
vw1
=
rng
.
uniform
()
vw1
=
rng
.
uniform
()
vw2
=
rng
.
uniform
()
vw2
=
rng
.
uniform
()
assert
n
umpy
.
allclose
(
f
(
vx1
,
vx2
,
vy1
,
vy2
,
vw1
,
vw2
,
1
),
assert
n
p
.
allclose
(
f
(
vx1
,
vx2
,
vy1
,
vy2
,
vw1
,
vw2
,
1
),
vx1
+
vy1
+
vw1
)
vx1
+
vy1
+
vw1
)
assert
n
umpy
.
allclose
(
f
(
vx1
,
vx2
,
vy1
,
vy2
,
vw1
,
vw2
,
0
),
assert
n
p
.
allclose
(
f
(
vx1
,
vx2
,
vy1
,
vy2
,
vw1
,
vw2
,
0
),
vx2
+
vy2
+
vw2
)
vx2
+
vy2
+
vw2
)
def
test_grad_test_values
(
self
):
def
test_grad_test_values
(
self
):
...
@@ -494,8 +494,8 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin):
...
@@ -494,8 +494,8 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin):
theano
.
config
.
compute_test_value
=
backup
theano
.
config
.
compute_test_value
=
backup
def
test_grad_int_value
(
self
):
def
test_grad_int_value
(
self
):
w
=
theano
.
shared
(
n
umpy
.
random
.
rand
(
10
))
w
=
theano
.
shared
(
n
p
.
random
.
rand
(
10
))
b
=
theano
.
shared
(
n
umpy
.
random
.
rand
())
b
=
theano
.
shared
(
n
p
.
random
.
rand
())
params
=
[
w
,
b
]
params
=
[
w
,
b
]
x
=
tensor
.
vector
()
x
=
tensor
.
vector
()
...
...
theano/tests/test_pickle_unpickle_theano_fn.py
浏览文件 @
dded8355
...
@@ -14,7 +14,7 @@ The config option is in configdefaults.py
...
@@ -14,7 +14,7 @@ The config option is in configdefaults.py
This note is written by Li Yao.
This note is written by Li Yao.
"""
"""
from
collections
import
OrderedDict
from
collections
import
OrderedDict
import
numpy
import
numpy
as
np
import
six.moves.cPickle
as
pickle
import
six.moves.cPickle
as
pickle
import
theano
import
theano
import
theano.tensor
as
T
import
theano.tensor
as
T
...
@@ -28,8 +28,8 @@ def test_pickle_unpickle_with_reoptimization():
...
@@ -28,8 +28,8 @@ def test_pickle_unpickle_with_reoptimization():
mode
=
"FAST_RUN"
mode
=
"FAST_RUN"
x1
=
T
.
fmatrix
(
'x1'
)
x1
=
T
.
fmatrix
(
'x1'
)
x2
=
T
.
fmatrix
(
'x2'
)
x2
=
T
.
fmatrix
(
'x2'
)
x3
=
theano
.
shared
(
n
umpy
.
ones
((
10
,
10
),
dtype
=
floatX
))
x3
=
theano
.
shared
(
n
p
.
ones
((
10
,
10
),
dtype
=
floatX
))
x4
=
theano
.
shared
(
n
umpy
.
ones
((
10
,
10
),
dtype
=
floatX
))
x4
=
theano
.
shared
(
n
p
.
ones
((
10
,
10
),
dtype
=
floatX
))
y
=
T
.
sum
(
T
.
sum
(
T
.
sum
(
x1
**
2
+
x2
)
+
x3
)
+
x4
)
y
=
T
.
sum
(
T
.
sum
(
T
.
sum
(
x1
**
2
+
x2
)
+
x3
)
+
x4
)
updates
=
OrderedDict
()
updates
=
OrderedDict
()
...
@@ -40,8 +40,8 @@ def test_pickle_unpickle_with_reoptimization():
...
@@ -40,8 +40,8 @@ def test_pickle_unpickle_with_reoptimization():
# now pickle the compiled theano fn
# now pickle the compiled theano fn
string_pkl
=
pickle
.
dumps
(
f
,
-
1
)
string_pkl
=
pickle
.
dumps
(
f
,
-
1
)
in1
=
n
umpy
.
ones
((
10
,
10
),
dtype
=
floatX
)
in1
=
n
p
.
ones
((
10
,
10
),
dtype
=
floatX
)
in2
=
n
umpy
.
ones
((
10
,
10
),
dtype
=
floatX
)
in2
=
n
p
.
ones
((
10
,
10
),
dtype
=
floatX
)
# test unpickle with optimization
# test unpickle with optimization
default
=
theano
.
config
.
reoptimize_unpickled_function
default
=
theano
.
config
.
reoptimize_unpickled_function
...
@@ -60,8 +60,8 @@ def test_pickle_unpickle_without_reoptimization():
...
@@ -60,8 +60,8 @@ def test_pickle_unpickle_without_reoptimization():
mode
=
"FAST_RUN"
mode
=
"FAST_RUN"
x1
=
T
.
fmatrix
(
'x1'
)
x1
=
T
.
fmatrix
(
'x1'
)
x2
=
T
.
fmatrix
(
'x2'
)
x2
=
T
.
fmatrix
(
'x2'
)
x3
=
theano
.
shared
(
n
umpy
.
ones
((
10
,
10
),
dtype
=
floatX
))
x3
=
theano
.
shared
(
n
p
.
ones
((
10
,
10
),
dtype
=
floatX
))
x4
=
theano
.
shared
(
n
umpy
.
ones
((
10
,
10
),
dtype
=
floatX
))
x4
=
theano
.
shared
(
n
p
.
ones
((
10
,
10
),
dtype
=
floatX
))
y
=
T
.
sum
(
T
.
sum
(
T
.
sum
(
x1
**
2
+
x2
)
+
x3
)
+
x4
)
y
=
T
.
sum
(
T
.
sum
(
T
.
sum
(
x1
**
2
+
x2
)
+
x3
)
+
x4
)
updates
=
OrderedDict
()
updates
=
OrderedDict
()
...
@@ -73,8 +73,8 @@ def test_pickle_unpickle_without_reoptimization():
...
@@ -73,8 +73,8 @@ def test_pickle_unpickle_without_reoptimization():
string_pkl
=
pickle
.
dumps
(
f
,
-
1
)
string_pkl
=
pickle
.
dumps
(
f
,
-
1
)
# compute f value
# compute f value
in1
=
n
umpy
.
ones
((
10
,
10
),
dtype
=
floatX
)
in1
=
n
p
.
ones
((
10
,
10
),
dtype
=
floatX
)
in2
=
n
umpy
.
ones
((
10
,
10
),
dtype
=
floatX
)
in2
=
n
p
.
ones
((
10
,
10
),
dtype
=
floatX
)
# test unpickle without optimization
# test unpickle without optimization
default
=
theano
.
config
.
reoptimize_unpickled_function
default
=
theano
.
config
.
reoptimize_unpickled_function
...
...
theano/tests/test_printing.py
浏览文件 @
dded8355
...
@@ -5,7 +5,7 @@ from __future__ import absolute_import, print_function, division
...
@@ -5,7 +5,7 @@ from __future__ import absolute_import, print_function, division
import
logging
import
logging
from
nose.plugins.skip
import
SkipTest
from
nose.plugins.skip
import
SkipTest
import
numpy
import
numpy
as
np
from
six.moves
import
StringIO
from
six.moves
import
StringIO
...
@@ -509,8 +509,8 @@ def test_scan_debugprint4():
...
@@ -509,8 +509,8 @@ def test_scan_debugprint4():
def
fn
(
a_m2
,
a_m1
,
b_m2
,
b_m1
):
def
fn
(
a_m2
,
a_m1
,
b_m2
,
b_m1
):
return
a_m1
+
a_m2
,
b_m1
+
b_m2
return
a_m1
+
a_m2
,
b_m1
+
b_m2
a0
=
theano
.
shared
(
n
umpy
.
arange
(
2
,
dtype
=
'int64'
))
a0
=
theano
.
shared
(
n
p
.
arange
(
2
,
dtype
=
'int64'
))
b0
=
theano
.
shared
(
n
umpy
.
arange
(
2
,
dtype
=
'int64'
))
b0
=
theano
.
shared
(
n
p
.
arange
(
2
,
dtype
=
'int64'
))
(
a
,
b
),
_
=
theano
.
scan
(
(
a
,
b
),
_
=
theano
.
scan
(
fn
,
outputs_info
=
[{
'initial'
:
a0
,
'taps'
:
[
-
2
,
-
1
]},
fn
,
outputs_info
=
[{
'initial'
:
a0
,
'taps'
:
[
-
2
,
-
1
]},
...
...
theano/tests/test_rop.py
浏览文件 @
dded8355
...
@@ -18,7 +18,7 @@ from theano import function
...
@@ -18,7 +18,7 @@ from theano import function
import
theano
import
theano
from
theano
import
tensor
from
theano
import
tensor
import
itertools
import
itertools
import
numpy
import
numpy
as
np
from
theano.gof
import
Op
,
Apply
from
theano.gof
import
Op
,
Apply
from
theano.gradient
import
grad_undefined
from
theano.gradient
import
grad_undefined
from
theano.tests.unittest_tools
import
SkipTest
from
theano.tests.unittest_tools
import
SkipTest
...
@@ -64,7 +64,7 @@ class RopLop_checker(unittest.TestCase):
...
@@ -64,7 +64,7 @@ class RopLop_checker(unittest.TestCase):
# computations using scan
# computations using scan
self
.
x
=
tensor
.
vector
(
'x'
)
self
.
x
=
tensor
.
vector
(
'x'
)
self
.
v
=
tensor
.
vector
(
'v'
)
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
.
in_shape
=
(
5
+
self
.
rng
.
randint
(
3
),)
self
.
mx
=
tensor
.
matrix
(
'mx'
)
self
.
mx
=
tensor
.
matrix
(
'mx'
)
self
.
mv
=
tensor
.
matrix
(
'mv'
)
self
.
mv
=
tensor
.
matrix
(
'mv'
)
...
@@ -103,9 +103,9 @@ class RopLop_checker(unittest.TestCase):
...
@@ -103,9 +103,9 @@ class RopLop_checker(unittest.TestCase):
If you want to test an Op with an output matrix, add a sum
If you want to test an Op with an output matrix, add a sum
after the Op you want to test.
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
)
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
)
theano
.
config
.
floatX
)
yv
=
tensor
.
Rop
(
y
,
self
.
mx
,
self
.
mv
)
yv
=
tensor
.
Rop
(
y
,
self
.
mx
,
self
.
mv
)
rop_f
=
function
([
self
.
mx
,
self
.
mv
],
yv
,
on_unused_input
=
'ignore'
)
rop_f
=
function
([
self
.
mx
,
self
.
mv
],
yv
,
on_unused_input
=
'ignore'
)
...
@@ -118,11 +118,11 @@ class RopLop_checker(unittest.TestCase):
...
@@ -118,11 +118,11 @@ class RopLop_checker(unittest.TestCase):
v1
=
rop_f
(
vx
,
vv
)
v1
=
rop_f
(
vx
,
vv
)
v2
=
scan_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
)}))
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
)
yv
=
tensor
.
Lop
(
y
,
self
.
mx
,
self
.
v
)
lop_f
=
function
([
self
.
mx
,
self
.
v
],
yv
)
lop_f
=
function
([
self
.
mx
,
self
.
v
],
yv
)
...
@@ -131,7 +131,7 @@ class RopLop_checker(unittest.TestCase):
...
@@ -131,7 +131,7 @@ class RopLop_checker(unittest.TestCase):
v1
=
lop_f
(
vx
,
vv
)
v1
=
lop_f
(
vx
,
vv
)
v2
=
scan_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
):
def
check_rop_lop
(
self
,
y
,
out_shape
):
"""
"""
...
@@ -140,9 +140,9 @@ class RopLop_checker(unittest.TestCase):
...
@@ -140,9 +140,9 @@ class RopLop_checker(unittest.TestCase):
"""
"""
# TEST ROP
# 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
)
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
)
theano
.
config
.
floatX
)
yv
=
tensor
.
Rop
(
y
,
self
.
x
,
self
.
v
)
yv
=
tensor
.
Rop
(
y
,
self
.
x
,
self
.
v
)
...
@@ -156,7 +156,7 @@ class RopLop_checker(unittest.TestCase):
...
@@ -156,7 +156,7 @@ class RopLop_checker(unittest.TestCase):
v1
=
rop_f
(
vx
,
vv
)
v1
=
rop_f
(
vx
,
vv
)
v2
=
scan_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
known_fail
=
False
try
:
try
:
self
.
check_nondiff_rop
(
theano
.
clone
(
y
,
replace
=
{
self
.
x
:
break_op
(
self
.
x
)}))
self
.
check_nondiff_rop
(
theano
.
clone
(
y
,
replace
=
{
self
.
x
:
break_op
(
self
.
x
)}))
...
@@ -165,9 +165,9 @@ class RopLop_checker(unittest.TestCase):
...
@@ -165,9 +165,9 @@ class RopLop_checker(unittest.TestCase):
# TEST LOP
# 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
)
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
)
theano
.
config
.
floatX
)
yv
=
tensor
.
Lop
(
y
,
self
.
x
,
self
.
v
)
yv
=
tensor
.
Lop
(
y
,
self
.
x
,
self
.
v
)
...
@@ -181,7 +181,7 @@ class RopLop_checker(unittest.TestCase):
...
@@ -181,7 +181,7 @@ class RopLop_checker(unittest.TestCase):
v1
=
lop_f
(
vx
,
vv
)
v1
=
lop_f
(
vx
,
vv
)
v2
=
scan_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
:
if
known_fail
:
raise
SkipTest
(
'Rop does not handle non-differentiable inputs '
raise
SkipTest
(
'Rop does not handle non-differentiable inputs '
...
@@ -213,21 +213,21 @@ class test_RopLop(RopLop_checker):
...
@@ -213,21 +213,21 @@ class test_RopLop(RopLop_checker):
self
.
check_rop_lop
(
self
.
x
[:
4
],
(
4
,))
self
.
check_rop_lop
(
self
.
x
[:
4
],
(
4
,))
def
test_incsubtensor1
(
self
):
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
)
theano
.
config
.
floatX
)
t
=
theano
.
shared
(
tv
)
t
=
theano
.
shared
(
tv
)
out
=
tensor
.
inc_subtensor
(
self
.
x
[:
3
],
t
)
out
=
tensor
.
inc_subtensor
(
self
.
x
[:
3
],
t
)
self
.
check_rop_lop
(
out
,
self
.
in_shape
)
self
.
check_rop_lop
(
out
,
self
.
in_shape
)
def
test_incsubtensor2
(
self
):
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
)
theano
.
config
.
floatX
)
t
=
theano
.
shared
(
tv
)
t
=
theano
.
shared
(
tv
)
out
=
tensor
.
inc_subtensor
(
t
[:
4
],
self
.
x
[:
4
])
out
=
tensor
.
inc_subtensor
(
t
[:
4
],
self
.
x
[:
4
])
self
.
check_rop_lop
(
out
,
(
10
,))
self
.
check_rop_lop
(
out
,
(
10
,))
def
test_setsubtensor1
(
self
):
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
)
theano
.
config
.
floatX
)
t
=
theano
.
shared
(
tv
)
t
=
theano
.
shared
(
tv
)
out
=
tensor
.
set_subtensor
(
self
.
x
[:
3
],
t
)
out
=
tensor
.
set_subtensor
(
self
.
x
[:
3
],
t
)
...
@@ -238,7 +238,7 @@ class test_RopLop(RopLop_checker):
...
@@ -238,7 +238,7 @@ class test_RopLop(RopLop_checker):
self
.
check_rop_lop
(
out
,
self
.
in_shape
)
self
.
check_rop_lop
(
out
,
self
.
in_shape
)
def
test_setsubtensor2
(
self
):
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
)
theano
.
config
.
floatX
)
t
=
theano
.
shared
(
tv
)
t
=
theano
.
shared
(
tv
)
out
=
tensor
.
set_subtensor
(
t
[:
4
],
self
.
x
[:
4
])
out
=
tensor
.
set_subtensor
(
t
[:
4
],
self
.
x
[:
4
])
...
@@ -258,7 +258,7 @@ class test_RopLop(RopLop_checker):
...
@@ -258,7 +258,7 @@ class test_RopLop(RopLop_checker):
(
1
,))
(
1
,))
def
test_downsample
(
self
):
def
test_downsample
(
self
):
rng
=
n
umpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
n
p
.
random
.
RandomState
(
utt
.
fetch_seed
())
# ws, shp
# ws, shp
examples
=
(
examples
=
(
((
2
,),
(
16
,)),
((
2
,),
(
16
,)),
...
@@ -296,7 +296,7 @@ class test_RopLop(RopLop_checker):
...
@@ -296,7 +296,7 @@ class test_RopLop(RopLop_checker):
scan_f
=
function
([],
sy
,
on_unused_input
=
'ignore'
,
mode
=
mode
)
scan_f
=
function
([],
sy
,
on_unused_input
=
'ignore'
,
mode
=
mode
)
v1
=
rop_f
()
v1
=
rop_f
()
v2
=
scan_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
):
def
test_conv
(
self
):
for
conv_op
in
[
conv
.
conv2d
,
conv2d
]:
for
conv_op
in
[
conv
.
conv2d
,
conv2d
]:
...
@@ -337,16 +337,16 @@ class test_RopLop(RopLop_checker):
...
@@ -337,16 +337,16 @@ class test_RopLop(RopLop_checker):
scan_f
=
function
([
input
,
filters
,
ev_input
,
ev_filters
],
sy
,
scan_f
=
function
([
input
,
filters
,
ev_input
,
ev_filters
],
sy
,
on_unused_input
=
'ignore'
,
mode
=
mode
)
on_unused_input
=
'ignore'
,
mode
=
mode
)
dtype
=
theano
.
config
.
floatX
dtype
=
theano
.
config
.
floatX
image_data
=
n
umpy
.
random
.
random
(
image_shape
)
.
astype
(
dtype
)
image_data
=
n
p
.
random
.
random
(
image_shape
)
.
astype
(
dtype
)
filter_data
=
n
umpy
.
random
.
random
(
filter_shape
)
.
astype
(
dtype
)
filter_data
=
n
p
.
random
.
random
(
filter_shape
)
.
astype
(
dtype
)
ev_image_data
=
n
umpy
.
random
.
random
(
image_shape
)
.
astype
(
dtype
)
ev_image_data
=
n
p
.
random
.
random
(
image_shape
)
.
astype
(
dtype
)
ev_filter_data
=
n
umpy
.
random
.
random
(
filter_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
)
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
)
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
):
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
)
theano
.
config
.
floatX
)
t
=
theano
.
shared
(
tv
)
t
=
theano
.
shared
(
tv
)
out
=
tensor
.
join
(
0
,
self
.
x
,
t
)
out
=
tensor
.
join
(
0
,
self
.
x
,
t
)
...
@@ -354,7 +354,7 @@ class test_RopLop(RopLop_checker):
...
@@ -354,7 +354,7 @@ class test_RopLop(RopLop_checker):
def
test_dot
(
self
):
def
test_dot
(
self
):
insh
=
self
.
in_shape
[
0
]
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
)
theano
.
config
.
floatX
)
W
=
theano
.
shared
(
vW
)
W
=
theano
.
shared
(
vW
)
self
.
check_rop_lop
(
tensor
.
dot
(
self
.
x
,
W
),
self
.
in_shape
)
self
.
check_rop_lop
(
tensor
.
dot
(
self
.
x
,
W
),
self
.
in_shape
)
...
@@ -367,7 +367,7 @@ class test_RopLop(RopLop_checker):
...
@@ -367,7 +367,7 @@ class test_RopLop(RopLop_checker):
self
.
in_shape
)
self
.
in_shape
)
def
test_reshape
(
self
):
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
]],
self
.
mat_in_shape
[
0
]
*
self
.
mat_in_shape
[
1
]],
dtype
=
'int64'
))
dtype
=
'int64'
))
...
@@ -435,6 +435,6 @@ class test_RopLop(RopLop_checker):
...
@@ -435,6 +435,6 @@ class test_RopLop(RopLop_checker):
# one differentiable path (i.e. there is no gradient wrt to one of
# one differentiable path (i.e. there is no gradient wrt to one of
# the inputs).
# the inputs).
x
=
tensor
.
arange
(
20.0
)
.
reshape
([
1
,
20
])
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
()
d
=
tensor
.
dot
(
x
,
v
)
.
sum
()
tensor
.
Rop
(
tensor
.
grad
(
d
,
v
),
v
,
v
)
tensor
.
Rop
(
tensor
.
grad
(
d
,
v
),
v
,
v
)
theano/tests/unittest_tools.py
浏览文件 @
dded8355
...
@@ -17,7 +17,7 @@ except ImportError:
...
@@ -17,7 +17,7 @@ except ImportError:
def
func
(
f
):
def
func
(
f
):
return
f
return
f
return
func
return
func
import
numpy
import
numpy
as
np
import
theano
import
theano
import
theano.tensor
as
T
import
theano.tensor
as
T
...
@@ -48,7 +48,7 @@ def fetch_seed(pseed=None):
...
@@ -48,7 +48,7 @@ def fetch_seed(pseed=None):
None, which is equivalent to seeding with a random seed.
None, which is equivalent to seeding with a random seed.
Useful for seeding RandomState objects.
Useful for seeding RandomState objects.
>>> rng = n
umpy
.random.RandomState(unittest_tools.fetch_seed())
>>> rng = n
p
.random.RandomState(unittest_tools.fetch_seed())
"""
"""
seed
=
pseed
or
config
.
unittests
.
rseed
seed
=
pseed
or
config
.
unittests
.
rseed
...
@@ -76,7 +76,7 @@ def seed_rng(pseed=None):
...
@@ -76,7 +76,7 @@ def seed_rng(pseed=None):
seed
=
fetch_seed
(
pseed
)
seed
=
fetch_seed
(
pseed
)
if
pseed
and
pseed
!=
seed
:
if
pseed
and
pseed
!=
seed
:
print
(
'Warning: using seed given by config.unittests.rseed=
%
i'
'instead of seed
%
i given as parameter'
%
(
seed
,
pseed
),
file
=
sys
.
stderr
)
print
(
'Warning: using seed given by config.unittests.rseed=
%
i'
'instead of seed
%
i given as parameter'
%
(
seed
,
pseed
),
file
=
sys
.
stderr
)
n
umpy
.
random
.
seed
(
seed
)
n
p
.
random
.
seed
(
seed
)
return
seed
return
seed
...
@@ -87,7 +87,7 @@ def verify_grad(op, pt, n_tests=2, rng=None, *args, **kwargs):
...
@@ -87,7 +87,7 @@ def verify_grad(op, pt, n_tests=2, rng=None, *args, **kwargs):
"""
"""
if
rng
is
None
:
if
rng
is
None
:
seed_rng
()
seed_rng
()
rng
=
n
umpy
.
random
rng
=
n
p
.
random
T
.
verify_grad
(
op
,
pt
,
n_tests
,
rng
,
*
args
,
**
kwargs
)
T
.
verify_grad
(
op
,
pt
,
n_tests
,
rng
,
*
args
,
**
kwargs
)
#
#
...
@@ -110,12 +110,12 @@ class MockRandomState:
...
@@ -110,12 +110,12 @@ class MockRandomState:
self
.
val
=
val
self
.
val
=
val
def
rand
(
self
,
*
shape
):
def
rand
(
self
,
*
shape
):
return
n
umpy
.
zeros
(
shape
,
dtype
=
'float64'
)
+
self
.
val
return
n
p
.
zeros
(
shape
,
dtype
=
'float64'
)
+
self
.
val
def
randint
(
self
,
minval
,
maxval
=
None
,
size
=
1
):
def
randint
(
self
,
minval
,
maxval
=
None
,
size
=
1
):
if
maxval
is
None
:
if
maxval
is
None
:
minval
,
maxval
=
0
,
minval
minval
,
maxval
=
0
,
minval
out
=
n
umpy
.
zeros
(
size
,
dtype
=
'int64'
)
out
=
n
p
.
zeros
(
size
,
dtype
=
'int64'
)
if
self
.
val
==
0
:
if
self
.
val
==
0
:
return
out
+
minval
return
out
+
minval
else
:
else
:
...
@@ -270,7 +270,7 @@ class InferShapeTester(unittest.TestCase):
...
@@ -270,7 +270,7 @@ class InferShapeTester(unittest.TestCase):
numeric_outputs
=
outputs_function
(
*
numeric_inputs
)
numeric_outputs
=
outputs_function
(
*
numeric_inputs
)
numeric_shapes
=
shapes_function
(
*
numeric_inputs
)
numeric_shapes
=
shapes_function
(
*
numeric_inputs
)
for
out
,
shape
in
zip
(
numeric_outputs
,
numeric_shapes
):
for
out
,
shape
in
zip
(
numeric_outputs
,
numeric_shapes
):
assert
n
umpy
.
all
(
out
.
shape
==
shape
),
(
out
.
shape
,
shape
)
assert
n
p
.
all
(
out
.
shape
==
shape
),
(
out
.
shape
,
shape
)
def
str_diagnostic
(
expected
,
value
,
rtol
,
atol
):
def
str_diagnostic
(
expected
,
value
,
rtol
,
atol
):
...
@@ -287,8 +287,8 @@ def str_diagnostic(expected, value, rtol, atol):
...
@@ -287,8 +287,8 @@ def str_diagnostic(expected, value, rtol, atol):
print
(
expected
.
strides
,
end
=
' '
,
file
=
ssio
)
print
(
expected
.
strides
,
end
=
' '
,
file
=
ssio
)
print
(
expected
.
min
(),
end
=
' '
,
file
=
ssio
)
print
(
expected
.
min
(),
end
=
' '
,
file
=
ssio
)
print
(
expected
.
max
(),
end
=
' '
,
file
=
ssio
)
print
(
expected
.
max
(),
end
=
' '
,
file
=
ssio
)
print
(
n
umpy
.
isinf
(
expected
)
.
sum
(),
end
=
' '
,
file
=
ssio
)
print
(
n
p
.
isinf
(
expected
)
.
sum
(),
end
=
' '
,
file
=
ssio
)
print
(
n
umpy
.
isnan
(
expected
)
.
sum
(),
end
=
' '
,
file
=
ssio
)
print
(
n
p
.
isnan
(
expected
)
.
sum
(),
end
=
' '
,
file
=
ssio
)
# only if all succeeds to we add anything to sio
# only if all succeeds to we add anything to sio
print
(
ssio
.
getvalue
(),
file
=
sio
)
print
(
ssio
.
getvalue
(),
file
=
sio
)
except
Exception
:
except
Exception
:
...
@@ -301,8 +301,8 @@ def str_diagnostic(expected, value, rtol, atol):
...
@@ -301,8 +301,8 @@ def str_diagnostic(expected, value, rtol, atol):
print
(
value
.
strides
,
end
=
' '
,
file
=
ssio
)
print
(
value
.
strides
,
end
=
' '
,
file
=
ssio
)
print
(
value
.
min
(),
end
=
' '
,
file
=
ssio
)
print
(
value
.
min
(),
end
=
' '
,
file
=
ssio
)
print
(
value
.
max
(),
end
=
' '
,
file
=
ssio
)
print
(
value
.
max
(),
end
=
' '
,
file
=
ssio
)
print
(
n
umpy
.
isinf
(
value
)
.
sum
(),
end
=
' '
,
file
=
ssio
)
print
(
n
p
.
isinf
(
value
)
.
sum
(),
end
=
' '
,
file
=
ssio
)
print
(
n
umpy
.
isnan
(
value
)
.
sum
(),
end
=
' '
,
file
=
ssio
)
print
(
n
p
.
isnan
(
value
)
.
sum
(),
end
=
' '
,
file
=
ssio
)
# only if all succeeds to we add anything to sio
# only if all succeeds to we add anything to sio
print
(
ssio
.
getvalue
(),
file
=
sio
)
print
(
ssio
.
getvalue
(),
file
=
sio
)
except
Exception
:
except
Exception
:
...
@@ -312,19 +312,19 @@ def str_diagnostic(expected, value, rtol, atol):
...
@@ -312,19 +312,19 @@ def str_diagnostic(expected, value, rtol, atol):
print
(
" value :"
,
value
,
file
=
sio
)
print
(
" value :"
,
value
,
file
=
sio
)
try
:
try
:
ov
=
n
umpy
.
asarray
(
expected
)
ov
=
n
p
.
asarray
(
expected
)
nv
=
n
umpy
.
asarray
(
value
)
nv
=
n
p
.
asarray
(
value
)
ssio
=
StringIO
()
ssio
=
StringIO
()
absdiff
=
n
umpy
.
absolute
(
nv
-
ov
)
absdiff
=
n
p
.
absolute
(
nv
-
ov
)
print
(
" Max Abs Diff: "
,
n
umpy
.
max
(
absdiff
),
file
=
ssio
)
print
(
" Max Abs Diff: "
,
n
p
.
max
(
absdiff
),
file
=
ssio
)
print
(
" Mean Abs Diff: "
,
n
umpy
.
mean
(
absdiff
),
file
=
ssio
)
print
(
" Mean Abs Diff: "
,
n
p
.
mean
(
absdiff
),
file
=
ssio
)
print
(
" Median Abs Diff: "
,
n
umpy
.
median
(
absdiff
),
file
=
ssio
)
print
(
" Median Abs Diff: "
,
n
p
.
median
(
absdiff
),
file
=
ssio
)
print
(
" Std Abs Diff: "
,
n
umpy
.
std
(
absdiff
),
file
=
ssio
)
print
(
" Std Abs Diff: "
,
n
p
.
std
(
absdiff
),
file
=
ssio
)
reldiff
=
n
umpy
.
absolute
(
nv
-
ov
)
/
numpy
.
absolute
(
ov
)
reldiff
=
n
p
.
absolute
(
nv
-
ov
)
/
np
.
absolute
(
ov
)
print
(
" Max Rel Diff: "
,
n
umpy
.
max
(
reldiff
),
file
=
ssio
)
print
(
" Max Rel Diff: "
,
n
p
.
max
(
reldiff
),
file
=
ssio
)
print
(
" Mean Rel Diff: "
,
n
umpy
.
mean
(
reldiff
),
file
=
ssio
)
print
(
" Mean Rel Diff: "
,
n
p
.
mean
(
reldiff
),
file
=
ssio
)
print
(
" Median Rel Diff: "
,
n
umpy
.
median
(
reldiff
),
file
=
ssio
)
print
(
" Median Rel Diff: "
,
n
p
.
median
(
reldiff
),
file
=
ssio
)
print
(
" Std Rel Diff: "
,
n
umpy
.
std
(
reldiff
),
file
=
ssio
)
print
(
" Std Rel Diff: "
,
n
p
.
std
(
reldiff
),
file
=
ssio
)
# only if all succeeds to we add anything to sio
# only if all succeeds to we add anything to sio
print
(
ssio
.
getvalue
(),
file
=
sio
)
print
(
ssio
.
getvalue
(),
file
=
sio
)
except
Exception
:
except
Exception
:
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论