2021-05-11 17:34:40 +00:00
|
|
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
|
|
|
// Licensed under the MIT License.
|
|
|
|
|
|
|
|
|
|
#ifndef TensorHelper_h
|
|
|
|
|
#define TensorHelper_h
|
|
|
|
|
|
|
|
|
|
#import <Foundation/Foundation.h>
|
2023-06-16 09:37:02 +00:00
|
|
|
#import <React/RCTBlobManager.h>
|
2023-05-09 00:12:10 +00:00
|
|
|
|
|
|
|
|
// Note: Using below syntax for including ort c api and ort extensions headers to resolve a compiling error happened
|
|
|
|
|
// in an expo react native ios app (a redefinition error happened with multiple object types defined within
|
|
|
|
|
// ORT C API header). It's an edge case that the compiler allows both ort c api headers to be included when #include
|
|
|
|
|
// syntax doesn't match. For the case when extensions not enabled, it still requires a onnxruntime prefix directory for
|
|
|
|
|
// searching paths. Also in general, it's a convention to use #include for C/C++ headers rather then #import. See:
|
|
|
|
|
// https://google.github.io/styleguide/objcguide.html#import-and-include
|
|
|
|
|
// https://microsoft.github.io/objc-guide/Headers/ImportAndInclude.html
|
|
|
|
|
#ifdef ORT_ENABLE_EXTENSIONS
|
|
|
|
|
#include "onnxruntime_cxx_api.h"
|
|
|
|
|
#else
|
2023-06-22 21:33:49 +00:00
|
|
|
#include <onnxruntime/onnxruntime_cxx_api.h>
|
2023-05-09 00:12:10 +00:00
|
|
|
#endif
|
2021-05-11 17:34:40 +00:00
|
|
|
|
|
|
|
|
@interface TensorHelper : NSObject
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Supported tensor data type
|
|
|
|
|
*/
|
|
|
|
|
FOUNDATION_EXPORT NSString* const JsTensorTypeBool;
|
2022-10-06 18:35:25 +00:00
|
|
|
FOUNDATION_EXPORT NSString* const JsTensorTypeUnsignedByte;
|
2021-05-11 17:34:40 +00:00
|
|
|
FOUNDATION_EXPORT NSString* const JsTensorTypeByte;
|
|
|
|
|
FOUNDATION_EXPORT NSString* const JsTensorTypeShort;
|
|
|
|
|
FOUNDATION_EXPORT NSString* const JsTensorTypeInt;
|
|
|
|
|
FOUNDATION_EXPORT NSString* const JsTensorTypeLong;
|
|
|
|
|
FOUNDATION_EXPORT NSString* const JsTensorTypeFloat;
|
|
|
|
|
FOUNDATION_EXPORT NSString* const JsTensorTypeDouble;
|
|
|
|
|
FOUNDATION_EXPORT NSString* const JsTensorTypeString;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* It creates an input tensor from a map passed by react native js.
|
2023-06-16 09:37:02 +00:00
|
|
|
* 'data' is blob object and the buffer is stored in RCTBlobManager. It first resolve it and creates a tensor.
|
2021-05-11 17:34:40 +00:00
|
|
|
*/
|
2023-06-16 09:37:02 +00:00
|
|
|
+(Ort::Value)createInputTensor:(RCTBlobManager *)blobManager
|
|
|
|
|
input:(NSDictionary*)input
|
2021-05-11 17:34:40 +00:00
|
|
|
ortAllocator:(OrtAllocator*)ortAllocator
|
2023-06-16 09:37:02 +00:00
|
|
|
allocations:(std::vector<Ort::MemoryAllocation>&)allocations;
|
2021-05-11 17:34:40 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* It creates an output map from an output tensor.
|
2023-06-16 09:37:02 +00:00
|
|
|
* a data array is store in RCTBlobManager.
|
2021-05-11 17:34:40 +00:00
|
|
|
*/
|
2023-06-16 09:37:02 +00:00
|
|
|
+(NSDictionary*)createOutputTensor:(RCTBlobManager *)blobManager
|
|
|
|
|
outputNames:(const std::vector<const char*>&)outputNames
|
2021-05-11 17:34:40 +00:00
|
|
|
values:(const std::vector<Ort::Value>&)values;
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
#endif /* TensorHelper_h */
|