Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
4078794d
提交
4078794d
authored
6月 27, 2013
作者:
lamblin
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1432 from nouiz/fix_sum_sum_crash
Fix sum sum crash
上级
6469c740
2e991052
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
56 行增加
和
22 行删除
+56
-22
basic.py
theano/tensor/basic.py
+14
-2
opt.py
theano/tensor/opt.py
+1
-1
test_keepdims.py
theano/tensor/tests/test_keepdims.py
+13
-5
test_opt.py
theano/tensor/tests/test_opt.py
+28
-14
没有找到文件。
theano/tensor/basic.py
浏览文件 @
4078794d
...
@@ -2653,8 +2653,13 @@ class MaxAndArgmax(Op):
...
@@ -2653,8 +2653,13 @@ class MaxAndArgmax(Op):
axis
=
[
axis
]
axis
=
[
axis
]
elif
isinstance
(
axis
,
(
tuple
,
list
)):
elif
isinstance
(
axis
,
(
tuple
,
list
)):
if
len
(
axis
)
!=
1
:
if
len
(
axis
)
!=
1
:
list
(
axis
)
axis
=
list
(
axis
)
for
idx
in
range
(
len
(
axis
)):
if
axis
[
idx
]
<
0
:
axis
[
idx
]
+=
x
.
type
.
ndim
axis
.
sort
()
axis
.
sort
()
if
axis
==
range
(
-
x
.
type
.
ndim
,
0
,
1
):
axis
=
range
(
x
.
type
.
ndim
)
assert
axis
==
range
(
x
.
type
.
ndim
),
(
assert
axis
==
range
(
x
.
type
.
ndim
),
(
"MaxAndArgmax does not support multiple"
"MaxAndArgmax does not support multiple"
" axes. the max fct supports it."
)
" axes. the max fct supports it."
)
...
@@ -2806,10 +2811,17 @@ def makeKeepDims(x, y, axis):
...
@@ -2806,10 +2811,17 @@ def makeKeepDims(x, y, axis):
axis
=
range
(
x
.
type
.
ndim
)
axis
=
range
(
x
.
type
.
ndim
)
elif
isinstance
(
axis
,
int
):
elif
isinstance
(
axis
,
int
):
axis
=
[
axis
]
axis
=
[
axis
]
newaxis
=
[]
for
a
in
axis
:
if
not
isinstance
(
a
,
int
):
raise
ValueError
(
"keepdims option can be used only with constant axis"
)
if
a
<
0
:
a
+=
x
.
type
.
ndim
newaxis
.
append
(
a
)
i
=
0
i
=
0
new_dims
=
[]
new_dims
=
[]
for
j
,
_
in
enumerate
(
x
.
type
.
broadcastable
):
for
j
,
_
in
enumerate
(
x
.
type
.
broadcastable
):
if
j
in
axis
:
if
j
in
new
axis
:
new_dims
.
append
(
'x'
)
new_dims
.
append
(
'x'
)
else
:
else
:
new_dims
.
append
(
i
)
new_dims
.
append
(
i
)
...
...
theano/tensor/opt.py
浏览文件 @
4078794d
...
@@ -3209,7 +3209,7 @@ def local_sum_sum(node):
...
@@ -3209,7 +3209,7 @@ def local_sum_sum(node):
for
i
in
node
.
op
.
axis
:
for
i
in
node
.
op
.
axis
:
new_i
=
i
new_i
=
i
for
ii
in
summed
.
owner
.
op
.
axis
:
for
ii
in
summed
.
owner
.
op
.
axis
:
if
i
>=
ii
:
if
new_
i
>=
ii
:
new_i
+=
1
new_i
+=
1
assert
new_i
not
in
newaxis
assert
new_i
not
in
newaxis
newaxis
.
append
(
new_i
)
newaxis
.
append
(
new_i
)
...
...
theano/tensor/tests/test_keepdims.py
浏览文件 @
4078794d
...
@@ -13,9 +13,14 @@ class TestKeepDims:
...
@@ -13,9 +13,14 @@ class TestKeepDims:
elif
isinstance
(
axis
,
int
):
elif
isinstance
(
axis
,
int
):
axis
=
[
axis
]
axis
=
[
axis
]
i
=
0
i
=
0
newaxis
=
[]
for
a
in
axis
:
if
a
<
0
:
a
+=
x
.
type
.
ndim
newaxis
.
append
(
a
)
new_dims
=
[]
new_dims
=
[]
for
j
,
_
in
enumerate
(
x
.
shape
):
for
j
,
_
in
enumerate
(
x
.
shape
):
if
j
in
axis
:
if
j
in
new
axis
:
new_dims
.
append
(
'x'
)
new_dims
.
append
(
'x'
)
else
:
else
:
new_dims
.
append
(
i
)
new_dims
.
append
(
i
)
...
@@ -30,7 +35,9 @@ class TestKeepDims:
...
@@ -30,7 +35,9 @@ class TestKeepDims:
# 'max_and_argmax' has two outputs and can be specified with either
# 'max_and_argmax' has two outputs and can be specified with either
# a single or every axis:
# a single or every axis:
for
axis
in
[
0
,
1
,
2
,
[
0
],
[
1
],
[
2
],
None
,
[
0
,
1
,
2
]]:
for
axis
in
[
0
,
1
,
2
,
[
0
],
[
1
],
[
2
],
None
,
[
0
,
1
,
2
],
[
-
1
],
[
-
2
],
[
-
3
],
[
-
1
,
-
2
,
-
3
],
[
0
,
-
1
,
-
2
],
[
-
2
,
-
3
,
2
]]:
op
=
tensor
.
max_and_argmax
op
=
tensor
.
max_and_argmax
keep_param
=
function
([
x
],
op
(
x
,
axis
=
axis
,
keepdims
=
True
)[
0
])
keep_param
=
function
([
x
],
op
(
x
,
axis
=
axis
,
keepdims
=
True
)[
0
])
...
@@ -50,8 +57,8 @@ class TestKeepDims:
...
@@ -50,8 +57,8 @@ class TestKeepDims:
# the following ops can be specified with either a single axis or every
# the following ops can be specified with either a single axis or every
# axis:
# axis:
for
op
in
([
tensor
.
argmax
,
tensor
.
argmin
]):
for
op
in
([
tensor
.
argmax
,
tensor
.
argmin
]):
for
axis
in
[
0
,
1
,
2
,
[
0
],
[
1
],
[
2
],
None
,
[
0
,
1
,
2
],
for
axis
in
[
0
,
1
,
2
,
[
0
],
[
1
],
[
2
],
None
,
[
0
,
1
,
2
]]:
[
-
1
],
[
-
2
],
[
-
3
],
[
-
1
,
-
2
,
-
3
],
[
0
,
-
2
,
2
]]:
keep_param
=
function
([
x
],
op
(
x
,
axis
=
axis
,
keepdims
=
True
))
keep_param
=
function
([
x
],
op
(
x
,
axis
=
axis
,
keepdims
=
True
))
keep_synth
=
function
([
x
],
self
.
makeKeepDims_local
(
x
,
keep_synth
=
function
([
x
],
self
.
makeKeepDims_local
(
x
,
...
@@ -72,7 +79,8 @@ class TestKeepDims:
...
@@ -72,7 +79,8 @@ class TestKeepDims:
for
op
in
([
tensor
.
sum
,
tensor
.
prod
,
tensor
.
mean
,
tensor
.
var
,
for
op
in
([
tensor
.
sum
,
tensor
.
prod
,
tensor
.
mean
,
tensor
.
var
,
tensor
.
std
,
tensor
.
all
,
tensor
.
any
,
tensor
.
std
,
tensor
.
all
,
tensor
.
any
,
tensor
.
max
,
tensor
.
min
]):
tensor
.
max
,
tensor
.
min
]):
for
axis
in
[
0
,
1
,
2
,
[
0
],
[
1
],
[
2
],
[
0
,
1
],
[
1
,
2
],
[
0
,
1
,
2
]]:
for
axis
in
[
0
,
1
,
2
,
[
0
],
[
1
],
[
2
],
[
0
,
1
],
[
1
,
2
],
[
0
,
1
,
2
],
[
-
1
],
[
-
2
],
[
-
3
],
[
-
1
,
-
2
],
[
-
1
,
-
2
,
-
3
],
[
0
,
-
2
,
2
]]:
keep_param
=
function
([
x
],
op
(
x
,
axis
=
axis
,
keepdims
=
True
))
keep_param
=
function
([
x
],
op
(
x
,
axis
=
axis
,
keepdims
=
True
))
keep_synth
=
function
([
x
],
self
.
makeKeepDims_local
(
x
,
keep_synth
=
function
([
x
],
self
.
makeKeepDims_local
(
x
,
...
...
theano/tensor/tests/test_opt.py
浏览文件 @
4078794d
...
@@ -3473,7 +3473,7 @@ class T_local_sum(unittest.TestCase):
...
@@ -3473,7 +3473,7 @@ class T_local_sum(unittest.TestCase):
def
test_local_sum_all_to_none
(
self
):
def
test_local_sum_all_to_none
(
self
):
a
=
T
.
tensor3
()
a
=
T
.
tensor3
()
input
=
numpy
.
arange
(
3
*
3
*
3
,
dtype
=
config
.
floatX
)
.
reshape
(
3
,
3
,
3
)
input
=
numpy
.
arange
(
3
*
4
*
5
,
dtype
=
config
.
floatX
)
.
reshape
(
3
,
4
,
5
)
f
=
theano
.
function
([
a
],
a
.
sum
(),
mode
=
self
.
mode
)
f
=
theano
.
function
([
a
],
a
.
sum
(),
mode
=
self
.
mode
)
assert
len
(
f
.
maker
.
fgraph
.
apply_nodes
)
==
1
assert
len
(
f
.
maker
.
fgraph
.
apply_nodes
)
==
1
assert
numpy
.
allclose
(
f
(
input
),
input
.
sum
())
assert
numpy
.
allclose
(
f
(
input
),
input
.
sum
())
...
@@ -3493,36 +3493,50 @@ class T_local_sum(unittest.TestCase):
...
@@ -3493,36 +3493,50 @@ class T_local_sum(unittest.TestCase):
def
test_local_sum_sum
(
self
):
def
test_local_sum_sum
(
self
):
a
=
T
.
tensor3
()
a
=
T
.
tensor3
()
input
=
numpy
.
arange
(
3
*
3
*
3
,
dtype
=
config
.
floatX
)
.
reshape
(
3
,
3
,
3
)
input
=
numpy
.
arange
(
3
*
4
*
5
,
dtype
=
config
.
floatX
)
.
reshape
(
3
,
4
,
5
)
dims
=
[(
0
,
0
),
(
1
,
0
),
(
2
,
0
),
(
0
,
1
),
(
1
,
1
),
(
2
,
1
)]
dims
=
[(
0
,
0
),
(
1
,
0
),
(
2
,
0
),
(
0
,
1
),
(
1
,
1
),
(
2
,
1
),
((
0
,
1
),
0
),
((
1
,
2
),
0
),
(
0
,
(
0
,
1
)),
(
1
,
(
0
,
1
)),
(
2
,
(
0
,
1
))]
backup
=
config
.
warn
.
sum_sum_bug
backup
=
config
.
warn
.
sum_sum_bug
config
.
warn
.
sum_sum_bug
=
False
config
.
warn
.
sum_sum_bug
=
False
def
my_sum
(
data
,
d
,
dd
):
# This sum when d or dd is a tuple of 2 dimensions.
if
not
isinstance
(
d
,
tuple
)
and
not
isinstance
(
dd
,
tuple
):
return
data
.
sum
(
d
)
.
sum
(
dd
)
if
isinstance
(
d
,
tuple
):
d
=
sorted
(
d
)
return
data
.
sum
(
d
[
1
])
.
sum
(
d
[
0
])
.
sum
(
dd
)
else
:
dd
=
sorted
(
dd
)
return
data
.
sum
(
d
)
.
sum
(
dd
[
1
])
.
sum
(
dd
[
0
])
try
:
try
:
for
d
,
dd
in
dims
:
for
d
,
dd
in
dims
:
expected
=
my_sum
(
input
,
d
,
dd
)
f
=
theano
.
function
([
a
],
a
.
sum
(
d
)
.
sum
(
dd
),
mode
=
self
.
mode
)
f
=
theano
.
function
([
a
],
a
.
sum
(
d
)
.
sum
(
dd
),
mode
=
self
.
mode
)
assert
numpy
.
allclose
(
f
(
input
),
input
.
sum
(
d
)
.
sum
(
dd
)
)
assert
numpy
.
allclose
(
f
(
input
),
expected
)
assert
len
(
f
.
maker
.
fgraph
.
apply_nodes
)
==
1
assert
len
(
f
.
maker
.
fgraph
.
apply_nodes
)
==
1
for
d
,
dd
in
dims
:
for
d
,
dd
in
dims
[:
6
]
:
f
=
theano
.
function
([
a
],
a
.
sum
(
d
)
.
sum
(
dd
)
.
f
=
theano
.
function
([
a
],
a
.
sum
(
d
)
.
sum
(
dd
)
.
sum
(
0
),
mode
=
self
.
mode
)
sum
(
0
),
mode
=
self
.
mode
)
assert
numpy
.
allclose
(
f
(
input
),
input
.
sum
(
d
)
.
sum
(
dd
)
.
sum
(
0
))
assert
numpy
.
allclose
(
f
(
input
),
input
.
sum
(
d
)
.
sum
(
dd
)
.
sum
(
0
))
assert
len
(
f
.
maker
.
fgraph
.
apply_nodes
)
==
1
assert
len
(
f
.
maker
.
fgraph
.
apply_nodes
)
==
1
for
d
in
[
0
,
1
,
2
]:
for
d
in
[
0
,
1
,
2
]:
f
=
theano
.
function
([
a
],
a
.
sum
(
d
)
.
sum
(
None
),
mode
=
self
.
mode
)
f
=
theano
.
function
([
a
],
a
.
sum
(
d
)
.
sum
(
None
),
mode
=
self
.
mode
)
assert
numpy
.
allclose
(
f
(
input
),
input
.
sum
(
d
)
.
sum
())
assert
numpy
.
allclose
(
f
(
input
),
input
.
sum
(
d
)
.
sum
())
assert
len
(
f
.
maker
.
fgraph
.
apply_nodes
)
==
1
assert
len
(
f
.
maker
.
fgraph
.
apply_nodes
)
==
1
for
d
in
[
0
,
1
,
2
]:
f
=
theano
.
function
([
a
],
a
.
sum
(
None
)
.
sum
(),
mode
=
self
.
mode
)
f
=
theano
.
function
([
a
],
a
.
sum
(
None
)
.
sum
(),
mode
=
self
.
mode
)
assert
numpy
.
allclose
(
f
(
input
),
input
.
sum
())
assert
numpy
.
allclose
(
f
(
input
),
input
.
sum
())
assert
len
(
f
.
maker
.
fgraph
.
apply_nodes
)
==
1
assert
len
(
f
.
maker
.
fgraph
.
apply_nodes
)
==
1
finally
:
finally
:
config
.
warn
.
sum_sum_bug
=
backup
config
.
warn
.
sum_sum_bug
=
backup
def
test_local_sum_alloc
(
self
):
def
test_local_sum_alloc
(
self
):
a
=
T
.
dtensor3
()
a
=
T
.
dtensor3
()
input
=
numpy
.
asarray
(
numpy
.
arange
(
2
*
3
*
4
)
.
reshape
(
2
,
3
,
4
),
input
=
numpy
.
asarray
(
numpy
.
arange
(
2
*
3
*
4
)
.
reshape
(
2
,
3
,
4
),
dtype
=
'float64'
)
dtype
=
'float64'
)
mode
=
self
.
mode
.
including
(
'specialize'
)
.
excluding
(
'fusion'
)
mode
=
self
.
mode
.
including
(
'specialize'
)
.
excluding
(
'fusion'
)
for
t_like
,
n_like
,
nb_nodes
in
[(
tensor
.
zeros_like
,
numpy
.
zeros_like
,(
1
,
3
,
3
,
2
)),
for
t_like
,
n_like
,
nb_nodes
in
[(
tensor
.
zeros_like
,
numpy
.
zeros_like
,(
1
,
3
,
3
,
2
)),
...
@@ -3556,14 +3570,14 @@ class T_local_sum(unittest.TestCase):
...
@@ -3556,14 +3570,14 @@ class T_local_sum(unittest.TestCase):
try
:
try
:
for
d
,
dd
in
[(
0
,
0
),
(
1
,
0
),
(
2
,
0
),
(
0
,
1
),
(
1
,
1
),
(
2
,
1
)]:
for
d
,
dd
in
[(
0
,
0
),
(
1
,
0
),
(
2
,
0
),
(
0
,
1
),
(
1
,
1
),
(
2
,
1
)]:
f
=
theano
.
function
([
a
],
t_like
(
a
)
.
f
=
theano
.
function
([
a
],
t_like
(
a
)
.
sum
(
d
)
.
sum
(
dd
),
mode
=
mode
)
sum
(
d
)
.
sum
(
dd
),
mode
=
mode
)
assert
numpy
.
allclose
(
f
(
input
),
assert
numpy
.
allclose
(
f
(
input
),
n_like
(
input
)
.
sum
(
d
)
.
sum
(
dd
))
n_like
(
input
)
.
sum
(
d
)
.
sum
(
dd
))
assert
len
(
f
.
maker
.
fgraph
.
apply_nodes
)
==
nb_nodes
[
3
]
assert
len
(
f
.
maker
.
fgraph
.
apply_nodes
)
==
nb_nodes
[
3
]
topo
=
f
.
maker
.
fgraph
.
toposort
()
topo
=
f
.
maker
.
fgraph
.
toposort
()
assert
topo
[
-
1
]
.
op
==
T
.
alloc
assert
topo
[
-
1
]
.
op
==
T
.
alloc
assert
not
any
([
isinstance
(
node
.
op
,
assert
not
any
([
isinstance
(
node
.
op
,
T
.
Sum
)
for
node
in
topo
])
T
.
Sum
)
for
node
in
topo
])
finally
:
finally
:
config
.
warn
.
sum_sum_bug
=
backup
config
.
warn
.
sum_sum_bug
=
backup
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论