Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
e014950e
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
e014950e
编写于
3月 29, 2019
作者:
W
wopeizl
提交者:
GitHub
3月 29, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add slice support for dim < 0 (#16494)
* add slice support for dim < 0 test=develop
上级
8f7b5883
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
39 addition
and
38 deletion
+39
-38
python/paddle/fluid/framework.py
python/paddle/fluid/framework.py
+17
-6
python/paddle/fluid/tests/unittests/test_variable.py
python/paddle/fluid/tests/unittests/test_variable.py
+22
-32
未找到文件。
python/paddle/fluid/framework.py
浏览文件 @
e014950e
...
@@ -789,13 +789,24 @@ class Variable(object):
...
@@ -789,13 +789,24 @@ class Variable(object):
if
isinstance
(
item
,
tuple
):
if
isinstance
(
item
,
tuple
):
if
len
(
item
)
>
len
(
self
.
shape
):
if
len
(
item
)
>
len
(
self
.
shape
):
raise
IndexError
(
"Too many indexes"
)
raise
IndexError
(
"Too many indexes"
)
fixedSize
=
True
for
i
in
range
(
len
(
self
.
shape
)):
if
self
.
shape
[
i
]
==
-
1
:
fixedSize
=
False
break
newitem
=
self
.
_reconstructSliceinfo
(
item
)
or
item
newitem
=
self
.
_reconstructSliceinfo
(
item
)
or
item
check
,
info
=
self
.
_detectContinuesSlice
(
newitem
)
if
fixedSize
:
if
check
:
check
,
info
=
self
.
_detectContinuesSlice
(
newitem
)
starts
=
info
[
0
]
if
check
and
fixedSize
:
ends
=
info
[
1
]
starts
=
info
[
0
]
axes
=
[
i
for
i
in
range
(
len
(
starts
))]
ends
=
info
[
1
]
return
self
.
_sliceVar
(
axes
,
starts
,
ends
)
axes
=
[
i
for
i
in
range
(
len
(
starts
))]
return
self
.
_sliceVar
(
axes
,
starts
,
ends
)
else
:
new_var
=
self
for
index
,
o
in
enumerate
(
newitem
):
new_var
=
new_var
.
_sliceAndConcatVar
(
o
,
index
)
else
:
else
:
new_var
=
self
new_var
=
self
for
index
,
o
in
enumerate
(
newitem
):
for
index
,
o
in
enumerate
(
newitem
):
...
...
python/paddle/fluid/tests/unittests/test_variable.py
浏览文件 @
e014950e
...
@@ -61,7 +61,7 @@ class TestVariable(unittest.TestCase):
...
@@ -61,7 +61,7 @@ class TestVariable(unittest.TestCase):
name
=
'step_scopes'
,
type
=
core
.
VarDesc
.
VarType
.
STEP_SCOPES
)
name
=
'step_scopes'
,
type
=
core
.
VarDesc
.
VarType
.
STEP_SCOPES
)
self
.
assertEqual
(
core
.
VarDesc
.
VarType
.
STEP_SCOPES
,
var
.
type
)
self
.
assertEqual
(
core
.
VarDesc
.
VarType
.
STEP_SCOPES
,
var
.
type
)
def
_test_slice
(
self
):
def
_test_slice
(
self
,
place
):
b
=
default_main_program
().
current_block
()
b
=
default_main_program
().
current_block
()
w
=
b
.
create_var
(
dtype
=
"float64"
,
shape
=
[
784
,
100
,
100
],
lod_level
=
0
)
w
=
b
.
create_var
(
dtype
=
"float64"
,
shape
=
[
784
,
100
,
100
],
lod_level
=
0
)
...
@@ -83,7 +83,6 @@ class TestVariable(unittest.TestCase):
...
@@ -83,7 +83,6 @@ class TestVariable(unittest.TestCase):
self
.
assertEqual
(
0
,
nw
.
lod_level
)
self
.
assertEqual
(
0
,
nw
.
lod_level
)
place
=
fluid
.
CPUPlace
()
main
=
fluid
.
Program
()
main
=
fluid
.
Program
()
with
fluid
.
program_guard
(
main
):
with
fluid
.
program_guard
(
main
):
exe
=
fluid
.
Executor
(
place
)
exe
=
fluid
.
Executor
(
place
)
...
@@ -100,10 +99,23 @@ class TestVariable(unittest.TestCase):
...
@@ -100,10 +99,23 @@ class TestVariable(unittest.TestCase):
var6
=
var
[
1
,
1
:,
1
:]
var6
=
var
[
1
,
1
:,
1
:]
var7
=
var
[
1
,
...,
1
:]
var7
=
var
[
1
,
...,
1
:]
var8
=
var
[
1
,
...]
var8
=
var
[
1
,
...]
var_reshape
=
fluid
.
layers
.
reshape
(
var
,
[
3
,
-
1
,
3
])
var9
=
var_reshape
[
1
,
...,
2
]
var10
=
var_reshape
[:,
:,
-
1
]
x
=
fluid
.
layers
.
data
(
name
=
'x'
,
shape
=
[
13
],
dtype
=
'float32'
)
y
=
fluid
.
layers
.
fc
(
input
=
x
,
size
=
1
,
act
=
None
)
var11
=
y
[:,
0
]
feeder
=
fluid
.
DataFeeder
(
place
=
place
,
feed_list
=
[
x
])
data
=
[]
data
.
append
((
np
.
random
.
randint
(
10
,
size
=
[
13
]).
astype
(
'float32'
)))
exe
.
run
(
fluid
.
default_startup_program
())
local_out
=
exe
.
run
(
main
,
local_out
=
exe
.
run
(
main
,
feed
=
feeder
.
feed
([
data
]),
fetch_list
=
[
fetch_list
=
[
var
,
var1
,
var2
,
var3
,
var4
,
var5
,
var6
,
var
,
var1
,
var2
,
var3
,
var4
,
var5
,
var6
,
var7
,
var8
var7
,
var8
,
var9
,
var10
,
var11
])
])
self
.
assertTrue
((
np
.
array
(
local_out
[
1
])
==
np
.
array
(
tensor_array
[
self
.
assertTrue
((
np
.
array
(
local_out
[
1
])
==
np
.
array
(
tensor_array
[
...
@@ -122,38 +134,16 @@ class TestVariable(unittest.TestCase):
...
@@ -122,38 +134,16 @@ class TestVariable(unittest.TestCase):
1
,
...,
1
:])).
all
())
1
,
...,
1
:])).
all
())
self
.
assertTrue
((
np
.
array
(
local_out
[
8
])
==
np
.
array
(
tensor_array
[
self
.
assertTrue
((
np
.
array
(
local_out
[
8
])
==
np
.
array
(
tensor_array
[
1
,
...])).
all
())
1
,
...])).
all
())
self
.
assertEqual
(
local_out
[
9
].
shape
,
(
1
,
3
,
1
))
self
.
assertEqual
(
local_out
[
10
].
shape
,
(
3
,
3
,
1
))
self
.
assertEqual
(
local_out
[
11
].
shape
,
(
1
,
1
))
def
test_slice
(
self
):
def
test_slice
(
self
):
self
.
_test_slice
()
place
=
fluid
.
CPUPlace
()
self
.
_test_slice
(
place
)
class
TestVariableImperative
(
unittest
.
TestCase
):
def
_test_slice
(
self
):
b
=
default_main_program
().
current_block
()
w
=
b
.
create_var
(
dtype
=
"float64"
,
shape
=
[
784
,
100
,
100
],
lod_level
=
0
)
for
i
in
range
(
3
):
nw
=
w
[
i
]
self
.
assertEqual
([
1
,
100
,
100
],
nw
.
shape
)
nw
=
w
[:]
self
.
assertEqual
([
784
,
100
,
100
],
nw
.
shape
)
nw
=
w
[:,
:,
:]
self
.
assertEqual
([
784
,
100
,
100
],
nw
.
shape
)
nw
=
w
[::
2
,
::
2
,
:]
self
.
assertEqual
([
392
,
50
,
100
],
nw
.
shape
)
nw
=
w
[::
-
2
,
::
-
2
,
:]
self
.
assertEqual
([
392
,
50
,
100
],
nw
.
shape
)
nw
=
w
[
0
::
-
2
,
0
::
-
2
,
:]
self
.
assertEqual
([
1
,
1
,
100
],
nw
.
shape
)
def
test_slice
(
self
):
if
core
.
is_compiled_with_cuda
():
with
fluid
.
dygraph
.
guard
():
self
.
_test_slice
(
core
.
CUDAPlace
(
0
))
self
.
_test_slice
()
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录