microsoft/onnxruntime-extensions
Publicmirrored from https://github.com/microsoft/onnxruntime-extensionsAvailable
test/shared_test/test_ortops_math.cc
132lines · modecode
| 1 | // Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | // Licensed under the MIT License. |
| 3 | |
| 4 | #include <filesystem> |
| 5 | #include "gtest/gtest.h" |
| 6 | #include "ocos.h" |
| 7 | #include "test_kernel.hpp" |
| 8 | |
| 9 | |
| 10 | TEST(math_operator, segment_extraction) { |
| 11 | auto ort_env = std::make_unique<Ort::Env>(ORT_LOGGING_LEVEL_WARNING, "Default"); |
| 12 | |
| 13 | std::vector<TestValue> inputs(1); |
| 14 | inputs[0].name = "input"; |
| 15 | inputs[0].element_type = ONNXTensorElementDataType::ONNX_TENSOR_ELEMENT_DATA_TYPE_INT64; |
| 16 | inputs[0].dims = {1, 11}; |
| 17 | inputs[0].values_int64 = {0, 0, 1, 1, 2, 2, 2, 3, 3, 3, 3}; |
| 18 | |
| 19 | std::vector<TestValue> outputs(2); |
| 20 | outputs[0].name = "position"; |
| 21 | outputs[0].element_type = ONNXTensorElementDataType::ONNX_TENSOR_ELEMENT_DATA_TYPE_INT64; |
| 22 | outputs[0].dims = {3,2}; |
| 23 | outputs[0].values_int64 = {2, 4, 4, 7, 7, 11}; |
| 24 | |
| 25 | outputs[1].name = "value"; |
| 26 | outputs[1].element_type = ONNXTensorElementDataType::ONNX_TENSOR_ELEMENT_DATA_TYPE_INT64; |
| 27 | outputs[1].dims = {3}; |
| 28 | outputs[1].values_int64 = {1, 2, 3}; |
| 29 | |
| 30 | std::filesystem::path model_path = "data"; |
| 31 | model_path /= "test_segment_extraction.onnx"; |
| 32 | TestInference(*ort_env, model_path.c_str(), inputs, outputs, GetLibraryPath()); |
| 33 | |
| 34 | inputs[0].name = "input"; |
| 35 | inputs[0].element_type = ONNXTensorElementDataType::ONNX_TENSOR_ELEMENT_DATA_TYPE_INT64; |
| 36 | inputs[0].dims = {1, 12}; |
| 37 | inputs[0].values_int64 = {1, 1, 0, 0, 2, 2, 2, 3, 3, 3, 0, 5}; |
| 38 | |
| 39 | outputs[0].name = "position"; |
| 40 | outputs[0].element_type = ONNXTensorElementDataType::ONNX_TENSOR_ELEMENT_DATA_TYPE_INT64; |
| 41 | outputs[0].dims = {4,2}; |
| 42 | outputs[0].values_int64 = {0, 2, 4, 7, 7, 10, 11, 12}; |
| 43 | |
| 44 | outputs[1].name = "value"; |
| 45 | outputs[1].element_type = ONNXTensorElementDataType::ONNX_TENSOR_ELEMENT_DATA_TYPE_INT64; |
| 46 | outputs[1].dims = {4}; |
| 47 | outputs[1].values_int64 = {1, 2, 3, 5}; |
| 48 | TestInference(*ort_env, model_path.c_str(), inputs, outputs, GetLibraryPath()); |
| 49 | |
| 50 | |
| 51 | inputs[0].name = "input"; |
| 52 | inputs[0].element_type = ONNXTensorElementDataType::ONNX_TENSOR_ELEMENT_DATA_TYPE_INT64; |
| 53 | inputs[0].dims = {1, 4}; |
| 54 | inputs[0].values_int64 = {1, 2, 4, 5}; |
| 55 | |
| 56 | outputs[0].name = "position"; |
| 57 | outputs[0].element_type = ONNXTensorElementDataType::ONNX_TENSOR_ELEMENT_DATA_TYPE_INT64; |
| 58 | outputs[0].dims = {4,2}; |
| 59 | outputs[0].values_int64 = {0, 1, 1, 2, 2, 3, 3, 4}; |
| 60 | |
| 61 | outputs[1].name = "value"; |
| 62 | outputs[1].element_type = ONNXTensorElementDataType::ONNX_TENSOR_ELEMENT_DATA_TYPE_INT64; |
| 63 | outputs[1].dims = {4}; |
| 64 | outputs[1].values_int64 = {1, 2, 4, 5}; |
| 65 | TestInference(*ort_env, model_path.c_str(), inputs, outputs, GetLibraryPath()); |
| 66 | |
| 67 | |
| 68 | inputs[0].name = "input"; |
| 69 | inputs[0].element_type = ONNXTensorElementDataType::ONNX_TENSOR_ELEMENT_DATA_TYPE_INT64; |
| 70 | inputs[0].dims = {1, 13}; |
| 71 | inputs[0].values_int64 = {0, 0, 1, 1, 1, 0, 0, 0, 0, 3, 3, 3, 0}; |
| 72 | |
| 73 | outputs[0].name = "position"; |
| 74 | outputs[0].element_type = ONNXTensorElementDataType::ONNX_TENSOR_ELEMENT_DATA_TYPE_INT64; |
| 75 | outputs[0].dims = {2,2}; |
| 76 | outputs[0].values_int64 = {2, 5, 9, 12}; |
| 77 | |
| 78 | outputs[1].name = "value"; |
| 79 | outputs[1].element_type = ONNXTensorElementDataType::ONNX_TENSOR_ELEMENT_DATA_TYPE_INT64; |
| 80 | outputs[1].dims = {2}; |
| 81 | outputs[1].values_int64 = {1, 3}; |
| 82 | TestInference(*ort_env, model_path.c_str(), inputs, outputs, GetLibraryPath()); |
| 83 | |
| 84 | inputs[0].name = "input"; |
| 85 | inputs[0].element_type = ONNXTensorElementDataType::ONNX_TENSOR_ELEMENT_DATA_TYPE_INT64; |
| 86 | inputs[0].dims = {1, 1}; |
| 87 | inputs[0].values_int64 = {0}; |
| 88 | |
| 89 | outputs[0].name = "position"; |
| 90 | outputs[0].element_type = ONNXTensorElementDataType::ONNX_TENSOR_ELEMENT_DATA_TYPE_INT64; |
| 91 | outputs[0].dims = {0, 2}; |
| 92 | outputs[0].values_int64 = {}; |
| 93 | |
| 94 | outputs[1].name = "value"; |
| 95 | outputs[1].element_type = ONNXTensorElementDataType::ONNX_TENSOR_ELEMENT_DATA_TYPE_INT64; |
| 96 | outputs[1].dims = {0}; |
| 97 | outputs[1].values_int64 = {}; |
| 98 | TestInference(*ort_env, model_path.c_str(), inputs, outputs, GetLibraryPath()); |
| 99 | |
| 100 | inputs[0].name = "input"; |
| 101 | inputs[0].element_type = ONNXTensorElementDataType::ONNX_TENSOR_ELEMENT_DATA_TYPE_INT64; |
| 102 | inputs[0].dims = {1, 0}; |
| 103 | inputs[0].values_int64 = {0}; |
| 104 | |
| 105 | outputs[0].name = "position"; |
| 106 | outputs[0].element_type = ONNXTensorElementDataType::ONNX_TENSOR_ELEMENT_DATA_TYPE_INT64; |
| 107 | outputs[0].dims = {0, 2}; |
| 108 | outputs[0].values_int64 = {}; |
| 109 | |
| 110 | outputs[1].name = "value"; |
| 111 | outputs[1].element_type = ONNXTensorElementDataType::ONNX_TENSOR_ELEMENT_DATA_TYPE_INT64; |
| 112 | outputs[1].dims = {0}; |
| 113 | outputs[1].values_int64 = {}; |
| 114 | TestInference(*ort_env, model_path.c_str(), inputs, outputs, GetLibraryPath()); |
| 115 | |
| 116 | |
| 117 | inputs[0].name = "input"; |
| 118 | inputs[0].element_type = ONNXTensorElementDataType::ONNX_TENSOR_ELEMENT_DATA_TYPE_INT64; |
| 119 | inputs[0].dims = {1, 1}; |
| 120 | inputs[0].values_int64 = {1}; |
| 121 | |
| 122 | outputs[0].name = "position"; |
| 123 | outputs[0].element_type = ONNXTensorElementDataType::ONNX_TENSOR_ELEMENT_DATA_TYPE_INT64; |
| 124 | outputs[0].dims = {1, 2}; |
| 125 | outputs[0].values_int64 = {0, 1}; |
| 126 | |
| 127 | outputs[1].name = "value"; |
| 128 | outputs[1].element_type = ONNXTensorElementDataType::ONNX_TENSOR_ELEMENT_DATA_TYPE_INT64; |
| 129 | outputs[1].dims = {1}; |
| 130 | outputs[1].values_int64 = {1}; |
| 131 | TestInference(*ort_env, model_path.c_str(), inputs, outputs, GetLibraryPath()); |
| 132 | } |