Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
a039fd7b
P
Paddle
项目概览
机器未来
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
a039fd7b
编写于
6月 09, 2021
作者:
L
liym27
提交者:
GitHub
6月 09, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[Static getitem] Support static Variable getitem for Ellipsis index (#32876)
上级
741811e0
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
23 addition
and
0 deletion
+23
-0
python/paddle/fluid/tests/unittests/test_variable.py
python/paddle/fluid/tests/unittests/test_variable.py
+22
-0
python/paddle/fluid/variable_index.py
python/paddle/fluid/variable_index.py
+1
-0
未找到文件。
python/paddle/fluid/tests/unittests/test_variable.py
浏览文件 @
a039fd7b
...
@@ -17,6 +17,7 @@ from __future__ import print_function
...
@@ -17,6 +17,7 @@ from __future__ import print_function
import
unittest
import
unittest
import
paddle
import
paddle
from
paddle.fluid.framework
import
default_main_program
,
Program
,
convert_np_dtype_to_dtype_
,
in_dygraph_mode
from
paddle.fluid.framework
import
default_main_program
,
Program
,
convert_np_dtype_to_dtype_
,
in_dygraph_mode
import
paddle
import
paddle.fluid
as
fluid
import
paddle.fluid
as
fluid
import
paddle.fluid.layers
as
layers
import
paddle.fluid.layers
as
layers
import
paddle.fluid.core
as
core
import
paddle.fluid.core
as
core
...
@@ -218,6 +219,26 @@ class TestVariable(unittest.TestCase):
...
@@ -218,6 +219,26 @@ class TestVariable(unittest.TestCase):
self
.
assertTrue
((
result
[
2
]
==
expected
[
2
]).
all
())
self
.
assertTrue
((
result
[
2
]
==
expected
[
2
]).
all
())
self
.
assertTrue
((
result
[
3
]
==
expected
[
3
]).
all
())
self
.
assertTrue
((
result
[
3
]
==
expected
[
3
]).
all
())
def
_test_slice_index_ellipsis
(
self
,
place
):
data
=
np
.
random
.
rand
(
2
,
3
,
4
).
astype
(
"float32"
)
prog
=
paddle
.
static
.
Program
()
with
paddle
.
static
.
program_guard
(
prog
):
x
=
paddle
.
assign
(
data
)
out1
=
x
[
0
:,
...,
1
:]
out2
=
x
[
0
:,
...]
out3
=
x
[...,
1
:]
out4
=
x
[...]
exe
=
paddle
.
static
.
Executor
(
place
)
result
=
exe
.
run
(
prog
,
fetch_list
=
[
out1
,
out2
,
out3
,
out4
])
expected
=
[
data
[
0
:,
...,
1
:],
data
[
0
:,
...],
data
[...,
1
:],
data
[...]]
self
.
assertTrue
((
result
[
0
]
==
expected
[
0
]).
all
())
self
.
assertTrue
((
result
[
1
]
==
expected
[
1
]).
all
())
self
.
assertTrue
((
result
[
2
]
==
expected
[
2
]).
all
())
self
.
assertTrue
((
result
[
3
]
==
expected
[
3
]).
all
())
with
self
.
assertRaises
(
IndexError
):
with
self
.
assertRaises
(
IndexError
):
res
=
x
[[
1
,
0
],
[
0
,
0
]]
res
=
x
[[
1
,
0
],
[
0
,
0
]]
...
@@ -233,6 +254,7 @@ class TestVariable(unittest.TestCase):
...
@@ -233,6 +254,7 @@ class TestVariable(unittest.TestCase):
self
.
_test_slice
(
place
)
self
.
_test_slice
(
place
)
self
.
_test_slice_index_tensor
(
place
)
self
.
_test_slice_index_tensor
(
place
)
self
.
_test_slice_index_list
(
place
)
self
.
_test_slice_index_list
(
place
)
self
.
_test_slice_index_ellipsis
(
place
)
def
_tostring
(
self
):
def
_tostring
(
self
):
b
=
default_main_program
().
current_block
()
b
=
default_main_program
().
current_block
()
...
...
python/paddle/fluid/variable_index.py
浏览文件 @
a039fd7b
...
@@ -112,6 +112,7 @@ def _getitem_impl_(var, item):
...
@@ -112,6 +112,7 @@ def _getitem_impl_(var, item):
use_strided_slice
=
False
use_strided_slice
=
False
item
,
none_axes
=
replace_none
(
item
)
item
,
none_axes
=
replace_none
(
item
)
item
=
replace_ellipsis
(
var
,
item
)
for
dim
,
slice_item
in
enumerate
(
item
):
for
dim
,
slice_item
in
enumerate
(
item
):
if
is_integer_or_scalar_tensor
(
slice_item
):
if
is_integer_or_scalar_tensor
(
slice_item
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录