diff --git a/js/react_native/ios/OnnxruntimeModuleTest/Resources/test_types_uint8.ort b/js/react_native/ios/OnnxruntimeModuleTest/Resources/test_types_uint8.ort new file mode 100644 index 0000000000..9f53108033 Binary files /dev/null and b/js/react_native/ios/OnnxruntimeModuleTest/Resources/test_types_uint8.ort differ diff --git a/js/react_native/ios/OnnxruntimeModuleTest/TensorHelperTest.mm b/js/react_native/ios/OnnxruntimeModuleTest/TensorHelperTest.mm index e2fd4ec7c6..3ed082e222 100644 --- a/js/react_native/ios/OnnxruntimeModuleTest/TensorHelperTest.mm +++ b/js/react_native/ios/OnnxruntimeModuleTest/TensorHelperTest.mm @@ -73,6 +73,14 @@ static void testCreateInputTensorT(const std::array &outValues, std::funct testCreateInputTensorT(outValues, convert, ONNX_TENSOR_ELEMENT_DATA_TYPE_BOOL, JsTensorTypeBool); } +- (void)testCreateInputTensorUInt8 { + std::array outValues{std::numeric_limits::min(), 2, std::numeric_limits::max()}; + std::function convert = [](uint8_t value) { + return [NSNumber numberWithUnsignedChar:value]; + }; + testCreateInputTensorT(outValues, convert, ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT8, JsTensorTypeUnsignedByte); +} + - (void)testCreateInputTensorInt8 { std::array outValues{std::numeric_limits::min(), 2, std::numeric_limits::max()}; std::function convert = [](int8_t value) { return [NSNumber numberWithChar:value]; }; @@ -225,6 +233,14 @@ static void testCreateOutputTensorT(const std::array &outValues, std::func testCreateOutputTensorT(outValues, convert, JsTensorTypeBool, @"test_types_bool", @"onnx"); } +- (void)testCreateOutputTensorUInt8 { + std::array outValues{std::numeric_limits::min(), 1, 2, 3, std::numeric_limits::max()}; + std::function convert = [](uint8_t value) { + return [NSNumber numberWithUnsignedChar:value]; + }; + testCreateOutputTensorT(outValues, convert, JsTensorTypeUnsignedByte, @"test_types_uint8", @"ort"); +} + - (void)testCreateOutputTensorInt8 { std::array outValues{std::numeric_limits::min(), 1, -2, 3, std::numeric_limits::max()}; std::function convert = [](int8_t value) { return [NSNumber numberWithChar:value]; }; diff --git a/js/react_native/ios/TensorHelper.h b/js/react_native/ios/TensorHelper.h index 40203c0cf9..f0936cce8b 100644 --- a/js/react_native/ios/TensorHelper.h +++ b/js/react_native/ios/TensorHelper.h @@ -13,6 +13,7 @@ * Supported tensor data type */ FOUNDATION_EXPORT NSString* const JsTensorTypeBool; +FOUNDATION_EXPORT NSString* const JsTensorTypeUnsignedByte; FOUNDATION_EXPORT NSString* const JsTensorTypeByte; FOUNDATION_EXPORT NSString* const JsTensorTypeShort; FOUNDATION_EXPORT NSString* const JsTensorTypeInt; diff --git a/js/react_native/ios/TensorHelper.mm b/js/react_native/ios/TensorHelper.mm index eecf064d7d..00c1c79def 100644 --- a/js/react_native/ios/TensorHelper.mm +++ b/js/react_native/ios/TensorHelper.mm @@ -10,6 +10,7 @@ * Supported tensor data type */ NSString *const JsTensorTypeBool = @"bool"; +NSString *const JsTensorTypeUnsignedByte = @"uint8"; NSString *const JsTensorTypeByte = @"int8"; NSString *const JsTensorTypeShort = @"int16"; NSString *const JsTensorTypeInt = @"int32"; @@ -137,6 +138,8 @@ static Ort::Value createInputTensorT(OrtAllocator *ortAllocator, const std::vect switch (tensorType) { case ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT: return createInputTensorT(ortAllocator, dims, buffer, allocations); + case ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT8: + return createInputTensorT(ortAllocator, dims, buffer, allocations); case ONNX_TENSOR_ELEMENT_DATA_TYPE_INT8: return createInputTensorT(ortAllocator, dims, buffer, allocations); case ONNX_TENSOR_ELEMENT_DATA_TYPE_INT16: @@ -150,7 +153,6 @@ static Ort::Value createInputTensorT(OrtAllocator *ortAllocator, const std::vect case ONNX_TENSOR_ELEMENT_DATA_TYPE_DOUBLE: return createInputTensorT(ortAllocator, dims, buffer, allocations); case ONNX_TENSOR_ELEMENT_DATA_TYPE_UNDEFINED: - case ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT8: case ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT16: case ONNX_TENSOR_ELEMENT_DATA_TYPE_STRING: case ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT16: @@ -182,6 +184,8 @@ template static NSString *createOutputTensorT(const Ort::Value &ten switch (tensorType) { case ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT: return createOutputTensorT(tensor); + case ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT8: + return createOutputTensorT(tensor); case ONNX_TENSOR_ELEMENT_DATA_TYPE_INT8: return createOutputTensorT(tensor); case ONNX_TENSOR_ELEMENT_DATA_TYPE_INT16: @@ -195,7 +199,6 @@ template static NSString *createOutputTensorT(const Ort::Value &ten case ONNX_TENSOR_ELEMENT_DATA_TYPE_DOUBLE: return createOutputTensorT(tensor); case ONNX_TENSOR_ELEMENT_DATA_TYPE_UNDEFINED: - case ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT8: case ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT16: case ONNX_TENSOR_ELEMENT_DATA_TYPE_STRING: case ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT16: @@ -219,6 +222,7 @@ NSDictionary *OnnxTensorTypeToJsTensorTypeMap; + (void)initialize { JsTensorTypeToOnnxTensorTypeMap = @{ JsTensorTypeFloat : @(ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT), + JsTensorTypeUnsignedByte : @(ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT8), JsTensorTypeByte : @(ONNX_TENSOR_ELEMENT_DATA_TYPE_INT8), JsTensorTypeShort : @(ONNX_TENSOR_ELEMENT_DATA_TYPE_INT16), JsTensorTypeInt : @(ONNX_TENSOR_ELEMENT_DATA_TYPE_INT32), @@ -230,6 +234,7 @@ NSDictionary *OnnxTensorTypeToJsTensorTypeMap; OnnxTensorTypeToJsTensorTypeMap = @{ @(ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT) : JsTensorTypeFloat, + @(ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT8) : JsTensorTypeUnsignedByte, @(ONNX_TENSOR_ELEMENT_DATA_TYPE_INT8) : JsTensorTypeByte, @(ONNX_TENSOR_ELEMENT_DATA_TYPE_INT16) : JsTensorTypeShort, @(ONNX_TENSOR_ELEMENT_DATA_TYPE_INT32) : JsTensorTypeInt,