Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
3519c630
P
PaddleDetection
项目概览
PaddlePaddle
/
PaddleDetection
1 年多 前同步成功
通知
696
Star
11112
Fork
2696
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
184
列表
看板
标记
里程碑
合并请求
40
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
184
Issue
184
列表
看板
标记
里程碑
合并请求
40
合并请求
40
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
3519c630
编写于
3月 09, 2017
作者:
L
livc
提交者:
Yu Yang
3月 09, 2017
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
complete some functions of c-api.
上级
97c64254
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
102 addition
and
10 deletion
+102
-10
paddle/capi/Arguments.cpp
paddle/capi/Arguments.cpp
+37
-5
paddle/capi/Vector.cpp
paddle/capi/Vector.cpp
+20
-3
paddle/capi/tests/test_Arguments.cpp
paddle/capi/tests/test_Arguments.cpp
+36
-0
paddle/capi/tests/test_Vector.cpp
paddle/capi/tests/test_Vector.cpp
+9
-2
未找到文件。
paddle/capi/Arguments.cpp
浏览文件 @
3519c630
...
...
@@ -75,34 +75,66 @@ int PDArgsGetIds(PD_Arguments args, uint64_t ID, PD_IVector ids) {
int
PDArgsSetIds
(
PD_Arguments
args
,
uint64_t
ID
,
PD_IVector
ids
)
{
//! TODO(lizhao): Complete this method.
return
kPD_UNDEFINED_ERROR
;
if
(
args
==
nullptr
||
ids
==
nullptr
)
return
kPD_NULLPTR
;
auto
iv
=
paddle
::
capi
::
cast
<
paddle
::
capi
::
CIVector
>
(
ids
);
if
(
iv
->
vec
==
nullptr
)
return
kPD_NULLPTR
;
auto
a
=
castArg
(
args
);
if
(
ID
>=
a
->
args
.
size
())
return
kPD_OUT_OF_RANGE
;
a
->
args
[
ID
].
ids
=
iv
->
vec
;
return
kPD_NO_ERROR
;
}
int
PDArgsSetSequenceStartPos
(
PD_Arguments
args
,
uint64_t
ID
,
PD_IVector
seqPos
)
{
//! TODO(lizhao): Complete this method.
return
kPD_UNDEFINED_ERROR
;
if
(
args
==
nullptr
||
seqPos
==
nullptr
)
return
kPD_NULLPTR
;
auto
iv
=
paddle
::
capi
::
cast
<
paddle
::
capi
::
CIVector
>
(
seqPos
);
if
(
iv
->
vec
==
nullptr
)
return
kPD_NULLPTR
;
auto
a
=
castArg
(
args
);
if
(
ID
>=
a
->
args
.
size
())
return
kPD_OUT_OF_RANGE
;
a
->
args
[
ID
].
sequenceStartPositions
=
std
::
make_shared
<
paddle
::
ICpuGpuVector
>
(
iv
->
vec
);
return
kPD_NO_ERROR
;
}
int
PDArgsSetSubSequenceStartPos
(
PD_Arguments
args
,
uint64_t
ID
,
PD_IVector
subSeqPos
)
{
//! TODO(lizhao): Complete this method.
return
kPD_UNDEFINED_ERROR
;
if
(
args
==
nullptr
||
subSeqPos
==
nullptr
)
return
kPD_NULLPTR
;
auto
iv
=
paddle
::
capi
::
cast
<
paddle
::
capi
::
CIVector
>
(
subSeqPos
);
if
(
iv
->
vec
==
nullptr
)
return
kPD_NULLPTR
;
auto
a
=
castArg
(
args
);
if
(
ID
>=
a
->
args
.
size
())
return
kPD_OUT_OF_RANGE
;
a
->
args
[
ID
].
sequenceStartPositions
=
std
::
make_shared
<
paddle
::
ICpuGpuVector
>
(
iv
->
vec
);
return
kPD_NO_ERROR
;
}
int
PDArgsGetSequenceStartPos
(
PD_Arguments
args
,
uint64_t
ID
,
PD_IVector
seqPos
)
{
//! TODO(lizhao): Complete this method.
return
kPD_UNDEFINED_ERROR
;
if
(
args
==
nullptr
||
seqPos
==
nullptr
)
return
kPD_NULLPTR
;
auto
iv
=
castIVec
(
seqPos
);
auto
a
=
castArg
(
args
);
if
(
ID
>=
a
->
args
.
size
())
return
kPD_OUT_OF_RANGE
;
std
::
make_shared
<
paddle
::
ICpuGpuVector
>
(
iv
->
vec
)
=
a
->
args
[
ID
].
sequenceStartPositions
;
return
kPD_NO_ERROR
;
}
int
PDArgsGetSubSequenceStartPos
(
PD_Arguments
args
,
uint64_t
ID
,
PD_IVector
subSeqPos
)
{
//! TODO(lizhao): Complete this method.
return
kPD_UNDEFINED_ERROR
;
if
(
args
==
nullptr
||
subSeqPos
==
nullptr
)
return
kPD_NULLPTR
;
auto
iv
=
castIVec
(
subSeqPos
);
auto
a
=
castArg
(
args
);
if
(
ID
>=
a
->
args
.
size
())
return
kPD_OUT_OF_RANGE
;
std
::
make_shared
<
paddle
::
ICpuGpuVector
>
(
iv
->
vec
)
=
a
->
args
[
ID
].
sequenceStartPositions
;
return
kPD_NO_ERROR
;
}
}
paddle/capi/Vector.cpp
浏览文件 @
3519c630
...
...
@@ -28,7 +28,16 @@ int PDIVecCreateNone(PD_IVector* ivec) {
int
PDIVectorCreate
(
PD_IVector
*
ivec
,
int
*
array
,
uint64_t
size
,
bool
copy
)
{
//! TODO(lizhao): Complete this method.
return
kPD_UNDEFINED_ERROR
;
if
(
ivec
==
nullptr
)
return
kPD_NULLPTR
;
auto
ptr
=
new
paddle
::
capi
::
CIVector
();
if
(
copy
)
{
ptr
->
vec
=
paddle
::
IVector
::
create
(
size
,
false
);
ptr
->
vec
->
copyFrom
(
array
,
size
);
}
else
{
ptr
->
vec
=
paddle
::
IVector
::
create
(
array
,
size
,
false
);
}
*
ivec
=
ptr
;
return
kPD_NO_ERROR
;
}
int
PDIVecDestroy
(
PD_IVector
ivec
)
{
...
...
@@ -47,11 +56,19 @@ int PDIVectorGet(PD_IVector ivec, int** buffer) {
int
PDIVectorResize
(
PD_IVector
ivec
,
uint64_t
size
)
{
//! TODO(lizhao): Complete this method.
return
kPD_UNDEFINED_ERROR
;
if
(
ivec
==
nullptr
)
return
kPD_NULLPTR
;
auto
v
=
cast
<
paddle
::
capi
::
CIVector
>
(
ivec
);
if
(
v
->
vec
==
nullptr
)
return
kPD_NULLPTR
;
v
->
vec
->
resize
(
size
);
return
kPD_NO_ERROR
;
}
int
PDIVectorGetSize
(
PD_IVector
ivec
,
uint64_t
*
size
)
{
//! TODO(lizhao): Complete this method.
return
kPD_UNDEFINED_ERROR
;
if
(
ivec
==
nullptr
)
return
kPD_NULLPTR
;
auto
v
=
cast
<
paddle
::
capi
::
CIVector
>
(
ivec
);
if
(
v
->
vec
==
nullptr
)
return
kPD_NULLPTR
;
*
size
=
v
->
vec
->
getSize
();
return
kPD_NO_ERROR
;
}
}
paddle/capi/tests/test_Arguments.cpp
浏览文件 @
3519c630
...
...
@@ -70,3 +70,39 @@ TEST(CAPIArguments, value) {
ASSERT_EQ
(
kPD_NO_ERROR
,
PDMatDestroy
(
mat
));
ASSERT_EQ
(
kPD_NO_ERROR
,
PDArgsDestroy
(
args
));
}
TEST
(
CAPIArguments
,
ids
)
{
PD_Arguments
args
;
ASSERT_EQ
(
kPD_NO_ERROR
,
PDArgsCreateNone
(
&
args
));
ASSERT_EQ
(
kPD_NO_ERROR
,
PDArgsResize
(
args
,
1
));
PD_IVector
ivec
;
int
array
[
3
]
=
{
1
,
2
,
3
};
ASSERT_EQ
(
kPD_NO_ERROR
,
PDIVectorCreate
(
&
ivec
,
array
,
3
,
true
));
ASSERT_EQ
(
kPD_NO_ERROR
,
PDArgsSetIds
(
args
,
0
,
ivec
));
PD_IVector
val
;
ASSERT_EQ
(
kPD_NO_ERROR
,
PDIVecCreateNone
(
&
val
));
ASSERT_EQ
(
kPD_NO_ERROR
,
PDArgsGetIds
(
args
,
0
,
val
));
ASSERT_EQ
(
kPD_NO_ERROR
,
PDIVecDestroy
(
ivec
));
ASSERT_EQ
(
kPD_NO_ERROR
,
PDIVecDestroy
(
val
));
ASSERT_EQ
(
kPD_NO_ERROR
,
PDArgsDestroy
(
args
));
}
TEST
(
CAPIArguments
,
Sequence
)
{
PD_Arguments
args
;
ASSERT_EQ
(
kPD_NO_ERROR
,
PDArgsCreateNone
(
&
args
));
ASSERT_EQ
(
kPD_NO_ERROR
,
PDArgsResize
(
args
,
1
));
PD_IVector
ivec
;
int
array
[
3
]
=
{
1
,
2
,
3
};
ASSERT_EQ
(
kPD_NO_ERROR
,
PDIVectorCreate
(
&
ivec
,
array
,
3
,
true
));
ASSERT_EQ
(
kPD_NO_ERROR
,
PDArgsSetSequenceStartPos
(
args
,
0
,
ivec
));
PD_IVector
val
;
ASSERT_EQ
(
kPD_NO_ERROR
,
PDIVecCreateNone
(
&
val
));
ASSERT_EQ
(
kPD_NO_ERROR
,
PDArgsGetSequenceStartPos
(
args
,
0
,
val
));
ASSERT_EQ
(
kPD_NO_ERROR
,
PDIVecDestroy
(
ivec
));
ASSERT_EQ
(
kPD_NO_ERROR
,
PDIVecDestroy
(
val
));
ASSERT_EQ
(
kPD_NO_ERROR
,
PDArgsDestroy
(
args
));
}
paddle/capi/tests/test_Vector.cpp
浏览文件 @
3519c630
...
...
@@ -17,10 +17,17 @@ limitations under the License. */
TEST
(
CAPIVector
,
create
)
{
PD_IVector
vec
;
ASSERT_EQ
(
kPD_NO_ERROR
,
PDIVecCreateNone
(
&
vec
));
int
array
[
3
]
=
{
1
,
2
,
3
};
ASSERT_EQ
(
kPD_NO_ERROR
,
PDIVectorCreate
(
&
vec
,
array
,
3
,
true
));
ASSERT_EQ
(
kPD_NO_ERROR
,
PDIVectorCreate
(
&
vec
,
array
,
3
,
false
));
ASSERT_EQ
(
kPD_NO_ERROR
,
PDIVectorResize
(
vec
,
1000
));
uint64_t
size
;
ASSERT_EQ
(
kPD_NO_ERROR
,
PDIVectorGetSize
(
vec
,
&
size
));
ASSERT_EQ
(
1000
,
size
);
ASSERT_EQ
(
kPD_NO_ERROR
,
PDIVecDestroy
(
vec
));
}
TEST
(
CAPIVector
,
createNone
)
{
PD_IVector
vec
;
ASSERT_EQ
(
kPD_NO_ERROR
,
PDIVecCreateNone
(
&
vec
));
ASSERT_EQ
(
kPD_NO_ERROR
,
PDIVecDestroy
(
vec
));
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录