1 // 2 // SpaceToDepthTest.cpp 3 // MNNTests 4 // 5 // Created by MNN on 2019/12/18. 6 // Copyright © 2018, Alibaba Group Holding Limited 7 // 8 9 #include <MNN/expr/Expr.hpp> 10 #include <MNN/expr/ExprCreator.hpp> 11 #include "MNNTestSuite.h" 12 #include "TestUtils.h" 13 using namespace MNN::Express; 14 class SpaceToDepthTest : public MNNTestCase { 15 public: 16 virtual ~SpaceToDepthTest() = default; run(int precision)17 virtual bool run(int precision) { 18 auto input = _Input({1, 4, 4, 1}, NHWC); 19 input->setName("input"); 20 // set input data 21 const float input_data[] = {-1.0, 2.0, -3.0, 4.0, 5.0, 6.0, 7.0, -8.0, 22 -9.0, -10.0, 11.0, 12.0, 13.0, 14.0, -15.0, -16.0}; 23 auto inputPtr = input->writeMap<float>(); 24 memcpy(inputPtr, input_data, 16 * sizeof(float)); 25 input->unMap(); 26 auto output = _SpaceToDepth(input, 2); 27 const std::vector<float> expectedOutput = {-1.0, 2.0, 5.0, 6.0, -3.0, 4.0, 7.0, -8.0, 28 -9.0, -10.0, 13.0, 14.0, 11.0, 12.0, -15.0, -16.0}; 29 const std::vector<int> expectedDim = {1, 2, 2, 4}; 30 auto gotOutput = output->readMap<float>(); 31 auto gotDim = output->getInfo()->dim; 32 if (!checkVector<float>(gotOutput, expectedOutput.data(), 16, 0)) { 33 MNN_ERROR("SpaceToDepthTest test failed!\n"); 34 return false; 35 } 36 if (!checkVector<int>(gotDim.data(), expectedDim.data(), 4, 0)) { 37 MNN_ERROR("SpaceToDepthTest test failed!\n"); 38 return false; 39 } 40 return true; 41 } 42 }; 43 MNNTestSuiteRegister(SpaceToDepthTest, "op/spacetodepth"); 44