From 52422ae47d83e97167a17f2ed066e4ccb06ab7fb Mon Sep 17 00:00:00 2001 From: "Carson M." Date: Wed, 4 Sep 2024 20:08:03 -0500 Subject: [PATCH] feat: support optional `ValueType`s According to the C API, these only appear in model metadata, so no need to implement another `Value`. --- src/value/mod.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/value/mod.rs b/src/value/mod.rs index 2ee91b39..c51c2810 100644 --- a/src/value/mod.rs +++ b/src/value/mod.rs @@ -87,7 +87,9 @@ pub enum ValueType { key: TensorElementType, /// The map value type. value: TensorElementType - } + }, + /// An optional value, which may or may not contain a [`Value`]. + Optional(Box) } impl ValueType { @@ -110,6 +112,15 @@ impl ValueType { ortsys![unsafe CastTypeInfoToMapTypeInfo(typeinfo_ptr, &mut info_ptr)?; nonNull(info_ptr)]; unsafe { extract_data_type_from_map_info(info_ptr)? } } + ort_sys::ONNXType::ONNX_TYPE_OPTIONAL => { + let mut info_ptr: *const ort_sys::OrtOptionalTypeInfo = std::ptr::null_mut(); + ortsys![unsafe CastTypeInfoToOptionalTypeInfo(typeinfo_ptr, &mut info_ptr)?; nonNull(info_ptr)]; + + let mut contained_type: *mut ort_sys::OrtTypeInfo = std::ptr::null_mut(); + ortsys![unsafe GetOptionalContainedTypeInfo(info_ptr, &mut contained_type)?; nonNull(contained_type)]; + + ValueType::Optional(Box::new(ValueType::from_type_info(contained_type)?)) + } _ => unreachable!() }; ortsys![unsafe ReleaseTypeInfo(typeinfo_ptr)];