MNN/test/op/UnstackTest.cpp

43 lines
1.5 KiB
C++
Raw Permalink Normal View History

2019-12-27 22:16:57 +08:00
//
// UnstackTest.cpp
// MNNTests
//
// Created by MNN on 2019/12/18.
// Copyright © 2018, Alibaba Group Holding Limited
//
2020-11-05 16:41:56 +08:00
2019-12-27 22:16:57 +08:00
#include <MNN/expr/Expr.hpp>
#include <MNN/expr/ExprCreator.hpp>
#include "MNNTestSuite.h"
#include "TestUtils.h"
using namespace MNN::Express;
class UnstackTest : public MNNTestCase {
public:
virtual ~UnstackTest() = default;
virtual bool run(int precision) {
2020-11-05 16:41:56 +08:00
auto input = _Input({3, 1, 2, 2}, NCHW);
2019-12-27 22:16:57 +08:00
input->setName("input_tensor");
// set input data
const float inpudata[] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0};
auto inputPtr = input->writeMap<float>();
memcpy(inputPtr, inpudata, 12 * sizeof(float));
input->unMap();
2020-11-05 16:41:56 +08:00
auto outputs = _Unstack(input, -2);
2019-12-27 22:16:57 +08:00
const std::vector<float> expectedOutput_0 = {1.0, 2.0, 5.0, 6.0, 9.0, 10.0};
2020-11-05 16:41:56 +08:00
const std::vector<float> expectedOutput_1 = {3.0, 4.0, 7.0, 8.0, 11.0, 12.0};
auto gotOutput_0 = outputs[0]->readMap<float>();
auto gotOutput_1 = outputs[1]->readMap<float>();
2019-12-27 22:16:57 +08:00
if (!checkVector<float>(gotOutput_0, expectedOutput_0.data(), 6, 0.01)) {
MNN_ERROR("UnstackTest test failed!\n");
return false;
}
if (!checkVector<float>(gotOutput_1, expectedOutput_1.data(), 6, 0.01)) {
MNN_ERROR("UnstackTest test failed!\n");
return false;
}
return true;
}
};
MNNTestSuiteRegister(UnstackTest, "op/unstack");