| 6 | using namespace test; |
| 7 | |
| 8 | TEST(INSTRUCTION, ShapeOf) { |
| 9 | //! input shape =[10, 20, 10, 10] |
| 10 | std::shared_ptr<Tensor> output; |
| 11 | std::vector<int> data0(20 * 10 * 10 * 10); |
| 12 | std::vector<int> data1(20); |
| 13 | |
| 14 | auto create_shape_of = [&](Tensor* input) { |
| 15 | auto shapeof = std::make_shared<ShapeOf>(); |
| 16 | |
| 17 | output = std::make_shared<Tensor>(); |
| 18 | output->is_dynamic = true; |
| 19 | |
| 20 | shapeof->input = input; |
| 21 | shapeof->output = output.get(); |
| 22 | return shapeof; |
| 23 | }; |
| 24 | VM* vm = create_vm(); |
| 25 | auto test_shape_of = [&](Tensor* input, const Tensor& expect) { |
| 26 | auto shapeof = create_shape_of(input); |
| 27 | Instruction inst; |
| 28 | inst.tag = TinyNN_INST_SHAPEOF; |
| 29 | inst.workload.shape_of = *shapeof; |
| 30 | vm_instruction_call(vm, &inst); |
| 31 | check_tensor(*shapeof->output, expect); |
| 32 | vm->model->host_dev.free(shapeof->output->ptr); |
| 33 | }; |
| 34 | |
| 35 | auto test_case = [&](std::vector<uint32_t> shape) { |
| 36 | auto src = create_tensor(shape, TinyNNDType::TinyNN_INT, data0.data()); |
| 37 | int index = 0; |
| 38 | for (auto i : shape) { |
| 39 | data1[index++] = i; |
| 40 | } |
| 41 | auto trueth = create_tensor( |
| 42 | {static_cast<uint32_t>(shape.size())}, TinyNNDType::TinyNN_INT, |
| 43 | data1.data()); |
| 44 | test_shape_of(src.get(), *trueth); |
| 45 | }; |
| 46 | |
| 47 | test_case({1, 1, 2, 3}); |
| 48 | test_case({10, 5, 8, 3}); |
| 49 | test_case({1, 3}); |
| 50 | test_case({2, 3, 5}); |
| 51 | } |
| 52 | |
| 53 | // vim: syntax=cpp.doxygen |
nothing calls this directly
no test coverage detected