| 67 | class MatMulTest : public MNNTestCase { |
| 68 | public: |
| 69 | virtual bool run(int precision) { |
| 70 | auto executor = cloneCurrentExecutor(); |
| 71 | ExecutorScope scope(executor); |
| 72 | int e = 5, h = 4, l = 6; |
| 73 | if (true) { |
| 74 | // Test MatMul |
| 75 | std::unique_ptr<MNN::OpT> op(new MNN::OpT); |
| 76 | op->type = MNN::OpType_MatMul; |
| 77 | op->main.type = MNN::OpParameter_MatMul; |
| 78 | op->main.value = new MNN::MatMulT; |
| 79 | auto matmulParam = op->main.AsMatMul(); |
| 80 | matmulParam->transposeA = false; |
| 81 | matmulParam->transposeB = false; |
| 82 | |
| 83 | auto x0 = _Input({}, NHWC, halide_type_of<float>()); |
| 84 | auto x1 = _Input({}, NHWC, halide_type_of<float>()); |
| 85 | auto y = Variable::create(Expr::create(op.get(), {x0, x1})); |
| 86 | x0->resize({h, l}); |
| 87 | x1->resize({l, e}); |
| 88 | fillFloat(x0->writeMap<float>(), h, l); |
| 89 | fillFloat(x1->writeMap<float>(), l, e); |
| 90 | |
| 91 | auto res = checkMatMul(y->readMap<float>(), x0->readMap<float>(), x1->readMap<float>(), e, l, h); |
| 92 | if (!res) { |
| 93 | FUNC_PRINT(1); |
| 94 | return false; |
| 95 | } |
| 96 | auto tranposeA = _Transpose(x0, {1, 0}); |
| 97 | matmulParam->transposeA = true; |
| 98 | matmulParam->transposeB = false; |
| 99 | y = Variable::create(Expr::create(op.get(), {tranposeA, x1})); |
| 100 | res = checkMatMul(y->readMap<float>(), x0->readMap<float>(), x1->readMap<float>(), e, l, h); |
| 101 | if (!res) { |
| 102 | FUNC_PRINT(1); |
| 103 | return false; |
| 104 | } |
| 105 | auto tranposeB = _Transpose(x1, {1, 0}); |
| 106 | matmulParam->transposeA = true; |
| 107 | matmulParam->transposeB = true; |
| 108 | y = Variable::create(Expr::create(op.get(), {tranposeA, tranposeB})); |
| 109 | res = checkMatMul(y->readMap<float>(), x0->readMap<float>(), x1->readMap<float>(), e, l, h); |
| 110 | if (!res) { |
| 111 | FUNC_PRINT(1); |
| 112 | return false; |
| 113 | } |
| 114 | matmulParam->transposeA = false; |
| 115 | matmulParam->transposeB = true; |
| 116 | y = Variable::create(Expr::create(op.get(), {x0, tranposeB})); |
| 117 | res = checkMatMul(y->readMap<float>(), x0->readMap<float>(), x1->readMap<float>(), e, l, h); |
| 118 | if (!res) { |
| 119 | FUNC_PRINT(1); |
| 120 | return false; |
| 121 | } |
| 122 | } |
| 123 | if (true) { |
| 124 | std::unique_ptr<MNN::OpT> op(new MNN::OpT); |
| 125 | op->type = MNN::OpType_BatchMatMul; |
| 126 | op->main.type = MNN::OpParameter_BatchMatMulParam; |
nothing calls this directly
no test coverage detected