Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
马赛克医院
Paddle
提交
e84b2e9b
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,发现更多精彩内容 >>
未验证
提交
e84b2e9b
编写于
8月 16, 2021
作者:
Z
Zhanlue Yang
提交者:
GitHub
8月 16, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add bcast semantics checks at C++ level to BroadcastTensorsOp (#34874)
上级
28279f6f
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
51 addition
and
0 deletion
+51
-0
paddle/fluid/operators/broadcast_tensors_op.cc
paddle/fluid/operators/broadcast_tensors_op.cc
+9
-0
python/paddle/fluid/tests/unittests/test_broadcast_tensors_op.py
...paddle/fluid/tests/unittests/test_broadcast_tensors_op.py
+42
-0
未找到文件。
paddle/fluid/operators/broadcast_tensors_op.cc
浏览文件 @
e84b2e9b
...
...
@@ -38,6 +38,7 @@ class BroadcastTensorsOp : public framework::OperatorWithKernel {
int
target_rank
=
0
;
const
auto
&
input_dims
=
ctx
->
GetInputsDim
(
"X"
);
// 1. Find Output rank = max(Inputs rank)
for
(
const
auto
&
input_ddim
:
input_dims
)
{
target_rank
=
std
::
max
(
target_rank
,
input_ddim
.
size
());
...
...
@@ -64,6 +65,14 @@ class BroadcastTensorsOp : public framework::OperatorWithKernel {
dim_size
=
input_ddim
[
axis
];
}
if
(
target_dim_size
!=
1
&&
dim_size
!=
1
&&
target_dim_size
!=
dim_size
)
{
PADDLE_THROW
(
platform
::
errors
::
InvalidArgument
(
"BroadcastTensorsOp inputs does not satisfy bcast semantics,"
"Please check axis = %d in reverse order"
,
index
));
}
// We performed bcast semantics check at python level
// So input tensors should all have legal shape
target_dim_size
=
std
::
max
(
target_dim_size
,
dim_size
);
...
...
python/paddle/fluid/tests/unittests/test_broadcast_tensors_op.py
浏览文件 @
e84b2e9b
...
...
@@ -192,5 +192,47 @@ class TestRaiseBroadcastTensorsError(unittest.TestCase):
self
.
assertRaises
(
TypeError
,
test_bcast_semantics
)
class
TestRaiseBroadcastTensorsErrorDyGraph
(
unittest
.
TestCase
):
def
test_errors
(
self
):
def
test_type
():
inputs
=
[
paddle
.
to_tensor
(
np
.
ones
(
shape
=
[
1
,
1
,
1
,
1
],
dtype
=
'float32'
,
name
=
"x4"
)),
paddle
.
to_tensor
(
np
.
ones
(
shape
=
[
1
,
4
,
1
,
1
],
dtype
=
'float64'
,
name
=
"x5"
))
]
paddle
.
broadcast_tensors
(
inputs
)
def
test_dtype
():
inputs
=
[
paddle
.
to_tensor
(
np
.
ones
(
shape
=
[
1
,
1
,
1
,
1
],
dtype
=
'int8'
,
name
=
"x6"
)),
paddle
.
to_tensor
(
np
.
ones
(
shape
=
[
1
,
4
,
1
,
1
],
dtype
=
'int8'
,
name
=
"x7"
))
]
paddle
.
broadcast_tensors
(
inputs
)
def
test_bcast_semantics
():
inputs
=
[
paddle
.
to_tensor
(
np
.
ones
(
shape
=
[
1
,
3
,
1
,
1
],
dtype
=
'float32'
,
name
=
"x9"
)),
paddle
.
to_tensor
(
np
.
ones
(
shape
=
[
1
,
8
,
1
,
1
],
dtype
=
'float32'
,
name
=
"x10"
))
]
paddle
.
broadcast_tensors
(
inputs
)
paddle
.
disable_static
()
self
.
assertRaises
(
TypeError
,
test_type
)
self
.
assertRaises
(
TypeError
,
test_dtype
)
self
.
assertRaises
(
TypeError
,
test_bcast_semantics
)
paddle
.
enable_static
()
if
__name__
==
'__main__'
:
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录