microsoft/onnxruntime-extensions
Publicmirrored fromhttps://github.com/microsoft/onnxruntime-extensionsAvailable
operators/text/op_ragged_tensor.hpp
59lines · modecode
| 1 | // Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | // Licensed under the MIT License. |
| 3 | |
| 4 | #pragma once |
| 5 | |
| 6 | #include "kernels.h" |
| 7 | |
| 8 | struct KernelRaggedTensorToSparse : BaseKernel { |
| 9 | KernelRaggedTensorToSparse(OrtApi api); |
| 10 | void Compute(OrtKernelContext* context); |
| 11 | }; |
| 12 | |
| 13 | struct CustomOpRaggedTensorToSparse : Ort::CustomOpBase<CustomOpRaggedTensorToSparse, KernelRaggedTensorToSparse> { |
| 14 | size_t GetInputTypeCount() const; |
| 15 | size_t GetOutputTypeCount() const; |
| 16 | ONNXTensorElementDataType GetOutputType(size_t index) const; |
| 17 | const char* GetName() const; |
| 18 | void* CreateKernel(OrtApi api, const OrtKernelInfo* /* info */) const; |
| 19 | ONNXTensorElementDataType GetInputType(size_t index) const; |
| 20 | }; |
| 21 | |
| 22 | struct CommonRaggedTensorToDense : BaseKernel { |
| 23 | CommonRaggedTensorToDense(OrtApi api, const OrtKernelInfo* info); |
| 24 | |
| 25 | protected: |
| 26 | void GetInputDims(OrtKernelContext* context, const OrtValue** inputs, OrtTensorDimensions* dims); |
| 27 | int64_t GetMaxCol(int64_t n, const int64_t* p_indices); |
| 28 | }; |
| 29 | |
| 30 | struct KernelRaggedTensorToDense : CommonRaggedTensorToDense { |
| 31 | KernelRaggedTensorToDense(OrtApi api, const OrtKernelInfo* info); |
| 32 | void Compute(OrtKernelContext* context); |
| 33 | |
| 34 | private: |
| 35 | int64_t missing_value_; |
| 36 | }; |
| 37 | |
| 38 | struct CustomOpRaggedTensorToDense : Ort::CustomOpBase<CustomOpRaggedTensorToDense, KernelRaggedTensorToDense> { |
| 39 | size_t GetInputTypeCount() const; |
| 40 | size_t GetOutputTypeCount() const; |
| 41 | ONNXTensorElementDataType GetOutputType(size_t index) const; |
| 42 | const char* GetName() const; |
| 43 | void* CreateKernel(OrtApi api, const OrtKernelInfo* /* info */) const; |
| 44 | ONNXTensorElementDataType GetInputType(size_t index) const; |
| 45 | }; |
| 46 | |
| 47 | struct KernelStringRaggedTensorToDense : CommonRaggedTensorToDense { |
| 48 | KernelStringRaggedTensorToDense(OrtApi api, const OrtKernelInfo* info); |
| 49 | void Compute(OrtKernelContext* context); |
| 50 | }; |
| 51 | |
| 52 | struct CustomOpStringRaggedTensorToDense : Ort::CustomOpBase<CustomOpStringRaggedTensorToDense, KernelStringRaggedTensorToDense> { |
| 53 | size_t GetInputTypeCount() const; |
| 54 | size_t GetOutputTypeCount() const; |
| 55 | ONNXTensorElementDataType GetOutputType(size_t index) const; |
| 56 | const char* GetName() const; |
| 57 | void* CreateKernel(OrtApi api, const OrtKernelInfo* /* info */) const; |
| 58 | ONNXTensorElementDataType GetInputType(size_t index) const; |
| 59 | }; |
| 60 | |