MNN/test/op/RankTest.cpp

42 lines
1.2 KiB
C++
Raw Permalink Normal View History

2019-04-17 10:49:11 +08:00
//
// RankTest.cpp
// MNNTests
//
// Created by MNN on 2019/01/15.
// 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>
2019-04-17 10:49:11 +08:00
#include "MNNTestSuite.h"
#include "TestUtils.h"
2019-12-27 22:16:57 +08:00
using namespace MNN::Express;
2019-04-17 10:49:11 +08:00
class RankTest : public MNNTestCase {
public:
virtual ~RankTest() = default;
virtual bool run(int precision) {
2020-11-05 16:41:56 +08:00
auto input = _Input({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};
auto inputPtr = input->writeMap<float>();
memcpy(inputPtr, inpudata, 4 * sizeof(float));
input->unMap();
2020-11-05 16:41:56 +08:00
auto output = _Rank(input);
2019-12-27 22:16:57 +08:00
const std::vector<int> expectedOutput = {2};
2020-11-05 16:41:56 +08:00
auto gotOutput = output->readMap<int>();
2019-12-27 22:16:57 +08:00
if (!checkVector<int>(gotOutput, expectedOutput.data(), 1, 0)) {
MNN_ERROR("RankTest test failed!\n");
return false;
}
auto dims = output->getInfo()->dim;
2020-11-05 16:41:56 +08:00
if (dims.size() != 0) {
2019-12-27 22:16:57 +08:00
MNN_ERROR("RankTest test failed!\n");
return false;
2019-04-17 10:49:11 +08:00
}
return true;
2019-04-17 10:49:11 +08:00
}
};
MNNTestSuiteRegister(RankTest, "op/rank");