| 15 | public: |
| 16 | virtual ~MatrixBandPartTest() = default; |
| 17 | virtual bool run(int precision) { |
| 18 | auto input = _Input({4, 4}, NHWC); |
| 19 | input->setName("input_tensor"); |
| 20 | // set input data |
| 21 | const float inpudata[] = {0.0, 1.0, 2.0, 3.0, -1.0, 0.0, 1.0, 2.0, -2.0, -1.0, 0.0, 1.0, -3.0, -2.0, -1.0, 0.0}; |
| 22 | auto inputPtr = input->writeMap<float>(); |
| 23 | memcpy(inputPtr, inpudata, 16 * sizeof(float)); |
| 24 | input->unMap(); |
| 25 | int lower_data = 1; |
| 26 | int higher_data = -1; |
| 27 | auto lower = _Const(&lower_data, {}, NCHW, halide_type_of<int>()); |
| 28 | auto higher = _Const(&higher_data, {}, NCHW, halide_type_of<int>()); |
| 29 | auto output = _MatrixBandPart(input, lower, higher); |
| 30 | const std::vector<float> expectedOutput = {0.0, 1.0, 2.0, 3.0, -1.0, 0.0, 1.0, 2.0, |
| 31 | 0.0, -1.0, 0.0, 1.0, 0.0, 0.0, -1.0, 0.0}; |
| 32 | auto gotOutput = output->readMap<float>(); |
| 33 | if (!checkVector<float>(gotOutput, expectedOutput.data(), 16, 0.01)) { |
| 34 | MNN_ERROR("MatrixBandPartTest test failed!\n"); |
| 35 | return false; |
| 36 | } |
| 37 | return true; |
| 38 | } |
| 39 | }; |
| 40 | MNNTestSuiteRegister(MatrixBandPartTest, "op/matrixbandpart"); |