@@ -53,24 +53,24 @@ constexpr size_t DATA_TYPE_ELEMENT_SIZE_MAP[] = {
53
53
static_assert (sizeof (DATA_TYPE_ELEMENT_SIZE_MAP) == sizeof(size_t ) * ONNX_TENSOR_ELEMENT_DATA_TYPE_COUNT,
54
54
"definition not matching");
55
55
56
- constexpr napi_typedarray_type DATA_TYPE_TYPEDARRAY_MAP[] = {
57
- ( napi_typedarray_type) (-1 ), // ONNX_TENSOR_ELEMENT_DATA_TYPE_UNDEFINED not supported
58
- napi_float32_array, // ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT
59
- napi_uint8_array, // ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT8
60
- napi_int8_array, // ONNX_TENSOR_ELEMENT_DATA_TYPE_INT8
61
- napi_uint16_array, // ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT16
62
- napi_int16_array, // ONNX_TENSOR_ELEMENT_DATA_TYPE_INT16
63
- napi_int32_array, // ONNX_TENSOR_ELEMENT_DATA_TYPE_INT32
64
- napi_bigint64_array, // ONNX_TENSOR_ELEMENT_DATA_TYPE_INT64
65
- ( napi_typedarray_type) (-1 ), // ONNX_TENSOR_ELEMENT_DATA_TYPE_STRING not supported
66
- napi_uint8_array, // ONNX_TENSOR_ELEMENT_DATA_TYPE_BOOL
67
- napi_uint16_array, // ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT16 FLOAT16 uses Uint16Array
68
- napi_float64_array, // ONNX_TENSOR_ELEMENT_DATA_TYPE_DOUBLE
69
- napi_uint32_array, // ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT32
70
- napi_biguint64_array, // ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT64
71
- ( napi_typedarray_type) (-1 ), // ONNX_TENSOR_ELEMENT_DATA_TYPE_COMPLEX64 not supported
72
- ( napi_typedarray_type) (-1 ), // ONNX_TENSOR_ELEMENT_DATA_TYPE_COMPLEX128 not supported
73
- ( napi_typedarray_type) (-1 ) // ONNX_TENSOR_ELEMENT_DATA_TYPE_BFLOAT16 not supported
56
+ constexpr std:: underlying_type_t < napi_typedarray_type> DATA_TYPE_TYPEDARRAY_MAP[] = {
57
+ std:: underlying_type_t < napi_typedarray_type> (-1 ), // ONNX_TENSOR_ELEMENT_DATA_TYPE_UNDEFINED not supported
58
+ napi_float32_array, // ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT
59
+ napi_uint8_array, // ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT8
60
+ napi_int8_array, // ONNX_TENSOR_ELEMENT_DATA_TYPE_INT8
61
+ napi_uint16_array, // ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT16
62
+ napi_int16_array, // ONNX_TENSOR_ELEMENT_DATA_TYPE_INT16
63
+ napi_int32_array, // ONNX_TENSOR_ELEMENT_DATA_TYPE_INT32
64
+ napi_bigint64_array, // ONNX_TENSOR_ELEMENT_DATA_TYPE_INT64
65
+ std:: underlying_type_t < napi_typedarray_type> (-1 ), // ONNX_TENSOR_ELEMENT_DATA_TYPE_STRING not supported
66
+ napi_uint8_array, // ONNX_TENSOR_ELEMENT_DATA_TYPE_BOOL
67
+ napi_uint16_array, // ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT16 FLOAT16 uses Uint16Array
68
+ napi_float64_array, // ONNX_TENSOR_ELEMENT_DATA_TYPE_DOUBLE
69
+ napi_uint32_array, // ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT32
70
+ napi_biguint64_array, // ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT64
71
+ std:: underlying_type_t < napi_typedarray_type> (-1 ), // ONNX_TENSOR_ELEMENT_DATA_TYPE_COMPLEX64 not supported
72
+ std:: underlying_type_t < napi_typedarray_type> (-1 ), // ONNX_TENSOR_ELEMENT_DATA_TYPE_COMPLEX128 not supported
73
+ std:: underlying_type_t < napi_typedarray_type> (-1 ) // ONNX_TENSOR_ELEMENT_DATA_TYPE_BFLOAT16 not supported
74
74
};
75
75
static_assert (sizeof (DATA_TYPE_TYPEDARRAY_MAP) == sizeof(napi_typedarray_type) * ONNX_TENSOR_ELEMENT_DATA_TYPE_COUNT,
76
76
"definition not matching");
@@ -98,7 +98,20 @@ static_assert(sizeof(DATA_TYPE_ID_TO_NAME_MAP) == sizeof(const char*) * ONNX_TEN
98
98
"definition not matching");
99
99
100
100
const std::unordered_map<std::string, ONNXTensorElementDataType> DATA_TYPE_NAME_TO_ID_MAP = {
101
- {" float32" , ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT}, {" uint8" , ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT8}, {" int8" , ONNX_TENSOR_ELEMENT_DATA_TYPE_INT8}, {" uint16" , ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT16}, {" int16" , ONNX_TENSOR_ELEMENT_DATA_TYPE_INT16}, {" int32" , ONNX_TENSOR_ELEMENT_DATA_TYPE_INT32}, {" int64" , ONNX_TENSOR_ELEMENT_DATA_TYPE_INT64}, {" string" , ONNX_TENSOR_ELEMENT_DATA_TYPE_STRING}, {" bool" , ONNX_TENSOR_ELEMENT_DATA_TYPE_BOOL}, {" float16" , ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT16}, {" float64" , ONNX_TENSOR_ELEMENT_DATA_TYPE_DOUBLE}, {" uint32" , ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT32}, {" uint64" , ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT64}};
101
+ {" float32" , ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT},
102
+ {" uint8" , ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT8},
103
+ {" int8" , ONNX_TENSOR_ELEMENT_DATA_TYPE_INT8},
104
+ {" uint16" , ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT16},
105
+ {" int16" , ONNX_TENSOR_ELEMENT_DATA_TYPE_INT16},
106
+ {" int32" , ONNX_TENSOR_ELEMENT_DATA_TYPE_INT32},
107
+ {" int64" , ONNX_TENSOR_ELEMENT_DATA_TYPE_INT64},
108
+ {" string" , ONNX_TENSOR_ELEMENT_DATA_TYPE_STRING},
109
+ {" bool" , ONNX_TENSOR_ELEMENT_DATA_TYPE_BOOL},
110
+ {" float16" , ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT16},
111
+ {" float64" , ONNX_TENSOR_ELEMENT_DATA_TYPE_DOUBLE},
112
+ {" uint32" , ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT32},
113
+ {" uint64" , ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT64},
114
+ };
102
115
103
116
// currently only support tensor
104
117
Ort::Value NapiValueToOrtValue (Napi::Env env, Napi::Value value, OrtMemoryInfo* cpu_memory_info, OrtMemoryInfo* webgpu_memory_info) {
@@ -181,7 +194,7 @@ Ort::Value NapiValueToOrtValue(Napi::Env env, Napi::Value value, OrtMemoryInfo*
181
194
" Tensor.data must be a typed array for numeric tensor." );
182
195
183
196
auto tensorDataTypedArray = tensorDataValue.As <Napi::TypedArray>();
184
- auto typedArrayType = tensorDataValue.As <Napi::TypedArray>().TypedArrayType ();
197
+ std:: underlying_type_t <napi_typedarray_type> typedArrayType = tensorDataValue.As <Napi::TypedArray>().TypedArrayType ();
185
198
ORT_NAPI_THROW_TYPEERROR_IF (DATA_TYPE_TYPEDARRAY_MAP[elemType] != typedArrayType, env,
186
199
" Tensor.data must be a typed array (" , DATA_TYPE_TYPEDARRAY_MAP[elemType], " ) for " ,
187
200
tensorTypeString, " tensors, but got typed array (" , typedArrayType, " )." );
@@ -294,7 +307,7 @@ Napi::Value OrtValueToNapiValue(Napi::Env env, Ort::Value&& value) {
294
307
}
295
308
napi_value typedArrayData;
296
309
napi_status status =
297
- napi_create_typedarray (env, DATA_TYPE_TYPEDARRAY_MAP[elemType], size, arrayBuffer, 0 , &typedArrayData);
310
+ napi_create_typedarray (env, (napi_typedarray_type) DATA_TYPE_TYPEDARRAY_MAP[elemType], size, arrayBuffer, 0 , &typedArrayData);
298
311
NAPI_THROW_IF_FAILED (env, status, Napi::Value);
299
312
300
313
// new Tensor(type, typedArrayData, dims)
0 commit comments