Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
5e02eb8b
提交
5e02eb8b
authored
6月 13, 2013
作者:
Frederic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
BUGFIX: reduction that upcast the input on no axis (ex: sum on scalar).
It produce bad results as we don't upcast the inputs in the code, we just copy it.
上级
85f83402
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
39 行增加
和
20 行删除
+39
-20
elemwise.py
theano/tensor/elemwise.py
+7
-2
test_elemwise.py
theano/tensor/tests/test_elemwise.py
+32
-18
没有找到文件。
theano/tensor/elemwise.py
浏览文件 @
5e02eb8b
...
@@ -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
浏览文件 @
5e02eb8b
...
@@ -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
)
...
@@ -675,13 +685,17 @@ class T_sum_dtype(unittest.TestCase):
...
@@ -675,13 +685,17 @@ class T_sum_dtype(unittest.TestCase):
tensor
.
grad
(
sum_var
.
sum
(),
x
,
tensor
.
grad
(
sum_var
.
sum
(),
x
,
disconnected_inputs
=
'ignore'
)
disconnected_inputs
=
'ignore'
)
idx
+=
1
idx
+=
1
f
=
theano
.
function
([
x
],
sum_var
)
data
=
numpy
.
random
.
rand
(
3
,
4
)
*
10
data
=
data
.
astype
(
input_dtype
)
f
(
data
)
def
test_sum_custom_acc_dtype
(
self
):
def
test_sum_custom_acc_dtype
(
self
):
"""
"""
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,7 +744,7 @@ class T_mean_dtype(unittest.TestCase):
...
@@ -730,7 +744,7 @@ 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
)
.
mean
(
axis
=
axis
)
...
@@ -744,7 +758,7 @@ class T_mean_dtype(unittest.TestCase):
...
@@ -744,7 +758,7 @@ class T_mean_dtype(unittest.TestCase):
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
)
...
@@ -795,7 +809,7 @@ class T_prod_dtype(unittest.TestCase):
...
@@ -795,7 +809,7 @@ 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
)
.
prod
(
axis
=
axis
)
...
@@ -813,7 +827,7 @@ class T_prod_dtype(unittest.TestCase):
...
@@ -813,7 +827,7 @@ class T_prod_dtype(unittest.TestCase):
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
)
.
prod
(
axis
=
axis
)
...
@@ -833,7 +847,7 @@ class T_prod_dtype(unittest.TestCase):
...
@@ -833,7 +847,7 @@ class T_prod_dtype(unittest.TestCase):
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
)
...
@@ -854,7 +868,7 @@ class T_prod_dtype(unittest.TestCase):
...
@@ -854,7 +868,7 @@ class T_prod_dtype(unittest.TestCase):
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
)
...
@@ -888,7 +902,7 @@ class T_prod_without_zeros_dtype(unittest.TestCase):
...
@@ -888,7 +902,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,7 +920,7 @@ class T_prod_without_zeros_dtype(unittest.TestCase):
...
@@ -906,7 +920,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
))
...
@@ -926,7 +940,7 @@ class T_prod_without_zeros_dtype(unittest.TestCase):
...
@@ -926,7 +940,7 @@ class T_prod_without_zeros_dtype(unittest.TestCase):
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
)
...
@@ -942,7 +956,7 @@ class T_prod_without_zeros_dtype(unittest.TestCase):
...
@@ -942,7 +956,7 @@ class T_prod_without_zeros_dtype(unittest.TestCase):
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
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论