Skip to content

Commit 52422ae

Browse files
committed
feat: support optional ValueTypes
According to the C API, these only appear in model metadata, so no need to implement another `Value<T>`.
1 parent dc08a6b commit 52422ae

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/value/mod.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ pub enum ValueType {
8787
key: TensorElementType,
8888
/// The map value type.
8989
value: TensorElementType
90-
}
90+
},
91+
/// An optional value, which may or may not contain a [`Value`].
92+
Optional(Box<ValueType>)
9193
}
9294

9395
impl ValueType {
@@ -110,6 +112,15 @@ impl ValueType {
110112
ortsys![unsafe CastTypeInfoToMapTypeInfo(typeinfo_ptr, &mut info_ptr)?; nonNull(info_ptr)];
111113
unsafe { extract_data_type_from_map_info(info_ptr)? }
112114
}
115+
ort_sys::ONNXType::ONNX_TYPE_OPTIONAL => {
116+
let mut info_ptr: *const ort_sys::OrtOptionalTypeInfo = std::ptr::null_mut();
117+
ortsys![unsafe CastTypeInfoToOptionalTypeInfo(typeinfo_ptr, &mut info_ptr)?; nonNull(info_ptr)];
118+
119+
let mut contained_type: *mut ort_sys::OrtTypeInfo = std::ptr::null_mut();
120+
ortsys![unsafe GetOptionalContainedTypeInfo(info_ptr, &mut contained_type)?; nonNull(contained_type)];
121+
122+
ValueType::Optional(Box::new(ValueType::from_type_info(contained_type)?))
123+
}
113124
_ => unreachable!()
114125
};
115126
ortsys![unsafe ReleaseTypeInfo(typeinfo_ptr)];

0 commit comments

Comments
 (0)