提交 5a9987a3 编写于 作者: Y Yu Yang

Fix bugs in lizhao's code

上级 d34322e1
......@@ -87,7 +87,6 @@ int PDArgsSetIds(PD_Arguments args, uint64_t ID, PD_IVector ids) {
int PDArgsSetSequenceStartPos(PD_Arguments args,
uint64_t ID,
PD_IVector seqPos) {
//! TODO(lizhao): Complete this method.
if (args == nullptr || seqPos == nullptr) return kPD_NULLPTR;
auto iv = paddle::capi::cast<paddle::capi::CIVector>(seqPos);
if (iv->vec == nullptr) return kPD_NULLPTR;
......@@ -101,13 +100,12 @@ int PDArgsSetSequenceStartPos(PD_Arguments args,
int PDArgsSetSubSequenceStartPos(PD_Arguments args,
uint64_t ID,
PD_IVector subSeqPos) {
//! TODO(lizhao): Complete this method.
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 =
a->args[ID].subSequenceStartPositions =
std::make_shared<paddle::ICpuGpuVector>(iv->vec);
return kPD_NO_ERROR;
}
......@@ -115,26 +113,24 @@ int PDArgsSetSubSequenceStartPos(PD_Arguments args,
int PDArgsGetSequenceStartPos(PD_Arguments args,
uint64_t ID,
PD_IVector seqPos) {
//! TODO(lizhao): Complete this method.
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;
paddle::Argument& arg = a->args[ID];
iv->vec = arg.sequenceStartPositions->getMutableVector(false);
return kPD_NO_ERROR;
}
int PDArgsGetSubSequenceStartPos(PD_Arguments args,
uint64_t ID,
PD_IVector subSeqPos) {
//! TODO(lizhao): Complete this method.
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;
paddle::Argument& arg = a->args[ID];
iv->vec = arg.subSequenceStartPositions->getMutableVector(false);
return kPD_NO_ERROR;
}
}
......@@ -27,7 +27,6 @@ int PDIVecCreateNone(PD_IVector* ivec) {
}
int PDIVectorCreate(PD_IVector* ivec, int* array, uint64_t size, bool copy) {
//! TODO(lizhao): Complete this method.
if (ivec == nullptr) return kPD_NULLPTR;
auto ptr = new paddle::capi::CIVector();
if (copy) {
......@@ -55,7 +54,6 @@ int PDIVectorGet(PD_IVector ivec, int** buffer) {
}
int PDIVectorResize(PD_IVector ivec, uint64_t size) {
//! TODO(lizhao): Complete this method.
if (ivec == nullptr) return kPD_NULLPTR;
auto v = cast<paddle::capi::CIVector>(ivec);
if (v->vec == nullptr) return kPD_NULLPTR;
......@@ -64,7 +62,6 @@ int PDIVectorResize(PD_IVector ivec, uint64_t size) {
}
int PDIVectorGetSize(PD_IVector ivec, uint64_t* size) {
//! TODO(lizhao): Complete this method.
if (ivec == nullptr) return kPD_NULLPTR;
auto v = cast<paddle::capi::CIVector>(ivec);
if (v->vec == nullptr) return kPD_NULLPTR;
......
......@@ -89,7 +89,8 @@ TEST(CAPIArguments, ids) {
ASSERT_EQ(kPD_NO_ERROR, PDArgsDestroy(args));
}
TEST(CAPIArguments, Sequence) {
template <typename T1, typename T2>
void testSequenceHelper(T1 setter, T2 getter) {
PD_Arguments args;
ASSERT_EQ(kPD_NO_ERROR, PDArgsCreateNone(&args));
ASSERT_EQ(kPD_NO_ERROR, PDArgsResize(args, 1));
......@@ -97,12 +98,27 @@ TEST(CAPIArguments, Sequence) {
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));
ASSERT_EQ(kPD_NO_ERROR, setter(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, getter(args, 0, val));
uint64_t size;
ASSERT_EQ(kPD_NO_ERROR, PDIVectorGetSize(val, &size));
int* rawBuf;
ASSERT_EQ(kPD_NO_ERROR, PDIVectorGet(val, &rawBuf));
for (size_t i = 0; i < size; ++i) {
ASSERT_EQ(array[i], rawBuf[i]);
}
ASSERT_EQ(kPD_NO_ERROR, PDIVecDestroy(ivec));
ASSERT_EQ(kPD_NO_ERROR, PDIVecDestroy(val));
ASSERT_EQ(kPD_NO_ERROR, PDArgsDestroy(args));
}
TEST(CAPIArguments, Sequence) {
testSequenceHelper(PDArgsSetSequenceStartPos, PDArgsGetSequenceStartPos);
testSequenceHelper(PDArgsSetSubSequenceStartPos,
PDArgsGetSubSequenceStartPos);
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册