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