Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
e5a0dc31
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2302
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看板
未验证
提交
e5a0dc31
编写于
3月 30, 2023
作者:
F
Feiyu Chan
提交者:
GitHub
3月 30, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
rename Scalar related utility functions(use CamelCase) (#52280)
上级
0f4229c5
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
52 addition
and
57 deletion
+52
-57
paddle/fluid/framework/attribute.cc
paddle/fluid/framework/attribute.cc
+8
-8
paddle/fluid/framework/attribute.h
paddle/fluid/framework/attribute.h
+4
-4
paddle/fluid/framework/attribute_test.cc
paddle/fluid/framework/attribute_test.cc
+38
-43
paddle/fluid/framework/op_desc.cc
paddle/fluid/framework/op_desc.cc
+2
-2
未找到文件。
paddle/fluid/framework/attribute.cc
浏览文件 @
e5a0dc31
...
...
@@ -130,13 +130,13 @@ Attribute GetAttrValue(const proto::OpDesc::Attr& attr_desc) {
}
case
proto
::
AttrType
::
SCALAR
:
{
return
make_scalar_from_p
roto
(
attr_desc
.
scalar
());
return
MakeScalarFromP
roto
(
attr_desc
.
scalar
());
}
case
proto
::
AttrType
::
SCALARS
:
{
std
::
vector
<
paddle
::
experimental
::
Scalar
>
val
(
attr_desc
.
scalars_size
());
for
(
int
i
=
0
;
i
<
attr_desc
.
scalars_size
();
++
i
)
{
val
[
i
]
=
make_scalar_from_p
roto
(
attr_desc
.
scalars
(
i
));
val
[
i
]
=
MakeScalarFromP
roto
(
attr_desc
.
scalars
(
i
));
}
return
val
;
}
...
...
@@ -170,7 +170,7 @@ Attribute GetAttrValue(const proto::VarDesc::Attr& attr_desc) {
return
paddle
::
blank
();
}
paddle
::
experimental
::
Scalar
make_scalar_from_p
roto
(
const
proto
::
Scalar
&
v
)
{
paddle
::
experimental
::
Scalar
MakeScalarFromP
roto
(
const
proto
::
Scalar
&
v
)
{
auto
data_type
=
v
.
type
();
switch
(
data_type
)
{
case
proto
::
Scalar_Type_BOOLEAN
:
...
...
@@ -192,7 +192,7 @@ paddle::experimental::Scalar make_scalar_from_proto(const proto::Scalar& v) {
return
paddle
::
experimental
::
Scalar
();
}
proto
::
Scalar
make_scalar_p
roto
(
const
paddle
::
experimental
::
Scalar
&
v
)
{
proto
::
Scalar
MakeScalarP
roto
(
const
paddle
::
experimental
::
Scalar
&
v
)
{
proto
::
Scalar
s
;
auto
data_type
=
v
.
dtype
();
switch
(
data_type
)
{
...
...
@@ -243,7 +243,7 @@ proto::Scalar make_scalar_proto(const paddle::experimental::Scalar& v) {
return
s
;
}
paddle
::
experimental
::
Scalar
make_scalar_from_a
ttribute
(
const
Attribute
&
v
)
{
paddle
::
experimental
::
Scalar
MakeScalarFromA
ttribute
(
const
Attribute
&
v
)
{
auto
attr_type
=
static_cast
<
proto
::
AttrType
>
(
v
.
index
()
-
1
);
switch
(
attr_type
)
{
case
proto
::
AttrType
::
SCALAR
:
...
...
@@ -266,7 +266,7 @@ paddle::experimental::Scalar make_scalar_from_attribute(const Attribute& v) {
}
}
std
::
vector
<
paddle
::
experimental
::
Scalar
>
make_scalars_from_a
ttribute
(
std
::
vector
<
paddle
::
experimental
::
Scalar
>
MakeScalarsFromA
ttribute
(
const
Attribute
&
v
)
{
auto
attr_type
=
static_cast
<
proto
::
AttrType
>
(
v
.
index
()
-
1
);
switch
(
attr_type
)
{
...
...
@@ -313,9 +313,9 @@ void CanonicalizeScalarAttrs(const proto::OpProto& op_proto,
continue
;
// VAR& VARS are not proper attribute
}
if
(
attr_type
==
proto
::
AttrType
::
SCALAR
)
{
it
->
second
=
Attribute
(
make_scalar_from_a
ttribute
(
it
->
second
));
it
->
second
=
Attribute
(
MakeScalarFromA
ttribute
(
it
->
second
));
}
else
if
(
attr_type
==
proto
::
AttrType
::
SCALARS
)
{
it
->
second
=
Attribute
(
make_scalars_from_a
ttribute
(
it
->
second
));
it
->
second
=
Attribute
(
MakeScalarsFromA
ttribute
(
it
->
second
));
}
}
}
...
...
paddle/fluid/framework/attribute.h
浏览文件 @
e5a0dc31
...
...
@@ -349,10 +349,10 @@ class AttrReader {
const
AttributeMap
*
default_attrs_
;
};
paddle
::
experimental
::
Scalar
make_scalar_from_p
roto
(
const
proto
::
Scalar
&
v
);
proto
::
Scalar
make_scalar_p
roto
(
const
paddle
::
experimental
::
Scalar
&
v
);
paddle
::
experimental
::
Scalar
make_scalar_from_a
ttribute
(
const
Attribute
&
v
);
std
::
vector
<
paddle
::
experimental
::
Scalar
>
make_scalars_from_a
ttribute
(
paddle
::
experimental
::
Scalar
MakeScalarFromP
roto
(
const
proto
::
Scalar
&
v
);
proto
::
Scalar
MakeScalarP
roto
(
const
paddle
::
experimental
::
Scalar
&
v
);
paddle
::
experimental
::
Scalar
MakeScalarFromA
ttribute
(
const
Attribute
&
v
);
std
::
vector
<
paddle
::
experimental
::
Scalar
>
MakeScalarsFromA
ttribute
(
const
Attribute
&
v
);
void
CanonicalizeScalarAttrs
(
const
proto
::
OpProto
&
op_proto
,
AttributeMap
*
attrs
);
...
...
paddle/fluid/framework/attribute_test.cc
浏览文件 @
e5a0dc31
...
...
@@ -200,91 +200,91 @@ TEST(Attribute, ProtoAttrToAttribute_scalar) {
paddle
::
experimental
::
Scalar
(
std
::
complex
<
double
>
(
42.1
,
42.1
));
auto
proto_scalar_bool
=
new
paddle
::
framework
::
proto
::
Scalar
;
*
proto_scalar_bool
=
paddle
::
framework
::
make_scalar_p
roto
(
s_bool
);
*
proto_scalar_bool
=
paddle
::
framework
::
MakeScalarP
roto
(
s_bool
);
proto_attr_scalar
.
set_allocated_scalar
(
proto_scalar_bool
);
ASSERT_EQ
(
AttrTypeID
(
paddle
::
framework
::
GetAttrValue
(
proto_attr_scalar
)),
paddle
::
framework
::
proto
::
SCALAR
);
auto
proto_scalar_int8
=
new
paddle
::
framework
::
proto
::
Scalar
;
*
proto_scalar_int8
=
paddle
::
framework
::
make_scalar_p
roto
(
s_int8
);
*
proto_scalar_int8
=
paddle
::
framework
::
MakeScalarP
roto
(
s_int8
);
proto_attr_scalar
.
set_allocated_scalar
(
proto_scalar_int8
);
ASSERT_EQ
(
AttrTypeID
(
paddle
::
framework
::
GetAttrValue
(
proto_attr_scalar
)),
paddle
::
framework
::
proto
::
SCALAR
);
auto
proto_scalar_int16
=
new
paddle
::
framework
::
proto
::
Scalar
;
*
proto_scalar_int16
=
paddle
::
framework
::
make_scalar_p
roto
(
s_int16
);
*
proto_scalar_int16
=
paddle
::
framework
::
MakeScalarP
roto
(
s_int16
);
proto_attr_scalar
.
set_allocated_scalar
(
proto_scalar_int16
);
ASSERT_EQ
(
AttrTypeID
(
paddle
::
framework
::
GetAttrValue
(
proto_attr_scalar
)),
paddle
::
framework
::
proto
::
SCALAR
);
auto
proto_scalar_int32
=
new
paddle
::
framework
::
proto
::
Scalar
;
*
proto_scalar_int32
=
paddle
::
framework
::
make_scalar_p
roto
(
s_int32
);
*
proto_scalar_int32
=
paddle
::
framework
::
MakeScalarP
roto
(
s_int32
);
proto_attr_scalar
.
set_allocated_scalar
(
proto_scalar_int32
);
ASSERT_EQ
(
AttrTypeID
(
paddle
::
framework
::
GetAttrValue
(
proto_attr_scalar
)),
paddle
::
framework
::
proto
::
SCALAR
);
auto
proto_scalar_int64
=
new
paddle
::
framework
::
proto
::
Scalar
;
*
proto_scalar_int64
=
paddle
::
framework
::
make_scalar_p
roto
(
s_int64
);
*
proto_scalar_int64
=
paddle
::
framework
::
MakeScalarP
roto
(
s_int64
);
proto_attr_scalar
.
set_allocated_scalar
(
proto_scalar_int64
);
ASSERT_EQ
(
AttrTypeID
(
paddle
::
framework
::
GetAttrValue
(
proto_attr_scalar
)),
paddle
::
framework
::
proto
::
SCALAR
);
auto
proto_scalar_uint8
=
new
paddle
::
framework
::
proto
::
Scalar
;
*
proto_scalar_uint8
=
paddle
::
framework
::
make_scalar_p
roto
(
s_uint8
);
*
proto_scalar_uint8
=
paddle
::
framework
::
MakeScalarP
roto
(
s_uint8
);
proto_attr_scalar
.
set_allocated_scalar
(
proto_scalar_uint8
);
ASSERT_EQ
(
AttrTypeID
(
paddle
::
framework
::
GetAttrValue
(
proto_attr_scalar
)),
paddle
::
framework
::
proto
::
SCALAR
);
auto
proto_scalar_uint16
=
new
paddle
::
framework
::
proto
::
Scalar
;
*
proto_scalar_uint16
=
paddle
::
framework
::
make_scalar_p
roto
(
s_uint16
);
*
proto_scalar_uint16
=
paddle
::
framework
::
MakeScalarP
roto
(
s_uint16
);
proto_attr_scalar
.
set_allocated_scalar
(
proto_scalar_uint16
);
ASSERT_EQ
(
AttrTypeID
(
paddle
::
framework
::
GetAttrValue
(
proto_attr_scalar
)),
paddle
::
framework
::
proto
::
SCALAR
);
auto
proto_scalar_uint32
=
new
paddle
::
framework
::
proto
::
Scalar
;
*
proto_scalar_uint32
=
paddle
::
framework
::
make_scalar_p
roto
(
s_uint32
);
*
proto_scalar_uint32
=
paddle
::
framework
::
MakeScalarP
roto
(
s_uint32
);
proto_attr_scalar
.
set_allocated_scalar
(
proto_scalar_uint32
);
ASSERT_EQ
(
AttrTypeID
(
paddle
::
framework
::
GetAttrValue
(
proto_attr_scalar
)),
paddle
::
framework
::
proto
::
SCALAR
);
auto
proto_scalar_uint64
=
new
paddle
::
framework
::
proto
::
Scalar
;
*
proto_scalar_uint64
=
paddle
::
framework
::
make_scalar_p
roto
(
s_uint64
);
*
proto_scalar_uint64
=
paddle
::
framework
::
MakeScalarP
roto
(
s_uint64
);
proto_attr_scalar
.
set_allocated_scalar
(
proto_scalar_uint64
);
ASSERT_EQ
(
AttrTypeID
(
paddle
::
framework
::
GetAttrValue
(
proto_attr_scalar
)),
paddle
::
framework
::
proto
::
SCALAR
);
auto
proto_scalar_float16
=
new
paddle
::
framework
::
proto
::
Scalar
;
*
proto_scalar_float16
=
paddle
::
framework
::
make_scalar_p
roto
(
s_float16
);
*
proto_scalar_float16
=
paddle
::
framework
::
MakeScalarP
roto
(
s_float16
);
proto_attr_scalar
.
set_allocated_scalar
(
proto_scalar_float16
);
ASSERT_EQ
(
AttrTypeID
(
paddle
::
framework
::
GetAttrValue
(
proto_attr_scalar
)),
paddle
::
framework
::
proto
::
SCALAR
);
auto
proto_scalar_bfloat16
=
new
paddle
::
framework
::
proto
::
Scalar
;
*
proto_scalar_bfloat16
=
paddle
::
framework
::
make_scalar_p
roto
(
s_bfloat16
);
*
proto_scalar_bfloat16
=
paddle
::
framework
::
MakeScalarP
roto
(
s_bfloat16
);
proto_attr_scalar
.
set_allocated_scalar
(
proto_scalar_bfloat16
);
ASSERT_EQ
(
AttrTypeID
(
paddle
::
framework
::
GetAttrValue
(
proto_attr_scalar
)),
paddle
::
framework
::
proto
::
SCALAR
);
auto
proto_scalar_float
=
new
paddle
::
framework
::
proto
::
Scalar
;
*
proto_scalar_float
=
paddle
::
framework
::
make_scalar_p
roto
(
s_float
);
*
proto_scalar_float
=
paddle
::
framework
::
MakeScalarP
roto
(
s_float
);
proto_attr_scalar
.
set_allocated_scalar
(
proto_scalar_float
);
ASSERT_EQ
(
AttrTypeID
(
paddle
::
framework
::
GetAttrValue
(
proto_attr_scalar
)),
paddle
::
framework
::
proto
::
SCALAR
);
auto
proto_scalar_double
=
new
paddle
::
framework
::
proto
::
Scalar
;
*
proto_scalar_double
=
paddle
::
framework
::
make_scalar_p
roto
(
s_double
);
*
proto_scalar_double
=
paddle
::
framework
::
MakeScalarP
roto
(
s_double
);
proto_attr_scalar
.
set_allocated_scalar
(
proto_scalar_double
);
ASSERT_EQ
(
AttrTypeID
(
paddle
::
framework
::
GetAttrValue
(
proto_attr_scalar
)),
paddle
::
framework
::
proto
::
SCALAR
);
auto
proto_scalar_cfloat
=
new
paddle
::
framework
::
proto
::
Scalar
;
*
proto_scalar_cfloat
=
paddle
::
framework
::
make_scalar_p
roto
(
s_cfloat
);
*
proto_scalar_cfloat
=
paddle
::
framework
::
MakeScalarP
roto
(
s_cfloat
);
proto_attr_scalar
.
set_allocated_scalar
(
proto_scalar_cfloat
);
ASSERT_EQ
(
AttrTypeID
(
paddle
::
framework
::
GetAttrValue
(
proto_attr_scalar
)),
paddle
::
framework
::
proto
::
SCALAR
);
auto
proto_scalar_cdouble
=
new
paddle
::
framework
::
proto
::
Scalar
;
*
proto_scalar_cdouble
=
paddle
::
framework
::
make_scalar_p
roto
(
s_cdouble
);
*
proto_scalar_cdouble
=
paddle
::
framework
::
MakeScalarP
roto
(
s_cdouble
);
proto_attr_scalar
.
set_allocated_scalar
(
proto_scalar_cdouble
);
ASSERT_EQ
(
AttrTypeID
(
paddle
::
framework
::
GetAttrValue
(
proto_attr_scalar
)),
paddle
::
framework
::
proto
::
SCALAR
);
...
...
@@ -302,7 +302,7 @@ TEST(Attribute, ProtoAttrToAttribute_scalars) {
std
::
vector
<
paddle
::
framework
::
proto
::
Scalar
>
proto_scalars
;
proto_scalars
.
reserve
(
scalars
.
size
());
for
(
const
auto
&
item
:
scalars
)
{
proto_scalars
.
emplace_back
(
paddle
::
framework
::
make_scalar_p
roto
(
item
));
proto_scalars
.
emplace_back
(
paddle
::
framework
::
MakeScalarP
roto
(
item
));
}
paddle
::
framework
::
VectorToRepeated
(
proto_scalars
,
proto_attr_scalars
.
mutable_scalars
());
...
...
@@ -310,8 +310,8 @@ TEST(Attribute, ProtoAttrToAttribute_scalars) {
paddle
::
framework
::
proto
::
SCALARS
);
}
TEST
(
Attribute
,
make_scalar_from_a
ttribute
)
{
using
paddle
::
framework
::
make_scalar_from_a
ttribute
;
TEST
(
Attribute
,
MakeScalarFromA
ttribute
)
{
using
paddle
::
framework
::
MakeScalarFromA
ttribute
;
auto
s_bool
=
true
;
auto
s_int32
=
static_cast
<
int32_t
>
(
42.1
);
auto
s_int64
=
static_cast
<
int64_t
>
(
42.1
);
...
...
@@ -321,22 +321,22 @@ TEST(Attribute, make_scalar_from_attribute) {
auto
s_scalar
=
paddle
::
experimental
::
Scalar
(
42.1
);
ASSERT_EQ
(
make_scalar_from_a
ttribute
(
paddle
::
framework
::
Attribute
(
s_bool
)),
ASSERT_EQ
(
MakeScalarFromA
ttribute
(
paddle
::
framework
::
Attribute
(
s_bool
)),
paddle
::
experimental
::
Scalar
(
s_bool
));
ASSERT_EQ
(
make_scalar_from_a
ttribute
(
paddle
::
framework
::
Attribute
(
s_int32
)),
ASSERT_EQ
(
MakeScalarFromA
ttribute
(
paddle
::
framework
::
Attribute
(
s_int32
)),
paddle
::
experimental
::
Scalar
(
s_int32
));
ASSERT_EQ
(
make_scalar_from_a
ttribute
(
paddle
::
framework
::
Attribute
(
s_int64
)),
ASSERT_EQ
(
MakeScalarFromA
ttribute
(
paddle
::
framework
::
Attribute
(
s_int64
)),
paddle
::
experimental
::
Scalar
(
s_int64
));
ASSERT_EQ
(
make_scalar_from_a
ttribute
(
paddle
::
framework
::
Attribute
(
s_float
)),
ASSERT_EQ
(
MakeScalarFromA
ttribute
(
paddle
::
framework
::
Attribute
(
s_float
)),
paddle
::
experimental
::
Scalar
(
s_float
));
ASSERT_EQ
(
make_scalar_from_a
ttribute
(
paddle
::
framework
::
Attribute
(
s_double
)),
ASSERT_EQ
(
MakeScalarFromA
ttribute
(
paddle
::
framework
::
Attribute
(
s_double
)),
paddle
::
experimental
::
Scalar
(
s_double
));
ASSERT_EQ
(
make_scalar_from_a
ttribute
(
paddle
::
framework
::
Attribute
(
s_scalar
)),
ASSERT_EQ
(
MakeScalarFromA
ttribute
(
paddle
::
framework
::
Attribute
(
s_scalar
)),
s_scalar
);
}
TEST
(
Attribute
,
make_scalars_from_a
ttribute
)
{
using
paddle
::
framework
::
make_scalars_from_a
ttribute
;
TEST
(
Attribute
,
MakeScalarsFromA
ttribute
)
{
using
paddle
::
framework
::
MakeScalarsFromA
ttribute
;
std
::
vector
<
bool
>
v_bool
(
4
,
true
);
std
::
vector
<
int
>
v_int
(
4
,
42
);
std
::
vector
<
int64_t
>
v_int64
(
4
,
42
);
...
...
@@ -345,23 +345,18 @@ TEST(Attribute, make_scalars_from_attribute) {
std
::
vector
<
paddle
::
experimental
::
Scalar
>
v_scalar
(
4
,
paddle
::
experimental
::
Scalar
(
std
::
complex
<
float
>
(
42.1
,
42.1
)));
ASSERT_EQ
(
make_scalars_from_attribute
(
paddle
::
framework
::
Attribute
(
v_bool
))[
0
],
paddle
::
experimental
::
Scalar
(
v_bool
[
0
]));
ASSERT_EQ
(
MakeScalarsFromAttribute
(
paddle
::
framework
::
Attribute
(
v_bool
))[
0
],
paddle
::
experimental
::
Scalar
(
v_bool
[
0
]));
ASSERT_EQ
(
make_scalars_from_a
ttribute
(
paddle
::
framework
::
Attribute
(
v_int
))[
0
],
ASSERT_EQ
(
MakeScalarsFromA
ttribute
(
paddle
::
framework
::
Attribute
(
v_int
))[
0
],
paddle
::
experimental
::
Scalar
(
v_int
[
0
]));
ASSERT_EQ
(
make_scalars_from_attribute
(
paddle
::
framework
::
Attribute
(
v_int64
))[
0
],
paddle
::
experimental
::
Scalar
(
v_int64
[
0
]));
ASSERT_EQ
(
make_scalars_from_attribute
(
paddle
::
framework
::
Attribute
(
v_float
))[
0
],
paddle
::
experimental
::
Scalar
(
v_float
[
0
]));
ASSERT_EQ
(
make_scalars_from_attribute
(
paddle
::
framework
::
Attribute
(
v_double
))[
0
],
paddle
::
experimental
::
Scalar
(
v_double
[
0
]));
ASSERT_EQ
(
make_scalars_from_attribute
(
paddle
::
framework
::
Attribute
(
v_scalar
))[
0
],
v_scalar
[
0
]);
ASSERT_EQ
(
MakeScalarsFromAttribute
(
paddle
::
framework
::
Attribute
(
v_int64
))[
0
],
paddle
::
experimental
::
Scalar
(
v_int64
[
0
]));
ASSERT_EQ
(
MakeScalarsFromAttribute
(
paddle
::
framework
::
Attribute
(
v_float
))[
0
],
paddle
::
experimental
::
Scalar
(
v_float
[
0
]));
ASSERT_EQ
(
MakeScalarsFromAttribute
(
paddle
::
framework
::
Attribute
(
v_double
))[
0
],
paddle
::
experimental
::
Scalar
(
v_double
[
0
]));
ASSERT_EQ
(
MakeScalarsFromAttribute
(
paddle
::
framework
::
Attribute
(
v_scalar
))[
0
],
v_scalar
[
0
]);
}
paddle/fluid/framework/op_desc.cc
浏览文件 @
e5a0dc31
...
...
@@ -935,7 +935,7 @@ struct SetAttrDescVisitor {
void
operator
()(
const
std
::
string
&
v
)
const
{
attr_
->
set_s
(
v
);
}
void
operator
()(
const
paddle
::
experimental
::
Scalar
&
v
)
const
{
auto
*
s
=
new
proto
::
Scalar
;
*
s
=
make_scalar_p
roto
(
v
);
*
s
=
MakeScalarP
roto
(
v
);
attr_
->
set_allocated_scalar
(
s
);
}
...
...
@@ -995,7 +995,7 @@ struct SetAttrDescVisitor {
std
::
vector
<
proto
::
Scalar
>
scalars
;
scalars
.
reserve
(
v
.
size
());
for
(
const
auto
&
item
:
v
)
{
scalars
.
emplace_back
(
make_scalar_p
roto
(
item
));
scalars
.
emplace_back
(
MakeScalarP
roto
(
item
));
}
VectorToRepeated
(
scalars
,
attr_
->
mutable_scalars
());
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录