Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
马赛克医院
Paddle
提交
57d4288a
P
Paddle
项目概览
马赛克医院
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
57d4288a
编写于
3月 30, 2021
作者:
L
liym27
提交者:
GitHub
3月 30, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[dynamic setitem] Fix bug of dynamic setitem: Decerease axes to do right broadcast (#31960)
上级
0fa6c8a3
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
32 addition
and
10 deletion
+32
-10
paddle/fluid/pybind/imperative.cc
paddle/fluid/pybind/imperative.cc
+8
-6
python/paddle/fluid/tests/unittests/test_set_value_op.py
python/paddle/fluid/tests/unittests/test_set_value_op.py
+24
-4
未找到文件。
paddle/fluid/pybind/imperative.cc
浏览文件 @
57d4288a
...
...
@@ -611,15 +611,17 @@ void BindImperative(py::module *m_ptr) {
// TODO(liym27): Try not to call TensorToPyArray because it always
// copys data to cpu place, which reduces performance.
if
(
parse_index
&&
value_is_tensor
)
{
std
::
vector
<
int
>
axes
,
starts
,
ends
,
steps
,
decrease_ax
i
s
,
std
::
vector
<
int
>
axes
,
starts
,
ends
,
steps
,
decrease_ax
e
s
,
infer_flags
;
ParseIndexingSlice
(
self_tensor
,
index_ptr
,
&
axes
,
&
starts
,
&
ends
,
&
steps
,
&
decrease_ax
i
s
,
&
infer_flags
);
&
steps
,
&
decrease_ax
e
s
,
&
infer_flags
);
framework
::
AttributeMap
attrs
=
{{
"axes"
,
axes
},
{
"starts"
,
starts
},
{
"ends"
,
ends
},
{
"steps"
,
steps
}};
framework
::
AttributeMap
attrs
=
{
{
"axes"
,
axes
},
{
"starts"
,
starts
},
{
"ends"
,
ends
},
{
"steps"
,
steps
},
{
"decrease_axes"
,
decrease_axes
}};
imperative
::
NameVarBaseMap
ins
=
{{
"Input"
,
{
self
}}};
imperative
::
NameVarBaseMap
outs
=
{{
"Out"
,
{
self
}}};
...
...
python/paddle/fluid/tests/unittests/test_set_value_op.py
浏览文件 @
57d4288a
...
...
@@ -48,18 +48,37 @@ class TestSetValueBase(unittest.TestCase):
class
TestSetValueApi
(
TestSetValueBase
):
def
test_api
(
self
):
def
_run_static
(
self
):
paddle
.
enable_static
()
with
paddle
.
static
.
program_guard
(
self
.
program
):
x
=
paddle
.
ones
(
shape
=
self
.
shape
,
dtype
=
self
.
dtype
)
self
.
_call_setitem
(
x
)
exe
=
paddle
.
static
.
Executor
(
paddle
.
CPUPlace
())
out
=
exe
.
run
(
self
.
program
,
fetch_list
=
[
x
])
paddle
.
disable_static
()
return
out
def
_run_dynamic
(
self
):
paddle
.
disable_static
()
x
=
paddle
.
ones
(
shape
=
self
.
shape
,
dtype
=
self
.
dtype
)
self
.
_call_setitem
(
x
)
out
=
x
.
numpy
()
paddle
.
enable_static
()
return
out
def
test_api
(
self
):
static_out
=
self
.
_run_static
()
dynamic_out
=
self
.
_run_dynamic
()
self
.
_get_answer
()
error_msg
=
"
\n
In {} mode:
\n
Expected res =
\n
{},
\n\n
but received :
\n
{}"
self
.
assertTrue
(
(
self
.
data
==
out
).
all
(),
msg
=
"
\n
Expected res =
\n
{},
\n\n
but received :
\n
{}"
.
format
(
self
.
data
,
out
))
(
self
.
data
==
static_out
).
all
(),
msg
=
error_msg
.
format
(
"static"
,
self
.
data
,
static_out
))
self
.
assertTrue
(
(
self
.
data
==
dynamic_out
).
all
(),
msg
=
error_msg
.
format
(
"dynamic"
,
self
.
data
,
dynamic_out
))
# 1. Test different type of item: int, Python slice, Paddle Tensor
...
...
@@ -748,6 +767,7 @@ class TestError(TestSetValueBase):
exe
.
run
(
program
)
def
test_error
(
self
):
paddle
.
enable_static
()
with
paddle
.
static
.
program_guard
(
self
.
program
):
self
.
_value_type_error
()
self
.
_dtype_error
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录