Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
33bd55ef
提交
33bd55ef
authored
10月 19, 2016
作者:
abergeron
提交者:
GitHub
10月 19, 2016
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #21 from lamblin/bool
Fix tests for CAReduceDtype with bool
上级
91333f00
c25f2cc0
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
100 行增加
和
91 行删除
+100
-91
elemwise.py
theano/tensor/elemwise.py
+2
-0
test_elemwise.py
theano/tensor/tests/test_elemwise.py
+98
-90
test_flake8.py
theano/tests/test_flake8.py
+0
-1
没有找到文件。
theano/tensor/elemwise.py
浏览文件 @
33bd55ef
...
@@ -1848,6 +1848,7 @@ class CAReduceDtype(CAReduce):
...
@@ -1848,6 +1848,7 @@ class CAReduceDtype(CAReduce):
if
dtype
is
None
:
if
dtype
is
None
:
# If input has a discrete dtype, upcast it to 64
# If input has a discrete dtype, upcast it to 64
return
dict
(
return
dict
(
bool
=
'int64'
,
int8
=
'int64'
,
int8
=
'int64'
,
int16
=
'int64'
,
int16
=
'int64'
,
int32
=
'int64'
,
int32
=
'int64'
,
...
@@ -1863,6 +1864,7 @@ class CAReduceDtype(CAReduce):
...
@@ -1863,6 +1864,7 @@ class CAReduceDtype(CAReduce):
acc_dtype
=
self
.
acc_dtype
acc_dtype
=
self
.
acc_dtype
if
acc_dtype
is
None
:
if
acc_dtype
is
None
:
return
dict
(
return
dict
(
bool
=
'int64'
,
int8
=
'int64'
,
int8
=
'int64'
,
int16
=
'int64'
,
int16
=
'int64'
,
int32
=
'int64'
,
int32
=
'int64'
,
...
...
theano/tensor/tests/test_elemwise.py
浏览文件 @
33bd55ef
...
@@ -113,42 +113,42 @@ class test_reduce_axes(unittest.TestCase):
...
@@ -113,42 +113,42 @@ class test_reduce_axes(unittest.TestCase):
[
numpy
.
array
(
0
),
numpy
.
array
(
1
)]]
[
numpy
.
array
(
0
),
numpy
.
array
(
1
)]]
for
a
in
axes
:
for
a
in
axes
:
x
=
tensor
.
matrix
()
x
=
tensor
.
matrix
()
m
=
x
.
sum
(
a
)
x
.
sum
(
a
)
def
test_mean_axes
(
self
):
def
test_mean_axes
(
self
):
axes
=
[
None
,
0
,
1
,
[
0
,
1
],
numpy
.
array
(
1
),
axes
=
[
None
,
0
,
1
,
[
0
,
1
],
numpy
.
array
(
1
),
[
numpy
.
array
(
0
),
numpy
.
array
(
1
)]]
[
numpy
.
array
(
0
),
numpy
.
array
(
1
)]]
for
a
in
axes
:
for
a
in
axes
:
x
=
tensor
.
matrix
()
x
=
tensor
.
matrix
()
m
=
x
.
mean
(
a
)
x
.
mean
(
a
)
def
test_max_axes
(
self
):
def
test_max_axes
(
self
):
axes
=
[
None
,
0
,
1
,
[
0
,
1
],
numpy
.
array
(
1
),
axes
=
[
None
,
0
,
1
,
[
0
,
1
],
numpy
.
array
(
1
),
[
numpy
.
array
(
0
),
numpy
.
array
(
1
)]]
[
numpy
.
array
(
0
),
numpy
.
array
(
1
)]]
for
a
in
axes
:
for
a
in
axes
:
x
=
tensor
.
matrix
()
x
=
tensor
.
matrix
()
m
=
x
.
max
(
a
)
x
.
max
(
a
)
def
test_min_axes
(
self
):
def
test_min_axes
(
self
):
axes
=
[
None
,
0
,
1
,
[
0
,
1
],
numpy
.
array
(
1
),
axes
=
[
None
,
0
,
1
,
[
0
,
1
],
numpy
.
array
(
1
),
[
numpy
.
array
(
0
),
numpy
.
array
(
1
)]]
[
numpy
.
array
(
0
),
numpy
.
array
(
1
)]]
for
a
in
axes
:
for
a
in
axes
:
x
=
tensor
.
matrix
()
x
=
tensor
.
matrix
()
m
=
x
.
min
(
a
)
x
.
min
(
a
)
def
test_argmax_axes
(
self
):
def
test_argmax_axes
(
self
):
axes
=
[
None
,
0
,
1
,
[
0
,
1
],
numpy
.
array
(
1
),
axes
=
[
None
,
0
,
1
,
[
0
,
1
],
numpy
.
array
(
1
),
[
numpy
.
array
(
0
),
numpy
.
array
(
1
)]]
[
numpy
.
array
(
0
),
numpy
.
array
(
1
)]]
for
a
in
axes
:
for
a
in
axes
:
x
=
tensor
.
matrix
()
x
=
tensor
.
matrix
()
m
=
x
.
argmax
(
a
)
x
.
argmax
(
a
)
def
test_var_axes
(
self
):
def
test_var_axes
(
self
):
axes
=
[
None
,
0
,
1
,
[
0
,
1
],
numpy
.
array
(
1
),
axes
=
[
None
,
0
,
1
,
[
0
,
1
],
numpy
.
array
(
1
),
[
numpy
.
array
(
0
),
numpy
.
array
(
1
)]]
[
numpy
.
array
(
0
),
numpy
.
array
(
1
)]]
for
a
in
axes
:
for
a
in
axes
:
x
=
tensor
.
matrix
()
x
=
tensor
.
matrix
()
m
=
x
.
var
(
a
)
x
.
var
(
a
)
class
test_Broadcast
(
unittest
.
TestCase
):
class
test_Broadcast
(
unittest
.
TestCase
):
...
@@ -159,7 +159,7 @@ class test_Broadcast(unittest.TestCase):
...
@@ -159,7 +159,7 @@ class test_Broadcast(unittest.TestCase):
ctype
=
TensorType
ctype
=
TensorType
cop
=
Elemwise
cop
=
Elemwise
openmp_minsize
=
2
*
config
.
openmp_elemwise_minsize
openmp_minsize
=
2
*
config
.
openmp_elemwise_minsize
openmp_minsize_sqrt
=
int
(
math
.
ceil
(
math
.
sqrt
(
openmp_minsize
)))
openmp_minsize_sqrt
=
int
(
math
.
ceil
(
math
.
sqrt
(
openmp_minsize
)))
# The order is important if you change them.
# The order is important if you change them.
...
@@ -346,8 +346,7 @@ class test_CAReduce(unittest_tools.InferShapeTester):
...
@@ -346,8 +346,7 @@ class test_CAReduce(unittest_tools.InferShapeTester):
((
5
,
0
),
(
1
,
)),
((
5
,
0
),
(
1
,
)),
((
5
,
0
),
()),
((
5
,
0
),
()),
((),
None
),
((),
None
),
((),
())
((),
())]
]
type
=
TensorType
type
=
TensorType
def
with_linker
(
self
,
linker
,
scalar_op
=
scalar
.
add
,
dtype
=
"floatX"
,
def
with_linker
(
self
,
linker
,
scalar_op
=
scalar
.
add
,
dtype
=
"floatX"
,
...
@@ -371,7 +370,7 @@ class test_CAReduce(unittest_tools.InferShapeTester):
...
@@ -371,7 +370,7 @@ class test_CAReduce(unittest_tools.InferShapeTester):
f
=
copy
(
linker
)
.
accept
(
FunctionGraph
([
x
],
[
e
]))
.
make_function
()
f
=
copy
(
linker
)
.
accept
(
FunctionGraph
([
x
],
[
e
]))
.
make_function
()
xv
=
numpy
.
asarray
(
numpy
.
random
.
rand
(
*
xsh
))
xv
=
numpy
.
asarray
(
numpy
.
random
.
rand
(
*
xsh
))
if
not
"int"
in
dtype
:
if
"int"
not
in
dtype
:
xv
=
numpy
.
asarray
(
xv
,
dtype
=
dtype
)
xv
=
numpy
.
asarray
(
xv
,
dtype
=
dtype
)
else
:
else
:
xv
=
numpy
.
asarray
(
xv
<
0.5
,
dtype
=
dtype
)
xv
=
numpy
.
asarray
(
xv
<
0.5
,
dtype
=
dtype
)
...
@@ -610,18 +609,20 @@ class test_Prod(unittest.TestCase):
...
@@ -610,18 +609,20 @@ class test_Prod(unittest.TestCase):
x
=
theano
.
tensor
.
dmatrix
()
x
=
theano
.
tensor
.
dmatrix
()
# sanity check
# sanity check
x2
=
theano
.
tensor
.
dmatrix
()
p
=
Prod
(
axis
=
1
)(
x
)
p
=
Prod
(
axis
=
1
)(
x
)
p2
=
Prod
(
axis
=
1
)(
x2
)
fn
=
theano
.
function
([
x
,
x2
],
[
p
-
p2
],
mode
=
self
.
mode
)
# Uncomment this for debugging if needed
# print "hand computed diff for each row"
# x2 = theano.tensor.dmatrix()
x2_val
=
numpy
.
asarray
([[
1.
,
2.
,
3.003
],
[
0.003
,
5.
,
6
],
[
# p2 = Prod(axis=1)(x2)
0.
,
0.
,
9.01
]])
# fn = theano.function([x, x2], [p - p2], mode=self.mode)
# print fn(x_val, x2_val)
# print("hand computed diff for each row")
fn2
=
theano
.
function
([
x
],
[
theano
.
tensor
.
grad
(
p
.
sum
(),
x
)],
# x2_val = numpy.asarray([[1., 2., 3.003], [0.003, 5., 6], [
mode
=
self
.
mode
)
# 0., 0., 9.01]])
# print "real grad"
# print(fn(x_val, x2_val))
# print fn2(x_val)
# fn2 = theano.function([x], [theano.tensor.grad(p.sum(), x)],
# mode=self.mode)
# print("real grad")
# print(fn2(x_val))
fn3
=
theano
.
function
([
x
],
[
p
],
mode
=
self
.
mode
)
fn3
=
theano
.
function
([
x
],
[
p
],
mode
=
self
.
mode
)
assert
numpy
.
allclose
(
fn3
(
x_val
),
[
6.
,
0.
,
0.
])
assert
numpy
.
allclose
(
fn3
(
x_val
),
[
6.
,
0.
,
0.
])
...
@@ -633,14 +634,14 @@ class test_Prod(unittest.TestCase):
...
@@ -633,14 +634,14 @@ class test_Prod(unittest.TestCase):
# def fn5(x5):
# def fn5(x5):
# return theano.tensor.sqr(Prod(axis=1)(x5))
# return theano.tensor.sqr(Prod(axis=1)(x5))
#x4 = theano.tensor.dmatrix()
#
x4 = theano.tensor.dmatrix()
#p4 = theano.tensor.sqr(Prod(axis=1)(x4))
#
p4 = theano.tensor.sqr(Prod(axis=1)(x4))
#fn4 = theano.function([x4], p4)
#
fn4 = theano.function([x4], p4)
# print
"with sqr"
# print
("with sqr")
# print
fn4(x_val
)
# print
(fn4(x_val)
)
# print
fn4(x2_val
)
# print
(fn4(x2_val)
)
#unittest_tools.verify_grad(fn5, [x_val])
#
unittest_tools.verify_grad(fn5, [x_val])
@attr
(
'slow'
)
@attr
(
'slow'
)
def
test_prod_no_zeros_in_input
(
self
):
def
test_prod_no_zeros_in_input
(
self
):
...
@@ -691,30 +692,33 @@ class test_Prod(unittest.TestCase):
...
@@ -691,30 +692,33 @@ class test_Prod(unittest.TestCase):
x
=
theano
.
tensor
.
dmatrix
()
x
=
theano
.
tensor
.
dmatrix
()
pwz_a1
=
ProdWithoutZeros
(
axis
=
0
)(
x
)
pwz_a1
=
ProdWithoutZeros
(
axis
=
0
)(
x
)
pwz_grad
=
theano
.
grad
(
theano
.
tensor
.
sum
(
pwz_a1
),
x
)
pwz_grad
=
theano
.
grad
(
theano
.
tensor
.
sum
(
pwz_a1
),
x
)
fn_a1
=
theano
.
function
([
x
],
pwz_grad
,
mode
=
self
.
mode
)
theano
.
function
([
x
],
pwz_grad
,
mode
=
self
.
mode
)
@attr
(
'slow'
)
@attr
(
'slow'
)
def
test_other_grad_tests
(
self
):
def
test_other_grad_tests
(
self
):
x
=
theano
.
tensor
.
dmatrix
()
x
=
theano
.
tensor
.
dmatrix
()
x_val1
=
numpy
.
array
([[
1
,
2
,
3
],
[
0
,
5
,
6
],
[
0
,
0
,
9
]],
x_val1
=
numpy
.
array
([[
1
,
2
,
3
],
[
0
,
5
,
6
],
[
0
,
0
,
9
]],
dtype
=
'float32'
)
dtype
=
'float32'
)
x_val2
=
numpy
.
array
([[
1
,
2
,
0
],
[
0
,
5
,
6
],
[
7
,
8
,
9
],
[
9
,
10
,
0
]],
x_val2
=
numpy
.
array
([[
1
,
2
,
0
],
[
0
,
5
,
6
],
[
7
,
8
,
9
],
[
9
,
10
,
0
]],
dtype
=
'float32'
)
dtype
=
'float32'
)
rng
=
rng
=
numpy
.
random
.
RandomState
(
43
)
rng
=
rng
=
numpy
.
random
.
RandomState
(
43
)
p
=
Prod
(
axis
=
1
)
p
=
Prod
(
axis
=
1
)
grad_p
=
theano
.
tensor
.
grad
(
p
(
x
)
.
sum
(),
x
)
grad_p
=
theano
.
tensor
.
grad
(
p
(
x
)
.
sum
(),
x
)
grad_fn
=
theano
.
function
([
x
],
grad_p
,
mode
=
self
.
mode
)
grad_fn
=
theano
.
function
([
x
],
grad_p
,
mode
=
self
.
mode
)
assert
numpy
.
allclose
(
grad_fn
(
x_val1
),
[[
6.
,
3.
,
2.
],
[
30.
,
0.
,
assert
numpy
.
allclose
(
0.
],
[
0.
,
0.
,
0.
]])
grad_fn
(
x_val1
),
assert
numpy
.
allclose
(
grad_fn
(
x_val2
),
[[
0.
,
0.
,
2.
],
[
30.
,
[[
6.
,
3.
,
2.
],
[
30.
,
0.
,
0.
],
[
0.
,
0.
,
0.
]])
0.
,
0.
],
[
72.
,
63.
,
56.
],
[
0.
,
0.
,
90.
]])
assert
numpy
.
allclose
(
grad_fn
(
x_val2
),
[[
0.
,
0.
,
2.
],
[
30.
,
0.
,
0.
],
[
72.
,
63.
,
56.
],
[
0.
,
0.
,
90.
]])
p_axis0
=
Prod
(
axis
=
0
)
p_axis0
=
Prod
(
axis
=
0
)
grad_p_axis0
=
theano
.
tensor
.
grad
(
p_axis0
(
x
)
.
sum
(),
x
)
grad_p_axis0
=
theano
.
tensor
.
grad
(
p_axis0
(
x
)
.
sum
(),
x
)
grad_fn_axis0
=
theano
.
function
([
x
],
grad_p_axis0
,
mode
=
self
.
mode
)
grad_fn_axis0
=
theano
.
function
([
x
],
grad_p_axis0
,
mode
=
self
.
mode
)
assert
numpy
.
allclose
(
grad_fn_axis0
(
x_val2
),
[[
0.
,
400.
,
assert
numpy
.
allclose
(
0.
],
[
63.
,
160.
,
0.
],
[
0.
,
100.
,
0.
],
[
0.
,
80.
,
0.
]])
grad_fn_axis0
(
x_val2
),
[[
0.
,
400.
,
0.
],
[
63.
,
160.
,
0.
],
[
0.
,
100.
,
0.
],
[
0.
,
80.
,
0.
]])
tensor
.
verify_grad
(
p
,
[
x_val1
],
rng
=
rng
,
mode
=
self
.
mode
)
tensor
.
verify_grad
(
p
,
[
x_val1
],
rng
=
rng
,
mode
=
self
.
mode
)
...
@@ -764,7 +768,7 @@ class test_IsInf_IsNan(unittest.TestCase):
...
@@ -764,7 +768,7 @@ class test_IsInf_IsNan(unittest.TestCase):
numpy_isfunc
=
getattr
(
numpy
,
isfunc
)
numpy_isfunc
=
getattr
(
numpy
,
isfunc
)
for
x
in
self
.
test_vals
:
for
x
in
self
.
test_vals
:
if
((
x
.
ndim
==
0
and
input
is
not
self
.
scalar
)
or
if
((
x
.
ndim
==
0
and
input
is
not
self
.
scalar
)
or
(
x
.
ndim
==
1
and
input
is
not
self
.
vector
)):
(
x
.
ndim
==
1
and
input
is
not
self
.
vector
)):
# We only test with the appropriate input type.
# We only test with the appropriate input type.
continue
continue
t_out
=
theano_isfunc
(
x
)
t_out
=
theano_isfunc
(
x
)
...
@@ -795,6 +799,7 @@ class T_reduce_dtype(unittest.TestCase):
...
@@ -795,6 +799,7 @@ class T_reduce_dtype(unittest.TestCase):
x
=
tensor
.
matrix
(
dtype
=
dtype
)
x
=
tensor
.
matrix
(
dtype
=
dtype
)
s
=
getattr
(
x
,
method
)(
axis
=
axis
)
s
=
getattr
(
x
,
method
)(
axis
=
axis
)
assert
s
.
dtype
==
dict
(
assert
s
.
dtype
==
dict
(
bool
=
'int64'
,
int8
=
'int64'
,
int8
=
'int64'
,
int16
=
'int64'
,
int16
=
'int64'
,
int32
=
'int64'
,
int32
=
'int64'
,
...
@@ -820,6 +825,7 @@ class T_reduce_dtype(unittest.TestCase):
...
@@ -820,6 +825,7 @@ class T_reduce_dtype(unittest.TestCase):
x
=
tensor
.
matrix
(
dtype
=
dtype
)
x
=
tensor
.
matrix
(
dtype
=
dtype
)
s
=
getattr
(
x
,
method
)(
axis
=
axis
)
s
=
getattr
(
x
,
method
)(
axis
=
axis
)
assert
s
.
owner
.
op
.
acc_dtype
==
dict
(
assert
s
.
owner
.
op
.
acc_dtype
==
dict
(
bool
=
'int64'
,
int8
=
'int64'
,
int8
=
'int64'
,
int16
=
'int64'
,
int16
=
'int64'
,
int32
=
'int64'
,
int32
=
'int64'
,
...
@@ -848,11 +854,11 @@ class T_reduce_dtype(unittest.TestCase):
...
@@ -848,11 +854,11 @@ class T_reduce_dtype(unittest.TestCase):
for
input_dtype
in
self
.
dtypes
:
for
input_dtype
in
self
.
dtypes
:
x
=
tensor
.
matrix
(
dtype
=
input_dtype
)
x
=
tensor
.
matrix
(
dtype
=
input_dtype
)
for
output_dtype
in
self
.
dtypes
:
for
output_dtype
in
self
.
dtypes
:
# If the output is a complex, the gradient of the reduce will
# If the output is a complex, the gradient of the reduce will
# cast the complex to the input dtype. We can't call the normal
# cast the complex to the input dtype. We can't call the normal
# cast on a complex to a not complex as this is ambiguous.
# cast on a complex to a not complex as this is ambiguous.
if
(
not
input_dtype
.
startswith
(
'complex'
)
and
if
(
not
input_dtype
.
startswith
(
'complex'
)
and
output_dtype
.
startswith
(
'complex'
)):
output_dtype
.
startswith
(
'complex'
)):
continue
continue
axis
=
self
.
axes
[
idx
%
len
(
self
.
axes
)]
axis
=
self
.
axes
[
idx
%
len
(
self
.
axes
)]
...
@@ -861,8 +867,8 @@ class T_reduce_dtype(unittest.TestCase):
...
@@ -861,8 +867,8 @@ class T_reduce_dtype(unittest.TestCase):
f
=
theano
.
function
([
x
],
var
,
mode
=
self
.
mode
)
f
=
theano
.
function
([
x
],
var
,
mode
=
self
.
mode
)
topo
=
f
.
maker
.
fgraph
.
toposort
()
topo
=
f
.
maker
.
fgraph
.
toposort
()
assert
[
n
for
n
in
topo
if
isinstance
(
n
.
op
,
self
.
op
)],
(
topo
,
assert
[
n
for
n
in
topo
if
isinstance
(
n
.
op
,
self
.
op
)],
\
dtype
)
(
topo
,
output_
dtype
)
data
=
numpy
.
random
.
rand
(
3
,
4
)
*
10
data
=
numpy
.
random
.
rand
(
3
,
4
)
*
10
data
=
data
.
astype
(
input_dtype
)
data
=
data
.
astype
(
input_dtype
)
f
(
data
)
f
(
data
)
...
@@ -882,21 +888,20 @@ class T_reduce_dtype(unittest.TestCase):
...
@@ -882,21 +888,20 @@ class T_reduce_dtype(unittest.TestCase):
for
input_dtype
in
self
.
dtypes
:
for
input_dtype
in
self
.
dtypes
:
x
=
tensor
.
matrix
(
dtype
=
input_dtype
)
x
=
tensor
.
matrix
(
dtype
=
input_dtype
)
for
acc_dtype
in
self
.
dtypes
:
for
acc_dtype
in
self
.
dtypes
:
# If the accumulator is a complex, the gradient of the reduce will
# If the accumulator is a complex, the gradient of the reduce will
# cast the complex to the input dtype. We can't call the normal
# cast the complex to the input dtype. We can't call the normal
# cast on a complex to a not complex as this is ambiguous.
# cast on a complex to a not complex as this is ambiguous.
if
(
not
input_dtype
.
startswith
(
'complex'
)
and
if
(
not
input_dtype
.
startswith
(
'complex'
)
and
acc_dtype
.
startswith
(
'complex'
)):
acc_dtype
.
startswith
(
'complex'
)):
continue
continue
axis
=
self
.
axes
[
idx
%
len
(
self
.
axes
)]
axis
=
self
.
axes
[
idx
%
len
(
self
.
axes
)]
# If output_dtype would force a downcast, we expect a TypeError
# If output_dtype would force a downcast, we expect a TypeError
# We always allow int/uint inputs with float/complex outputs.
# We always allow int/uint inputs with float/complex outputs.
upcasted_dtype
=
scalar
.
upcast
(
input_dtype
,
acc_dtype
)
upcasted_dtype
=
scalar
.
upcast
(
input_dtype
,
acc_dtype
)
if
(
acc_dtype
==
upcasted_dtype
or
if
(
acc_dtype
==
upcasted_dtype
or
(
input_dtype
in
tensor
.
discrete_dtypes
and
(
input_dtype
in
tensor
.
discrete_dtypes
and
acc_dtype
in
tensor
.
continuous_dtypes
)
acc_dtype
in
tensor
.
continuous_dtypes
)):
):
var
=
getattr
(
x
,
method
)(
acc_dtype
=
acc_dtype
,
var
=
getattr
(
x
,
method
)(
acc_dtype
=
acc_dtype
,
axis
=
axis
)
axis
=
axis
)
assert
var
.
owner
.
op
.
acc_dtype
==
acc_dtype
assert
var
.
owner
.
op
.
acc_dtype
==
acc_dtype
...
@@ -921,8 +926,7 @@ class T_reduce_dtype(unittest.TestCase):
...
@@ -921,8 +926,7 @@ class T_reduce_dtype(unittest.TestCase):
s
=
getattr
(
x
,
method
)()
s
=
getattr
(
x
,
method
)()
f
=
theano
.
function
([],
s
,
mode
=
self
.
mode
)
f
=
theano
.
function
([],
s
,
mode
=
self
.
mode
)
topo
=
f
.
maker
.
fgraph
.
toposort
()
topo
=
f
.
maker
.
fgraph
.
toposort
()
assert
[
n
for
n
in
topo
if
isinstance
(
n
.
op
,
self
.
op
)],
(
topo
,
assert
[
n
for
n
in
topo
if
isinstance
(
n
.
op
,
self
.
op
)],
topo
dtype
)
s_val
=
f
()
s_val
=
f
()
# Use extra precision in NumPy to compute the good answer.
# Use extra precision in NumPy to compute the good answer.
ret
=
getattr
(
numpy
.
asarray
([
1e8
,
1
,
-
1e8
],
dtype
=
'float64'
),
ret
=
getattr
(
numpy
.
asarray
([
1e8
,
1
,
-
1e8
],
dtype
=
'float64'
),
...
@@ -976,7 +980,7 @@ class T_mean_dtype(unittest.TestCase):
...
@@ -976,7 +980,7 @@ class T_mean_dtype(unittest.TestCase):
(
mean_var
.
dtype
,
sum_dtype
))
(
mean_var
.
dtype
,
sum_dtype
))
if
((
'complex'
in
input_dtype
or
if
((
'complex'
in
input_dtype
or
'complex'
in
sum_dtype
)
and
'complex'
in
sum_dtype
)
and
input_dtype
!=
sum_dtype
):
input_dtype
!=
sum_dtype
):
continue
continue
f
=
theano
.
function
([
x
],
mean_var
)
f
=
theano
.
function
([
x
],
mean_var
)
data
=
numpy
.
random
.
rand
(
3
,
4
)
*
10
data
=
numpy
.
random
.
rand
(
3
,
4
)
*
10
...
@@ -1017,6 +1021,7 @@ class T_prod_without_zeros_dtype(unittest.TestCase):
...
@@ -1017,6 +1021,7 @@ class T_prod_without_zeros_dtype(unittest.TestCase):
axis
=
axes
[
idx
%
len
(
axes
)]
axis
=
axes
[
idx
%
len
(
axes
)]
x
=
ProdWithoutZeros
(
axis
=
axis
)(
tensor
.
matrix
(
dtype
=
dtype
))
x
=
ProdWithoutZeros
(
axis
=
axis
)(
tensor
.
matrix
(
dtype
=
dtype
))
assert
x
.
dtype
==
dict
(
assert
x
.
dtype
==
dict
(
bool
=
'int64'
,
int8
=
'int64'
,
int8
=
'int64'
,
int16
=
'int64'
,
int16
=
'int64'
,
int32
=
'int64'
,
int32
=
'int64'
,
...
@@ -1035,16 +1040,17 @@ class T_prod_without_zeros_dtype(unittest.TestCase):
...
@@ -1035,16 +1040,17 @@ class T_prod_without_zeros_dtype(unittest.TestCase):
x
=
tensor
.
matrix
(
dtype
=
dtype
)
x
=
tensor
.
matrix
(
dtype
=
dtype
)
p
=
ProdWithoutZeros
(
axis
=
axis
)(
x
)
p
=
ProdWithoutZeros
(
axis
=
axis
)(
x
)
assert
p
.
owner
.
op
.
acc_dtype
==
dict
(
assert
p
.
owner
.
op
.
acc_dtype
==
dict
(
int8
=
'int64'
,
bool
=
'int64'
,
int16
=
'int64'
,
int8
=
'int64'
,
int32
=
'int64'
,
int16
=
'int64'
,
uint8
=
'uint64'
,
int32
=
'int64'
,
uint16
=
'uint64'
,
uint8
=
'uint64'
,
uint32
=
'uint64'
,
uint16
=
'uint64'
,
float16
=
'float32'
,
uint32
=
'uint64'
,
float32
=
'float64'
,
float16
=
'float32'
,
complex64
=
'complex128'
float32
=
'float64'
,
)
.
get
(
dtype
,
dtype
)
complex64
=
'complex128'
)
.
get
(
dtype
,
dtype
)
if
'complex'
in
dtype
:
if
'complex'
in
dtype
:
continue
continue
...
@@ -1065,11 +1071,11 @@ class T_prod_without_zeros_dtype(unittest.TestCase):
...
@@ -1065,11 +1071,11 @@ class T_prod_without_zeros_dtype(unittest.TestCase):
for
output_dtype
in
imap
(
str
,
theano
.
scalar
.
all_types
):
for
output_dtype
in
imap
(
str
,
theano
.
scalar
.
all_types
):
axis
=
axes
[
idx
%
len
(
axes
)]
axis
=
axes
[
idx
%
len
(
axes
)]
prod_woz_var
=
ProdWithoutZeros
(
prod_woz_var
=
ProdWithoutZeros
(
axis
=
axis
,
dtype
=
output_dtype
)(
x
)
axis
=
axis
,
dtype
=
output_dtype
)(
x
)
assert
prod_woz_var
.
dtype
==
output_dtype
assert
prod_woz_var
.
dtype
==
output_dtype
idx
+=
1
idx
+=
1
if
(
'complex'
in
output_dtype
or
if
(
'complex'
in
output_dtype
or
'complex'
in
input_dtype
):
'complex'
in
input_dtype
):
continue
continue
f
=
theano
.
function
([
x
],
prod_woz_var
)
f
=
theano
.
function
([
x
],
prod_woz_var
)
data
=
numpy
.
random
.
rand
(
2
,
3
)
*
3
data
=
numpy
.
random
.
rand
(
2
,
3
)
*
3
...
@@ -1092,23 +1098,23 @@ class T_prod_without_zeros_dtype(unittest.TestCase):
...
@@ -1092,23 +1098,23 @@ class T_prod_without_zeros_dtype(unittest.TestCase):
upcasted_dtype
=
scalar
.
upcast
(
input_dtype
,
acc_dtype
)
upcasted_dtype
=
scalar
.
upcast
(
input_dtype
,
acc_dtype
)
if
(
acc_dtype
==
upcasted_dtype
or
if
(
acc_dtype
==
upcasted_dtype
or
(
input_dtype
in
tensor
.
discrete_dtypes
and
(
input_dtype
in
tensor
.
discrete_dtypes
and
acc_dtype
in
tensor
.
continuous_dtypes
)
acc_dtype
in
tensor
.
continuous_dtypes
)):
):
prod_woz_var
=
ProdWithoutZeros
(
prod_woz_var
=
ProdWithoutZeros
(
axis
=
axis
,
acc_dtype
=
acc_dtype
)(
x
)
axis
=
axis
,
acc_dtype
=
acc_dtype
)(
x
)
assert
prod_woz_var
.
owner
.
op
.
acc_dtype
==
acc_dtype
assert
prod_woz_var
.
owner
.
op
.
acc_dtype
==
acc_dtype
if
(
acc_dtype
.
startswith
(
'complex'
)
and
if
(
acc_dtype
.
startswith
(
'complex'
)
and
input_dtype
!=
acc_dtype
):
input_dtype
!=
acc_dtype
):
continue
continue
f
=
theano
.
function
([
x
],
prod_woz_var
)
f
=
theano
.
function
([
x
],
prod_woz_var
)
data
=
numpy
.
random
.
rand
(
2
,
3
)
*
3
data
=
numpy
.
random
.
rand
(
2
,
3
)
*
3
data
=
data
.
astype
(
input_dtype
)
data
=
data
.
astype
(
input_dtype
)
f
(
data
)
f
(
data
)
else
:
else
:
self
.
assertRaises
(
TypeError
,
self
.
assertRaises
(
ProdWithoutZeros
(
axis
=
axis
,
acc_dtype
=
acc_dtype
),
TypeError
,
x
)
ProdWithoutZeros
(
axis
=
axis
,
acc_dtype
=
acc_dtype
),
x
)
idx
+=
1
idx
+=
1
...
@@ -1148,24 +1154,26 @@ class TestElemwise(unittest_tools.InferShapeTester):
...
@@ -1148,24 +1154,26 @@ class TestElemwise(unittest_tools.InferShapeTester):
def
test_infer_shape
(
self
):
def
test_infer_shape
(
self
):
for
s_left
,
s_right
in
[((
5
,
6
),
(
5
,
6
)),
for
s_left
,
s_right
in
[
((
5
,
6
),
(
5
,
1
)),
((
5
,
6
),
(
5
,
6
)),
((
5
,
6
),
(
1
,
6
)),
((
5
,
6
),
(
5
,
1
)),
((
5
,
1
),
(
5
,
6
)),
((
5
,
6
),
(
1
,
6
)),
((
1
,
6
),
(
5
,
6
)),
((
5
,
1
),
(
5
,
6
)),
((
2
,
3
,
4
,
5
),
(
2
,
3
,
4
,
5
)),
((
1
,
6
),
(
5
,
6
)),
((
2
,
3
,
4
,
5
),
(
2
,
3
,
1
,
5
)),
((
2
,
3
,
4
,
5
),
(
2
,
3
,
4
,
5
)),
((
2
,
3
,
4
,
5
),
(
1
,
3
,
4
,
5
)),
((
2
,
3
,
4
,
5
),
(
2
,
3
,
1
,
5
)),
((
2
,
1
,
4
,
5
),
(
2
,
3
,
4
,
5
)),
((
2
,
3
,
4
,
5
),
(
1
,
3
,
4
,
5
)),
((
2
,
3
,
4
,
1
),
(
2
,
3
,
4
,
5
))]:
((
2
,
1
,
4
,
5
),
(
2
,
3
,
4
,
5
)),
((
2
,
3
,
4
,
1
),
(
2
,
3
,
4
,
5
))]:
dtype
=
theano
.
config
.
floatX
dtype
=
theano
.
config
.
floatX
t_left
=
TensorType
(
dtype
,
[(
entry
==
1
)
for
entry
in
s_left
])()
t_left
=
TensorType
(
dtype
,
[(
entry
==
1
)
for
entry
in
s_left
])()
t_right
=
TensorType
(
dtype
,
[(
entry
==
1
)
for
entry
in
s_right
])()
t_right
=
TensorType
(
dtype
,
[(
entry
==
1
)
for
entry
in
s_right
])()
t_left_val
=
numpy
.
zeros
(
s_left
,
dtype
=
dtype
)
t_left_val
=
numpy
.
zeros
(
s_left
,
dtype
=
dtype
)
t_right_val
=
numpy
.
zeros
(
s_right
,
dtype
=
dtype
)
t_right_val
=
numpy
.
zeros
(
s_right
,
dtype
=
dtype
)
self
.
_compile_and_check
([
t_left
,
t_right
],
self
.
_compile_and_check
(
[
Elemwise
(
scalar
.
add
)(
t_left
,
t_right
)],
[
t_left
,
t_right
],
[
t_left_val
,
t_right_val
],
Elemwise
)
[
Elemwise
(
scalar
.
add
)(
t_left
,
t_right
)],
[
t_left_val
,
t_right_val
],
Elemwise
)
def
test_input_dimensions_overflow
(
self
):
def
test_input_dimensions_overflow
(
self
):
# Elemwise.perform used to compute the product
# Elemwise.perform used to compute the product
...
@@ -1174,7 +1182,7 @@ class TestElemwise(unittest_tools.InferShapeTester):
...
@@ -1174,7 +1182,7 @@ class TestElemwise(unittest_tools.InferShapeTester):
a
,
b
,
c
,
d
,
e
,
f
=
tensor
.
vectors
(
'abcdef'
)
a
,
b
,
c
,
d
,
e
,
f
=
tensor
.
vectors
(
'abcdef'
)
s
=
a
+
b
+
c
+
d
+
e
+
f
s
=
a
+
b
+
c
+
d
+
e
+
f
g
=
theano
.
function
([
a
,
b
,
c
,
d
,
e
,
f
],
s
,
g
=
theano
.
function
([
a
,
b
,
c
,
d
,
e
,
f
],
s
,
mode
=
theano
.
compile
.
Mode
(
linker
=
'py'
))
mode
=
theano
.
compile
.
Mode
(
linker
=
'py'
))
g
(
*
[
numpy
.
zeros
(
2
**
11
,
config
.
floatX
)
for
i
in
xrange
(
6
)])
g
(
*
[
numpy
.
zeros
(
2
**
11
,
config
.
floatX
)
for
i
in
xrange
(
6
)])
...
@@ -1192,7 +1200,7 @@ def test_gt_grad():
...
@@ -1192,7 +1200,7 @@ def test_gt_grad():
input_
=
T
.
vector
(
dtype
=
floatX
)
input_
=
T
.
vector
(
dtype
=
floatX
)
random_values
=
numpy
.
random
.
RandomState
(
1234
)
.
uniform
(
random_values
=
numpy
.
random
.
RandomState
(
1234
)
.
uniform
(
low
=-
1
,
high
=
1
,
size
=
(
2
,
2
))
low
=-
1
,
high
=
1
,
size
=
(
2
,
2
))
W_values
=
numpy
.
asarray
(
random_values
,
dtype
=
floatX
)
W_values
=
numpy
.
asarray
(
random_values
,
dtype
=
floatX
)
W
=
theano
.
shared
(
value
=
W_values
,
name
=
'weights'
)
W
=
theano
.
shared
(
value
=
W_values
,
name
=
'weights'
)
correct_score
=
T
.
dot
(
input_
,
W
)
correct_score
=
T
.
dot
(
input_
,
W
)
...
@@ -1223,7 +1231,7 @@ def test_clip_grad():
...
@@ -1223,7 +1231,7 @@ def test_clip_grad():
# use an x value less than y, an x value between y and z, and an x value
# use an x value less than y, an x value between y and z, and an x value
# greater than z
# greater than z
unittest_tools
.
verify_grad
(
func
,
unittest_tools
.
verify_grad
(
func
,
[
numpy
.
asarray
([
-
1.
,
0.5
,
2.
]),
0.
,
1.
])
[
numpy
.
asarray
([
-
1.
,
0.5
,
2.
]),
0.
,
1.
])
def
test_clip_grad_int
():
def
test_clip_grad_int
():
...
...
theano/tests/test_flake8.py
浏览文件 @
33bd55ef
...
@@ -56,7 +56,6 @@ whitelist_flake8 = [
...
@@ -56,7 +56,6 @@ whitelist_flake8 = [
"tensor/tests/test_opt.py"
,
"tensor/tests/test_opt.py"
,
"tensor/tests/test_basic.py"
,
"tensor/tests/test_basic.py"
,
"tensor/tests/test_blas.py"
,
"tensor/tests/test_blas.py"
,
"tensor/tests/test_elemwise.py"
,
"tensor/tests/test_merge.py"
,
"tensor/tests/test_merge.py"
,
"tensor/tests/test_gc.py"
,
"tensor/tests/test_gc.py"
,
"tensor/tests/test_complex.py"
,
"tensor/tests/test_complex.py"
,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论