| 21 | class GatherExprTest : public MNNTestCase { |
| 22 | public: |
| 23 | virtual bool run(int precision) { |
| 24 | auto executor = cloneCurrentExecutor(); |
| 25 | ExecutorScope scope(executor); |
| 26 | |
| 27 | std::unique_ptr<MNN::OpT> gatherOp(new MNN::OpT); |
| 28 | gatherOp->type = MNN::OpType_GatherND; |
| 29 | auto parameter = _Input({2, 2}, NHWC, halide_type_of<int32_t>()); |
| 30 | parameter->setName("param"); |
| 31 | auto indice = _Input({2, 2}, NHWC, halide_type_of<int32_t>()); |
| 32 | indice->setName("indice"); |
| 33 | auto y = Variable::create(Expr::create(gatherOp.get(), {parameter, indice})); |
| 34 | y->setName("y"); |
| 35 | { |
| 36 | parameter->resize({2, 2}); |
| 37 | auto ptr = parameter->writeMap<float>(); |
| 38 | ptr[0] = 7.0; |
| 39 | ptr[1] = 2.0; |
| 40 | ptr[2] = 4.0; |
| 41 | ptr[3] = 6.0; |
| 42 | } |
| 43 | { |
| 44 | auto indicePtr = indice->writeMap<int32_t>(); |
| 45 | indicePtr[0] = 0; |
| 46 | indicePtr[1] = 0; |
| 47 | indicePtr[2] = 1; |
| 48 | indicePtr[3] = 1; |
| 49 | auto size = y->getInfo()->size; |
| 50 | if (size != 2) { |
| 51 | return false; |
| 52 | } |
| 53 | auto yPtr = y->readMap<float>(); |
| 54 | if (fabs(yPtr[0] - 7.0) > 0.001 || fabs(yPtr[1] - 6.0) > 0.001) { |
| 55 | return false; |
| 56 | } |
| 57 | } |
| 58 | { |
| 59 | indice->resize({2, 1}); |
| 60 | auto indicePtr = indice->writeMap<int32_t>(); |
| 61 | indicePtr[0] = 1; |
| 62 | indicePtr[1] = 0; |
| 63 | auto size = y->getInfo()->size; |
| 64 | if (4 != size) { |
| 65 | return false; |
| 66 | } |
| 67 | auto yPtr = y->readMap<float>(); |
| 68 | if (fabs(yPtr[0] - 4.0) > 0.001 || fabs(yPtr[1] - 6.0) > 0.001 || fabs(yPtr[2] - 7.0) > 0.001 || |
| 69 | fabs(yPtr[3] - 2.0) > 0.001) { |
| 70 | return false; |
| 71 | } |
| 72 | } |
| 73 | { |
| 74 | indice->resize({1, 1}); |
| 75 | auto indicePtr = indice->writeMap<int32_t>(); |
| 76 | indicePtr[0] = 1; |
| 77 | parameter->resize({2, 2, 2}); |
| 78 | auto parameterPtr = parameter->writeMap<float>(); |
| 79 | for (int i = 0; i < parameter->getInfo()->size; ++i) { |
| 80 | parameterPtr[i] = 1.0 * i; |
nothing calls this directly
no test coverage detected