2019-12-27 22:16:57 +08:00
|
|
|
//
|
|
|
|
|
// SpaceToDepthTest.cpp
|
|
|
|
|
// MNNTests
|
|
|
|
|
//
|
|
|
|
|
// Created by MNN on 2019/12/18.
|
|
|
|
|
// Copyright © 2018, Alibaba Group Holding Limited
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
#include <MNN/expr/Expr.hpp>
|
|
|
|
|
#include <MNN/expr/ExprCreator.hpp>
|
|
|
|
|
#include "MNNTestSuite.h"
|
|
|
|
|
#include "TestUtils.h"
|
|
|
|
|
using namespace MNN::Express;
|
|
|
|
|
class SpaceToDepthTest : public MNNTestCase {
|
|
|
|
|
public:
|
|
|
|
|
virtual ~SpaceToDepthTest() = default;
|
2021-06-11 17:17:13 +08:00
|
|
|
virtual bool run(int precision) {
|
2019-12-27 22:16:57 +08:00
|
|
|
auto input = _Input({1, 4, 4, 1}, NHWC);
|
|
|
|
|
input->setName("input");
|
|
|
|
|
// set input data
|
2020-11-05 16:41:56 +08:00
|
|
|
const float input_data[] = {-1.0, 2.0, -3.0, 4.0, 5.0, 6.0, 7.0, -8.0,
|
|
|
|
|
-9.0, -10.0, 11.0, 12.0, 13.0, 14.0, -15.0, -16.0};
|
|
|
|
|
auto inputPtr = input->writeMap<float>();
|
2019-12-27 22:16:57 +08:00
|
|
|
memcpy(inputPtr, input_data, 16 * sizeof(float));
|
|
|
|
|
input->unMap();
|
2020-11-05 16:41:56 +08:00
|
|
|
auto output = _SpaceToDepth(input, 2);
|
|
|
|
|
const std::vector<float> expectedOutput = {-1.0, 2.0, 5.0, 6.0, -3.0, 4.0, 7.0, -8.0,
|
|
|
|
|
-9.0, -10.0, 13.0, 14.0, 11.0, 12.0, -15.0, -16.0};
|
|
|
|
|
const std::vector<int> expectedDim = {1, 2, 2, 4};
|
|
|
|
|
auto gotOutput = output->readMap<float>();
|
|
|
|
|
auto gotDim = output->getInfo()->dim;
|
2019-12-27 22:16:57 +08:00
|
|
|
if (!checkVector<float>(gotOutput, expectedOutput.data(), 16, 0)) {
|
|
|
|
|
MNN_ERROR("SpaceToDepthTest test failed!\n");
|
|
|
|
|
return false;
|
2020-11-05 16:41:56 +08:00
|
|
|
}
|
2019-12-27 22:16:57 +08:00
|
|
|
if (!checkVector<int>(gotDim.data(), expectedDim.data(), 4, 0)) {
|
|
|
|
|
MNN_ERROR("SpaceToDepthTest test failed!\n");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
MNNTestSuiteRegister(SpaceToDepthTest, "op/spacetodepth");
|