microsoft/onnxruntime-extensions

Public

mirrored from https://github.com/microsoft/onnxruntime-extensionsAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
2ef88b0bda3208844b2bee2ea682bc76a4085c63

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

ocos/kernels/string_upper.cc

55lines · modecode

1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT License.
3
4#include "string_upper.hpp"
5#include <vector>
6#include <cmath>
7#include <algorithm>
8
9
10KernelStringUpper::KernelStringUpper(OrtApi api) : BaseKernel(api) {
11}
12
13void KernelStringUpper::Compute(OrtKernelContext* context) {
14 // Setup inputs
15 const OrtValue* input_X = ort_.KernelContext_GetInput(context, 0);
16 const std::string* X = ort_.GetTensorData<std::string>(input_X);
17
18 // Setup output
19 OrtTensorDimensions dimensions(ort_, input_X);
20 OrtValue* output = ort_.KernelContext_GetOutput(context, 0, dimensions.data(), dimensions.size());
21 std::string* out = ort_.GetTensorMutableData<std::string>(output);
22
23 OrtTensorTypeAndShapeInfo* output_info = ort_.GetTensorTypeAndShape(output);
24 int64_t size = ort_.GetTensorShapeElementCount(output_info);
25 ort_.ReleaseTensorTypeAndShapeInfo(output_info);
26
27 // Do computation
28 for (int64_t i = 0; i < size; i++) {
29 out[i] = X[i];
30 std::transform(out[i].begin(), out[i].end(), out[i].begin(), ::toupper);
31 }
32}
33
34void* CustomOpStringUpper::CreateKernel(OrtApi api, const OrtKernelInfo* /* info */) {
35 return new KernelStringUpper(api);
36};
37
38const char* CustomOpStringUpper::GetName() const { return "StringUpper"; };
39
40size_t CustomOpStringUpper::GetInputTypeCount() const {
41 return 1;
42};
43
44ONNXTensorElementDataType CustomOpStringUpper::GetInputType(size_t /*index*/) const {
45 return ONNX_TENSOR_ELEMENT_DATA_TYPE_STRING;
46};
47
48size_t CustomOpStringUpper::GetOutputTypeCount() const {
49 return 1;
50};
51
52ONNXTensorElementDataType CustomOpStringUpper::GetOutputType(size_t /*index*/) const {
53 return ONNX_TENSOR_ELEMENT_DATA_TYPE_STRING;
54};