pub enum ValueType {
Tensor {
ty: TensorElementType,
shape: Shape,
dimension_symbols: SymbolicDimensions,
},
Sequence(Box<ValueType>),
Map {
key: TensorElementType,
value: TensorElementType,
},
Optional(Box<ValueType>),
}Expand description
The type of a Value, or a session input/output.
// `ValueType`s can be obtained from session inputs/outputs:
let input = &session.inputs()[0];
assert_eq!(
input.dtype(),
&ValueType::Tensor {
ty: TensorElementType::Float32,
// Our model's input has 3 dynamic dimensions, represented by -1
shape: Shape::new([-1, -1, -1, 3]),
// Dynamic dimensions may also have names.
dimension_symbols: SymbolicDimensions::new([
"unk__31".to_string(),
"unk__32".to_string(),
"unk__33".to_string(),
String::default()
])
}
);
// ...or by `Value`s created in Rust or output by a session.
let value = Tensor::from_array(([5usize], vec![1_i64, 2, 3, 4, 5].into_boxed_slice()))?;
assert_eq!(
value.dtype(),
&ValueType::Tensor {
ty: TensorElementType::Int64,
shape: Shape::new([5]),
dimension_symbols: SymbolicDimensions::new([String::default()])
}
);Variants§
Tensor
Value is a tensor/multi-dimensional array.
Fields
§
ty: TensorElementTypeElement type of the tensor.
§
dimension_symbols: SymbolicDimensionsSequence(Box<ValueType>)
A sequence (vector) of other Values.
Per ONNX spec, only sequences of tensors and maps are allowed.
Map
A map/dictionary from one element type to another.
Optional(Box<ValueType>)
An optional value, which may or may not contain a Value.
Implementations§
Source§impl ValueType
impl ValueType
Sourcepub fn tensor_shape(&self) -> Option<&Shape>
pub fn tensor_shape(&self) -> Option<&Shape>
Returns the shape of this value type if it is a tensor, or None if it is a sequence or map.
let value: DynValue = Tensor::from_array(([5usize], vec![1_i64, 2, 3, 4, 5].into_boxed_slice()))?.into_dyn();
let shape = value.dtype().tensor_shape().unwrap();
assert_eq!(**shape, [5]);Sourcepub fn tensor_type(&self) -> Option<TensorElementType>
pub fn tensor_type(&self) -> Option<TensorElementType>
Returns the element type of this value type if it is a tensor, or None if it is a sequence or map.
let value = Tensor::from_array(([5usize], vec![1_i64, 2, 3, 4, 5].into_boxed_slice()))?;
assert_eq!(value.dtype().tensor_type(), Some(TensorElementType::Int64));Sourcepub fn is_sequence(&self) -> bool
pub fn is_sequence(&self) -> bool
Returns true if this value type is a sequence.
Trait Implementations§
impl Eq for ValueType
impl StructuralPartialEq for ValueType
Auto Trait Implementations§
impl Freeze for ValueType
impl RefUnwindSafe for ValueType
impl Send for ValueType
impl Sync for ValueType
impl Unpin for ValueType
impl UnsafeUnpin for ValueType
impl UnwindSafe for ValueType
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more