提交 60acbe05 编写于 作者: alinag's avatar alinag

add reduce sum test of 3 dimention case

test=develop
上级 62257e33
......@@ -52,7 +52,7 @@ inline int ConvOutputSize(int input_size,
return output_size;
}
void UpdatePaddingAndDilation(std::vector<int>* paddings,
inline void UpdatePaddingAndDilation(std::vector<int>* paddings,
std::vector<int>* dilations,
const std::vector<int>& strides,
const std::string padding_algorithm,
......
......@@ -196,7 +196,7 @@ class ReduceSumComputeTester : public arena::TestCase {
std::vector<int> dim_{0};
bool keep_dim_ = false;
bool reduce_all_ = false;
DDim x_dims_{{3, 2, 3, 4}};
DDim x_dims_;
public:
ReduceSumComputeTester(const Place& place,
......@@ -255,6 +255,7 @@ class ReduceSumComputeTester : public arena::TestCase {
out->Resize(DDim(out_dims));
auto* out_data = out->mutable_data<float>();
if (x_dims_.size() == 4) {
int in_n = x_dims_[0];
int in_c = x_dims_[1];
int in_h = x_dims_[2];
......@@ -290,6 +291,42 @@ class ReduceSumComputeTester : public arena::TestCase {
LOG(FATAL) << "invalid dims_!!";
}
}
} else {
if (dim_.size() == 1 && !reduce_all_) {
switch (dim_[0]) {
case 0:
for (int i = 0; i < x_dims_[1]; i++) {
for (int j = 0; j < x_dims_[2]; j++) {
out_data[i * x_dims_[2] + j] =
i * x_dims_[0] * x_dims_[2] + j * x_dims_[0] +
x_dims_[0] * (x_dims_[0] - 1) * x_dims_[1] * x_dims_[2] / 2;
}
}
break;
case 1:
for (int i = 0; i < x_dims_[0]; i++) {
for (int j = 0; j < x_dims_[2]; j++) {
out_data[i * x_dims_[2] + j] =
i * x_dims_[1] * x_dims_[1] * x_dims_[2] + j * x_dims_[1] +
x_dims_[1] * (x_dims_[1] - 1) * x_dims_[2] / 2;
}
}
break;
case 2:
for (int i = 0; i < x_dims_[0]; i++) {
for (int j = 0; j < x_dims_[1]; j++) {
out_data[i * x_dims_[1] + j] =
i * x_dims_[1] * x_dims_[2] * x_dims_[2] +
j * x_dims_[2] * x_dims_[2] +
x_dims_[2] * (x_dims_[2] - 1) / 2;
}
}
break;
default:
LOG(FATAL) << "error!!!";
}
}
}
}
void PrepareOpDesc(cpp::OpDesc* op_desc) {
......@@ -333,6 +370,21 @@ void test_reduce_sum(Place place) {
}
}
}
std::vector<std::vector<int>> reduce_dimm{{0}, {1}, {2}};
for (auto dim : reduce_dimm) {
for (auto c : {1, 3}) {
for (auto h : {1, 3}) {
for (auto w : {1, 4}) {
auto x_dims = DDim(std::vector<int64_t>({c, h, w}));
std::unique_ptr<arena::TestCase> tester(new ReduceSumComputeTester(
place, "def", dim, false, false, x_dims));
arena::Arena arena(std::move(tester), place, 2e-5);
arena.TestPrecision();
}
}
}
}
}
TEST(ReduceSum, precision) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册