Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
c6398151
提交
c6398151
authored
6月 17, 2013
作者:
lamblin
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1416 from nouiz/reduce_dtype_noaxis
[BUGFIX] Reduce dtype noaxis
上级
ba833bb1
72132077
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
121 行增加
和
32 行删除
+121
-32
basic.py
theano/scalar/basic.py
+6
-0
elemwise.py
theano/tensor/elemwise.py
+7
-2
test_elemwise.py
theano/tensor/tests/test_elemwise.py
+108
-30
没有找到文件。
theano/scalar/basic.py
浏览文件 @
c6398151
...
@@ -301,6 +301,12 @@ class Scalar(Type):
...
@@ -301,6 +301,12 @@ class Scalar(Type):
ret.imag = -this->imag;
ret.imag = -this->imag;
return ret;
return ret;
}
}
bool operator ==(const complex_type &y) const {
return (this->real == y.real) && (this->imag == y.imag);
}
bool operator ==(const npy_float
%(nbits)
s &y) const {
return (this->real == y) && (this->imag == 0);
}
complex_type operator -(const complex_type &y) const {
complex_type operator -(const complex_type &y) const {
complex_type ret;
complex_type ret;
ret.real = this->real - y.real;
ret.real = this->real - y.real;
...
...
theano/tensor/elemwise.py
浏览文件 @
c6398151
...
@@ -1463,8 +1463,13 @@ class CAReduce(Op):
...
@@ -1463,8 +1463,13 @@ class CAReduce(Op):
axis
=
range
(
len
(
input
.
type
.
broadcastable
))
axis
=
range
(
len
(
input
.
type
.
broadcastable
))
if
len
(
axis
)
==
0
:
if
len
(
axis
)
==
0
:
op
=
Elemwise
(
scalar
.
identity
)
# The acc_dtype is never a downcast compared to the input dtype
return
op
.
_c_all
(
op
.
make_node
(
input
),
name
,
inames
,
onames
,
sub
)
# So we just need a cast to the output dtype.
var
=
theano
.
tensor
.
cast
(
input
,
node
.
outputs
[
0
]
.
dtype
)
if
var
is
input
:
var
=
Elemwise
(
scalar
.
identity
)(
input
)
assert
var
.
dtype
==
node
.
outputs
[
0
]
.
dtype
return
var
.
owner
.
op
.
_c_all
(
var
.
owner
,
name
,
inames
,
onames
,
sub
)
order1
=
[
i
for
i
in
xrange
(
input
.
type
.
ndim
)
if
i
not
in
axis
]
order1
=
[
i
for
i
in
xrange
(
input
.
type
.
ndim
)
if
i
not
in
axis
]
order
=
order1
+
list
(
axis
)
order
=
order1
+
list
(
axis
)
...
...
theano/tensor/tests/test_elemwise.py
浏览文件 @
c6398151
...
@@ -617,11 +617,12 @@ class T_sum_dtype(unittest.TestCase):
...
@@ -617,11 +617,12 @@ class T_sum_dtype(unittest.TestCase):
Test the default dtype of a sum().
Test the default dtype of a sum().
"""
"""
# We try multiple axis combinations even though axis should not matter.
# We try multiple axis combinations even though axis should not matter.
axes
=
[
None
,
0
,
1
,
[
0
],
[
1
],
[
0
,
1
]]
axes
=
[
None
,
0
,
1
,
[
],
[
0
],
[
1
],
[
0
,
1
]]
for
idx
,
dtype
in
enumerate
(
imap
(
str
,
theano
.
scalar
.
all_types
)):
for
idx
,
dtype
in
enumerate
(
imap
(
str
,
theano
.
scalar
.
all_types
)):
axis
=
axes
[
idx
%
len
(
axes
)]
axis
=
axes
[
idx
%
len
(
axes
)]
x
=
tensor
.
matrix
(
dtype
=
dtype
)
.
sum
(
axis
=
axis
)
x
=
tensor
.
matrix
(
dtype
=
dtype
)
assert
x
.
dtype
==
dict
(
s
=
x
.
sum
(
axis
=
axis
)
assert
s
.
dtype
==
dict
(
int8
=
'int64'
,
int8
=
'int64'
,
int16
=
'int64'
,
int16
=
'int64'
,
int32
=
'int64'
,
int32
=
'int64'
,
...
@@ -629,15 +630,20 @@ class T_sum_dtype(unittest.TestCase):
...
@@ -629,15 +630,20 @@ class T_sum_dtype(unittest.TestCase):
uint16
=
'uint64'
,
uint16
=
'uint64'
,
uint32
=
'uint64'
,
uint32
=
'uint64'
,
)
.
get
(
dtype
,
dtype
)
)
.
get
(
dtype
,
dtype
)
f
=
theano
.
function
([
x
],
s
)
data
=
numpy
.
random
.
rand
(
3
,
4
)
*
10
data
=
data
.
astype
(
dtype
)
f
(
data
)
def
test_sum_default_acc_dtype
(
self
):
def
test_sum_default_acc_dtype
(
self
):
##Test the default acc_dtype of a sum().
##Test the default acc_dtype of a sum().
# We try multiple axis combinations even though axis should not matter.
# We try multiple axis combinations even though axis should not matter.
axes
=
[
None
,
0
,
1
,
[
0
],
[
1
],
[
0
,
1
]]
axes
=
[
None
,
0
,
1
,
[
],
[
0
],
[
1
],
[
0
,
1
]]
for
idx
,
dtype
in
enumerate
(
imap
(
str
,
theano
.
scalar
.
all_types
)):
for
idx
,
dtype
in
enumerate
(
imap
(
str
,
theano
.
scalar
.
all_types
)):
axis
=
axes
[
idx
%
len
(
axes
)]
axis
=
axes
[
idx
%
len
(
axes
)]
x
=
tensor
.
matrix
(
dtype
=
dtype
)
.
sum
(
axis
=
axis
)
x
=
tensor
.
matrix
(
dtype
=
dtype
)
assert
x
.
owner
.
op
.
acc_dtype
==
dict
(
s
=
x
.
sum
(
axis
=
axis
)
assert
s
.
owner
.
op
.
acc_dtype
==
dict
(
int8
=
'int64'
,
int8
=
'int64'
,
int16
=
'int64'
,
int16
=
'int64'
,
int32
=
'int64'
,
int32
=
'int64'
,
...
@@ -647,13 +653,17 @@ class T_sum_dtype(unittest.TestCase):
...
@@ -647,13 +653,17 @@ class T_sum_dtype(unittest.TestCase):
float32
=
'float64'
,
float32
=
'float64'
,
complex64
=
'complex128'
,
complex64
=
'complex128'
,
)
.
get
(
dtype
,
dtype
)
)
.
get
(
dtype
,
dtype
)
f
=
theano
.
function
([
x
],
s
)
data
=
numpy
.
random
.
rand
(
3
,
4
)
*
10
data
=
data
.
astype
(
dtype
)
f
(
data
)
def
test_sum_custom_dtype
(
self
):
def
test_sum_custom_dtype
(
self
):
"""
"""
Test the ability to provide your own output dtype for a sum.
Test the ability to provide your own output dtype for a sum.
"""
"""
# We try multiple axis combinations even though axis should not matter.
# We try multiple axis combinations even though axis should not matter.
axes
=
[
None
,
0
,
1
,
[
0
],
[
1
],
[
0
,
1
]]
axes
=
[
None
,
0
,
1
,
[
],
[
0
],
[
1
],
[
0
,
1
]]
idx
=
0
idx
=
0
for
input_dtype
in
imap
(
str
,
theano
.
scalar
.
all_types
):
for
input_dtype
in
imap
(
str
,
theano
.
scalar
.
all_types
):
x
=
tensor
.
matrix
(
dtype
=
input_dtype
)
x
=
tensor
.
matrix
(
dtype
=
input_dtype
)
...
@@ -669,6 +679,10 @@ class T_sum_dtype(unittest.TestCase):
...
@@ -669,6 +679,10 @@ class T_sum_dtype(unittest.TestCase):
sum_var
=
x
.
sum
(
dtype
=
output_dtype
,
axis
=
axis
)
sum_var
=
x
.
sum
(
dtype
=
output_dtype
,
axis
=
axis
)
assert
sum_var
.
dtype
==
output_dtype
assert
sum_var
.
dtype
==
output_dtype
f
=
theano
.
function
([
x
],
sum_var
)
data
=
numpy
.
random
.
rand
(
3
,
4
)
*
10
data
=
data
.
astype
(
input_dtype
)
f
(
data
)
if
"complex"
in
input_dtype
:
if
"complex"
in
input_dtype
:
continue
continue
# Check that we can take the gradient
# Check that we can take the gradient
...
@@ -681,7 +695,7 @@ class T_sum_dtype(unittest.TestCase):
...
@@ -681,7 +695,7 @@ class T_sum_dtype(unittest.TestCase):
Test the ability to provide your own accumulator dtype for a sum.
Test the ability to provide your own accumulator dtype for a sum.
"""
"""
# We try multiple axis combinations even though axis should not matter.
# We try multiple axis combinations even though axis should not matter.
axes
=
[
None
,
0
,
1
,
[
0
],
[
1
],
[
0
,
1
]]
axes
=
[
None
,
0
,
1
,
[
],
[
0
],
[
1
],
[
0
,
1
]]
idx
=
0
idx
=
0
for
input_dtype
in
imap
(
str
,
theano
.
scalar
.
all_types
):
for
input_dtype
in
imap
(
str
,
theano
.
scalar
.
all_types
):
x
=
tensor
.
matrix
(
dtype
=
input_dtype
)
x
=
tensor
.
matrix
(
dtype
=
input_dtype
)
...
@@ -730,21 +744,26 @@ class T_mean_dtype(unittest.TestCase):
...
@@ -730,21 +744,26 @@ class T_mean_dtype(unittest.TestCase):
Test the default dtype of a mean().
Test the default dtype of a mean().
"""
"""
# We try multiple axis combinations even though axis should not matter.
# We try multiple axis combinations even though axis should not matter.
axes
=
[
None
,
0
,
1
,
[
0
],
[
1
],
[
0
,
1
]]
axes
=
[
None
,
0
,
1
,
[
],
[
0
],
[
1
],
[
0
,
1
]]
for
idx
,
dtype
in
enumerate
(
imap
(
str
,
theano
.
scalar
.
all_types
)):
for
idx
,
dtype
in
enumerate
(
imap
(
str
,
theano
.
scalar
.
all_types
)):
axis
=
axes
[
idx
%
len
(
axes
)]
axis
=
axes
[
idx
%
len
(
axes
)]
x
=
tensor
.
matrix
(
dtype
=
dtype
)
.
mean
(
axis
=
axis
)
x
=
tensor
.
matrix
(
dtype
=
dtype
)
if
dtype
in
tensor
.
discrete_dtypes
:
m
=
x
.
mean
(
axis
=
axis
)
assert
x
.
dtype
==
'float64'
if
dtype
in
tensor
.
discrete_dtypes
and
axis
!=
[]:
assert
m
.
dtype
==
'float64'
else
:
else
:
assert
x
.
dtype
==
dtype
,
(
x
,
x
.
dtype
,
dtype
)
assert
m
.
dtype
==
dtype
,
(
m
,
m
.
dtype
,
dtype
)
f
=
theano
.
function
([
x
],
m
)
data
=
numpy
.
random
.
rand
(
3
,
4
)
*
10
data
=
data
.
astype
(
dtype
)
f
(
data
)
def
test_mean_custom_dtype
(
self
):
def
test_mean_custom_dtype
(
self
):
"""
"""
Test the ability to provide your own output dtype for a mean.
Test the ability to provide your own output dtype for a mean.
"""
"""
# We try multiple axis combinations even though axis should not matter.
# We try multiple axis combinations even though axis should not matter.
axes
=
[
None
,
0
,
1
,
[
0
],
[
1
],
[
0
,
1
]]
axes
=
[
None
,
0
,
1
,
[
],
[
0
],
[
1
],
[
0
,
1
]]
idx
=
0
idx
=
0
for
input_dtype
in
imap
(
str
,
theano
.
scalar
.
all_types
):
for
input_dtype
in
imap
(
str
,
theano
.
scalar
.
all_types
):
x
=
tensor
.
matrix
(
dtype
=
input_dtype
)
x
=
tensor
.
matrix
(
dtype
=
input_dtype
)
...
@@ -758,12 +777,20 @@ class T_mean_dtype(unittest.TestCase):
...
@@ -758,12 +777,20 @@ class T_mean_dtype(unittest.TestCase):
pass
pass
else
:
else
:
# Executed if no TypeError was raised
# Executed if no TypeError was raised
if
sum_dtype
in
tensor
.
discrete_dtypes
:
if
sum_dtype
in
tensor
.
discrete_dtypes
and
axis
!=
[]
:
assert
mean_var
.
dtype
==
'float64'
,
(
assert
mean_var
.
dtype
==
'float64'
,
(
(
mean_var
.
dtype
,
sum_dtype
))
(
mean_var
.
dtype
,
sum_dtype
))
else
:
else
:
assert
mean_var
.
dtype
==
sum_dtype
,
(
assert
mean_var
.
dtype
==
sum_dtype
,
(
(
mean_var
.
dtype
,
sum_dtype
))
(
mean_var
.
dtype
,
sum_dtype
))
if
((
'complex'
in
input_dtype
or
'complex'
in
sum_dtype
)
and
input_dtype
!=
sum_dtype
):
continue
f
=
theano
.
function
([
x
],
mean_var
)
data
=
numpy
.
random
.
rand
(
3
,
4
)
*
10
data
=
data
.
astype
(
input_dtype
)
f
(
data
)
# Check that we can take the gradient, when implemented
# Check that we can take the gradient, when implemented
if
"complex"
in
mean_var
.
dtype
:
if
"complex"
in
mean_var
.
dtype
:
continue
continue
...
@@ -795,11 +822,12 @@ class T_prod_dtype(unittest.TestCase):
...
@@ -795,11 +822,12 @@ class T_prod_dtype(unittest.TestCase):
Test the default dtype of a prod().
Test the default dtype of a prod().
"""
"""
# We try multiple axis combinations even though axis should not matter.
# We try multiple axis combinations even though axis should not matter.
axes
=
[
None
,
0
,
1
,
[
0
],
[
1
],
[
0
,
1
]]
axes
=
[
None
,
0
,
1
,
[
],
[
0
],
[
1
],
[
0
,
1
]]
for
idx
,
dtype
in
enumerate
(
imap
(
str
,
theano
.
scalar
.
all_types
)):
for
idx
,
dtype
in
enumerate
(
imap
(
str
,
theano
.
scalar
.
all_types
)):
axis
=
axes
[
idx
%
len
(
axes
)]
axis
=
axes
[
idx
%
len
(
axes
)]
x
=
tensor
.
matrix
(
dtype
=
dtype
)
.
prod
(
axis
=
axis
)
x
=
tensor
.
matrix
(
dtype
=
dtype
)
assert
x
.
dtype
==
dict
(
p
=
x
.
prod
(
axis
=
axis
)
assert
p
.
dtype
==
dict
(
int8
=
'int64'
,
int8
=
'int64'
,
int16
=
'int64'
,
int16
=
'int64'
,
int32
=
'int64'
,
int32
=
'int64'
,
...
@@ -807,17 +835,22 @@ class T_prod_dtype(unittest.TestCase):
...
@@ -807,17 +835,22 @@ class T_prod_dtype(unittest.TestCase):
uint16
=
'uint64'
,
uint16
=
'uint64'
,
uint32
=
'uint64'
,
uint32
=
'uint64'
,
)
.
get
(
dtype
,
dtype
)
)
.
get
(
dtype
,
dtype
)
f
=
theano
.
function
([
x
],
p
)
data
=
numpy
.
random
.
rand
(
3
,
4
)
*
10
data
=
data
.
astype
(
dtype
)
f
(
data
)
def
test_prod_default_acc_dtype
(
self
):
def
test_prod_default_acc_dtype
(
self
):
"""
"""
Test the default acc_dtype of a prod().
Test the default acc_dtype of a prod().
"""
"""
# We try multiple axis combinations even though axis should not matter.
# We try multiple axis combinations even though axis should not matter.
axes
=
[
None
,
0
,
1
,
[
0
],
[
1
],
[
0
,
1
]]
axes
=
[
None
,
0
,
1
,
[
],
[
0
],
[
1
],
[
0
,
1
]]
for
idx
,
dtype
in
enumerate
(
imap
(
str
,
theano
.
scalar
.
all_types
)):
for
idx
,
dtype
in
enumerate
(
imap
(
str
,
theano
.
scalar
.
all_types
)):
axis
=
axes
[
idx
%
len
(
axes
)]
axis
=
axes
[
idx
%
len
(
axes
)]
x
=
tensor
.
matrix
(
dtype
=
dtype
)
.
prod
(
axis
=
axis
)
x
=
tensor
.
matrix
(
dtype
=
dtype
)
assert
x
.
owner
.
op
.
acc_dtype
==
dict
(
p
=
x
.
prod
(
axis
=
axis
)
assert
p
.
owner
.
op
.
acc_dtype
==
dict
(
int8
=
'int64'
,
int8
=
'int64'
,
int16
=
'int64'
,
int16
=
'int64'
,
int32
=
'int64'
,
int32
=
'int64'
,
...
@@ -827,34 +860,48 @@ class T_prod_dtype(unittest.TestCase):
...
@@ -827,34 +860,48 @@ class T_prod_dtype(unittest.TestCase):
float32
=
'float64'
,
float32
=
'float64'
,
complex64
=
'complex128'
,
complex64
=
'complex128'
,
)
.
get
(
dtype
,
dtype
)
)
.
get
(
dtype
,
dtype
)
f
=
theano
.
function
([
x
],
p
)
data
=
numpy
.
random
.
rand
(
3
,
4
)
*
10
data
=
data
.
astype
(
dtype
)
f
(
data
)
def
test_prod_custom_dtype
(
self
):
def
test_prod_custom_dtype
(
self
):
"""
"""
Test the ability to provide your own output dtype for a prod.
Test the ability to provide your own output dtype for a prod.
"""
"""
# We try multiple axis combinations even though axis should not matter.
# We try multiple axis combinations even though axis should not matter.
axes
=
[
None
,
0
,
1
,
[
0
],
[
1
],
[
0
,
1
]]
axes
=
[
None
,
0
,
1
,
[
],
[
0
],
[
1
],
[
0
,
1
]]
idx
=
0
idx
=
0
for
input_dtype
in
imap
(
str
,
theano
.
scalar
.
all_types
):
for
input_dtype
in
imap
(
str
,
theano
.
scalar
.
all_types
):
x
=
tensor
.
matrix
(
dtype
=
input_dtype
)
x
=
tensor
.
matrix
(
dtype
=
input_dtype
)
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
)]
idx
+=
1
prod_var
=
x
.
prod
(
dtype
=
output_dtype
,
axis
=
axis
)
prod_var
=
x
.
prod
(
dtype
=
output_dtype
,
axis
=
axis
)
assert
prod_var
.
dtype
==
output_dtype
assert
prod_var
.
dtype
==
output_dtype
if
((
'complex'
in
output_dtype
or
'complex'
in
input_dtype
)
and
input_dtype
!=
output_dtype
):
continue
f
=
theano
.
function
([
x
],
prod_var
)
data
=
numpy
.
random
.
rand
(
3
,
4
)
*
10
data
=
data
.
astype
(
input_dtype
)
f
(
data
)
if
"complex"
in
output_dtype
or
"complex"
in
input_dtype
:
if
"complex"
in
output_dtype
or
"complex"
in
input_dtype
:
continue
continue
# Check that we can take the gradient
# Check that we can take the gradient
tensor
.
grad
(
prod_var
.
sum
(),
x
,
tensor
.
grad
(
prod_var
.
sum
(),
x
,
disconnected_inputs
=
'ignore'
)
disconnected_inputs
=
'ignore'
)
idx
+=
1
def
test_prod_custom_acc_dtype
(
self
):
def
test_prod_custom_acc_dtype
(
self
):
"""
"""
Test the ability to provide your own acc_dtype for a prod.
Test the ability to provide your own acc_dtype for a prod.
"""
"""
# We try multiple axis combinations even though axis should not matter.
# We try multiple axis combinations even though axis should not matter.
axes
=
[
None
,
0
,
1
,
[
0
],
[
1
],
[
0
,
1
]]
axes
=
[
None
,
0
,
1
,
[
],
[
0
],
[
1
],
[
0
,
1
]]
idx
=
0
idx
=
0
for
input_dtype
in
imap
(
str
,
theano
.
scalar
.
all_types
):
for
input_dtype
in
imap
(
str
,
theano
.
scalar
.
all_types
):
x
=
tensor
.
matrix
(
dtype
=
input_dtype
)
x
=
tensor
.
matrix
(
dtype
=
input_dtype
)
...
@@ -870,6 +917,14 @@ class T_prod_dtype(unittest.TestCase):
...
@@ -870,6 +917,14 @@ class T_prod_dtype(unittest.TestCase):
prod_var
=
x
.
prod
(
acc_dtype
=
acc_dtype
,
axis
=
axis
)
prod_var
=
x
.
prod
(
acc_dtype
=
acc_dtype
,
axis
=
axis
)
assert
prod_var
.
owner
.
op
.
acc_dtype
==
acc_dtype
assert
prod_var
.
owner
.
op
.
acc_dtype
==
acc_dtype
if
(
acc_dtype
.
startswith
(
'complex'
)
and
input_dtype
!=
acc_dtype
):
continue
f
=
theano
.
function
([
x
],
prod_var
)
data
=
numpy
.
random
.
rand
(
3
,
4
)
*
10
data
=
data
.
astype
(
input_dtype
)
f
(
data
)
if
"complex"
in
acc_dtype
:
if
"complex"
in
acc_dtype
:
continue
continue
# Check that we can take the gradient
# Check that we can take the gradient
...
@@ -888,7 +943,7 @@ class T_prod_without_zeros_dtype(unittest.TestCase):
...
@@ -888,7 +943,7 @@ class T_prod_without_zeros_dtype(unittest.TestCase):
Test the default dtype of a ProdWithoutZeros().
Test the default dtype of a ProdWithoutZeros().
"""
"""
# We try multiple axis combinations even though axis should not matter.
# We try multiple axis combinations even though axis should not matter.
axes
=
[
None
,
0
,
1
,
[
0
],
[
1
],
[
0
,
1
]]
axes
=
[
None
,
0
,
1
,
[
],
[
0
],
[
1
],
[
0
,
1
]]
for
idx
,
dtype
in
enumerate
(
imap
(
str
,
theano
.
scalar
.
all_types
)):
for
idx
,
dtype
in
enumerate
(
imap
(
str
,
theano
.
scalar
.
all_types
)):
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
))
...
@@ -906,11 +961,12 @@ class T_prod_without_zeros_dtype(unittest.TestCase):
...
@@ -906,11 +961,12 @@ class T_prod_without_zeros_dtype(unittest.TestCase):
Test the default dtype of a ProdWithoutZeros().
Test the default dtype of a ProdWithoutZeros().
"""
"""
# We try multiple axis combinations even though axis should not matter.
# We try multiple axis combinations even though axis should not matter.
axes
=
[
None
,
0
,
1
,
[
0
],
[
1
],
[
0
,
1
]]
axes
=
[
None
,
0
,
1
,
[
],
[
0
],
[
1
],
[
0
,
1
]]
for
idx
,
dtype
in
enumerate
(
imap
(
str
,
theano
.
scalar
.
all_types
)):
for
idx
,
dtype
in
enumerate
(
imap
(
str
,
theano
.
scalar
.
all_types
)):
axis
=
axes
[
idx
%
len
(
axes
)]
axis
=
axes
[
idx
%
len
(
axes
)]
x
=
ProdWithoutZeros
(
axis
=
axis
)(
tensor
.
matrix
(
dtype
=
dtype
))
x
=
tensor
.
matrix
(
dtype
=
dtype
)
assert
x
.
owner
.
op
.
acc_dtype
==
dict
(
p
=
ProdWithoutZeros
(
axis
=
axis
)(
x
)
assert
p
.
owner
.
op
.
acc_dtype
==
dict
(
int8
=
'int64'
,
int8
=
'int64'
,
int16
=
'int64'
,
int16
=
'int64'
,
int32
=
'int64'
,
int32
=
'int64'
,
...
@@ -921,12 +977,19 @@ class T_prod_without_zeros_dtype(unittest.TestCase):
...
@@ -921,12 +977,19 @@ class T_prod_without_zeros_dtype(unittest.TestCase):
complex64
=
'complex128'
complex64
=
'complex128'
)
.
get
(
dtype
,
dtype
)
)
.
get
(
dtype
,
dtype
)
if
'complex'
in
dtype
:
continue
f
=
theano
.
function
([
x
],
p
)
data
=
numpy
.
random
.
rand
(
2
,
3
)
*
3
data
=
data
.
astype
(
dtype
)
f
(
data
)
def
test_prod_without_zeros_custom_dtype
(
self
):
def
test_prod_without_zeros_custom_dtype
(
self
):
"""
"""
Test ability to provide your own output dtype for a ProdWithoutZeros().
Test ability to provide your own output dtype for a ProdWithoutZeros().
"""
"""
# We try multiple axis combinations even though axis should not matter.
# We try multiple axis combinations even though axis should not matter.
axes
=
[
None
,
0
,
1
,
[
0
],
[
1
],
[
0
,
1
]]
axes
=
[
None
,
0
,
1
,
[
],
[
0
],
[
1
],
[
0
,
1
]]
idx
=
0
idx
=
0
for
input_dtype
in
imap
(
str
,
theano
.
scalar
.
all_types
):
for
input_dtype
in
imap
(
str
,
theano
.
scalar
.
all_types
):
x
=
tensor
.
matrix
(
dtype
=
input_dtype
)
x
=
tensor
.
matrix
(
dtype
=
input_dtype
)
...
@@ -936,13 +999,20 @@ class T_prod_without_zeros_dtype(unittest.TestCase):
...
@@ -936,13 +999,20 @@ class T_prod_without_zeros_dtype(unittest.TestCase):
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
'complex'
in
input_dtype
):
continue
f
=
theano
.
function
([
x
],
prod_woz_var
)
data
=
numpy
.
random
.
rand
(
2
,
3
)
*
3
data
=
data
.
astype
(
input_dtype
)
f
(
data
)
def
test_prod_without_zeros_custom_acc_dtype
(
self
):
def
test_prod_without_zeros_custom_acc_dtype
(
self
):
"""
"""
Test ability to provide your own acc_dtype for a ProdWithoutZeros().
Test ability to provide your own acc_dtype for a ProdWithoutZeros().
"""
"""
# We try multiple axis combinations even though axis should not matter.
# We try multiple axis combinations even though axis should not matter.
axes
=
[
None
,
0
,
1
,
[
0
],
[
1
],
[
0
,
1
]]
axes
=
[
None
,
0
,
1
,
[
],
[
0
],
[
1
],
[
0
,
1
]]
idx
=
0
idx
=
0
for
input_dtype
in
imap
(
str
,
theano
.
scalar
.
all_types
):
for
input_dtype
in
imap
(
str
,
theano
.
scalar
.
all_types
):
x
=
tensor
.
matrix
(
dtype
=
input_dtype
)
x
=
tensor
.
matrix
(
dtype
=
input_dtype
)
...
@@ -958,6 +1028,14 @@ class T_prod_without_zeros_dtype(unittest.TestCase):
...
@@ -958,6 +1028,14 @@ class T_prod_without_zeros_dtype(unittest.TestCase):
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
input_dtype
!=
acc_dtype
):
continue
f
=
theano
.
function
([
x
],
prod_woz_var
)
data
=
numpy
.
random
.
rand
(
2
,
3
)
*
3
data
=
data
.
astype
(
input_dtype
)
f
(
data
)
else
:
else
:
self
.
assertRaises
(
TypeError
,
self
.
assertRaises
(
TypeError
,
ProdWithoutZeros
(
axis
=
axis
,
acc_dtype
=
acc_dtype
),
ProdWithoutZeros
(
axis
=
axis
,
acc_dtype
=
acc_dtype
),
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论