use ndarray::ArrayD;
#[derive(Debug, Clone, PartialEq)]
pub enum InferenceTensor {
F32(ArrayD<f32>),
I64(ArrayD<i64>),
I32(ArrayD<i32>),
U8(ArrayD<u8>),
Bool(ArrayD<bool>),
}
impl InferenceTensor {
#[allow(dead_code)]
pub fn as_f32(&self) -> Option<&ArrayD<f32>> {
match self {
Self::F32(array) => Some(array),
_ => None,
}
}
}
impl From<ArrayD<f32>> for InferenceTensor {
fn from(array: ArrayD<f32>) -> Self {
Self::F32(array)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn as_f32_returns_payload_for_f32_and_none_otherwise() {
let f32_tensor: InferenceTensor = ndarray::arr1(&[1.0f32, 2.0]).into_dyn().into();
assert_eq!(f32_tensor.as_f32().unwrap(), &ndarray::arr1(&[1.0f32, 2.0]).into_dyn());
let i64_tensor = InferenceTensor::I64(ndarray::arr1(&[1i64, 2]).into_dyn());
assert!(i64_tensor.as_f32().is_none());
}
}