pub fn cast_to_dt(&self, dt: DatumType) -> TractResult<Cow<Tensor>> {
        use DatumType::*;
        if self.dt == dt {
            return Ok(Cow::Borrowed(self));
        }
        let target = match (self.dt, dt) {
            (TDim, I32) => self.cast::<crate::dim::TDim, i32>()?,
            (TDim, I64) => self.cast::<crate::dim::TDim, i64>()?,
            (I32, TDim) => self.cast::<i32, crate::dim::TDim>()?,
            (I64, TDim) => self.cast::<i64, crate::dim::TDim>()?,

            (F16, F32) => self.cast::<f16, f32>()?,
            (F32, F16) => self.cast::<f32, f16>()?,
            (F16, F64) => self.cast::<f16, f64>()?,
            (F64, F16) => self.cast::<f64, f16>()?,
            (F32, F64) => self.cast::<f32, f64>()?,
            (F64, F32) => self.cast::<f64, f32>()?,

            (I8, I16) => self.cast::<i8, i16>()?,
            (I16, I8) => self.cast::<i16, i8>()?,
            (I8, I32) => self.cast::<i8, i32>()?,
            (I32, I8) => self.cast::<i32, i8>()?,
            (I8, I64) => self.cast::<i8, i64>()?,
            (I64, I8) => self.cast::<i64, i8>()?,
            (I16, I32) => self.cast::<i16, i32>()?,
            (I32, I16) => self.cast::<i32, i16>()?,
            (I16, I64) => self.cast::<i16, i64>()?,
            (I64, I16) => self.cast::<i64, i16>()?,
            (I32, I64) => self.cast::<i32, i64>()?,
            (I64, I32) => self.cast::<i64, i32>()?,

            (Bool, F32) => self.cast::<bool, f32>()?,
            (I8, F32) => self.cast::<i8, f32>()?,
            (I16, F32) => self.cast::<i16, f32>()?,
            (I32, F32) => self.cast::<i32, f32>()?,
            (I64, F32) => self.cast::<i64, f32>()?,

            (F32, String) => self.cast::<f32, std::string::String>()?,
            (String, F32) => self.cast::<std::string::String, f32>()?,

            _ => bail!("Unsupported cast from {:?} to {:?}", self.dt, dt),
        };
        Ok(Cow::Owned(target))
    }
/// Optionnaly convert data to a tensor for a new DatumType.
Optionnaly convert data to a tensor for a new DatumType.
Optionnaly convert data to a tensor for a new DatumType .
pub fn cast_to_dt(&self, dt: DatumType) -> TractResult<Cow<Tensor>> {
        use DatumType::*;
        if self.dt == dt {
            return Ok(Cow::Borrowed(self));
        }
        let target = match (self.dt, dt) {
            (TDim, I32) => self.cast::<crate::dim::TDim, i32>()?,
            (TDim, I64) => self.cast::<crate::dim::TDim, i64>()?,
            (I32, TDim) => self.cast::<i32, crate::dim::TDim>()?,
            (I64, TDim) => self.cast::<i64, crate::dim::TDim>()?,
            (F16, F32) => self.cast::<f16, f32>()?,
            (F32, F16) => self.cast::<f32, f16>()?,
            (F16, F64) => self.cast::<f16, f64>()?,
            (F64, F16) => self.cast::<f64, f16>()?,
            (F32, F64) => self.cast::<f32, f64>()?,
            (F64, F32) => self.cast::<f64, f32>()?,
            (I8, I16) => self.cast::<i8, i16>()?,
            (I16, I8) => self.cast::<i16, i8>()?,
            (I8, I32) => self.cast::<i8, i32>()?,
            (I32, I8) => self.cast::<i32, i8>()?,
            (I8, I64) => self.cast::<i8, i64>()?,
            (I64, I8) => self.cast::<i64, i8>()?,
            (I16, I32) => self.cast::<i16, i32>()?,
            (I32, I16) => self.cast::<i32, i16>()?,
            (I16, I64) => self.cast::<i16, i64>()?,
            (I64, I16) => self.cast::<i64, i16>()?,
            (I32, I64) => self.cast::<i32, i64>()?,
            (I64, I32) => self.cast::<i64, i32>()?,
            (Bool, F32) => self.cast::<bool, f32>()?,
            (I8, F32) => self.cast::<i8, f32>()?,
            (I16, F32) => self.cast::<i16, f32>()?,
            (I32, F32) => self.cast::<i32, f32>()?,
            (I64, F32) => self.cast::<i64, f32>()?,
            (F32, String) => self.cast::<f32, std::string::String>()?,
            (String, F32) => self.cast::<std::string::String, f32>()?,
            _ => bail!("Unsupported cast from {:?} to {:?}", self.dt, dt),
        };
        Ok(Cow::Owned(target))
    }
pub fn cast_to_dt ( & self , dt : DatumType ) -> TractResult < Cow < Tensor > > { use DatumType :: * ; if self . dt == dt { return Ok ( Cow :: Borrowed ( self ) ) ; } let target = match ( self . dt , dt ) { ( TDim , I32 ) => self . cast :: < crate :: dim :: TDim , i32 > ( ) ? , ( TDim , I64 ) => self . cast :: < crate :: dim :: TDim , i64 > ( ) ? , ( I32 , TDim ) => self . cast :: < i32 , crate :: dim :: TDim > ( ) ? , ( I64 , TDim ) => self . cast :: < i64 , crate :: dim :: TDim > ( ) ? , ( F16 , F32 ) => self . cast :: < f16 , f32 > ( ) ? , ( F32 , F16 ) => self . cast :: < f32 , f16 > ( ) ? , ( F16 , F64 ) => self . cast :: < f16 , f64 > ( ) ? , ( F64 , F16 ) => self . cast :: < f64 , f16 > ( ) ? , ( F32 , F64 ) => self . cast :: < f32 , f64 > ( ) ? , ( F64 , F32 ) => self . cast :: < f64 , f32 > ( ) ? , ( I8 , I16 ) => self . cast :: < i8 , i16 > ( ) ? , ( I16 , I8 ) => self . cast :: < i16 , i8 > ( ) ? , ( I8 , I32 ) => self . cast :: < i8 , i32 > ( ) ? , ( I32 , I8 ) => self . cast :: < i32 , i8 > ( ) ? , ( I8 , I64 ) => self . cast :: < i8 , i64 > ( ) ? , ( I64 , I8 ) => self . cast :: < i64 , i8 > ( ) ? , ( I16 , I32 ) => self . cast :: < i16 , i32 > ( ) ? , ( I32 , I16 ) => self . cast :: < i32 , i16 > ( ) ? , ( I16 , I64 ) => self . cast :: < i16 , i64 > ( ) ? , ( I64 , I16 ) => self . cast :: < i64 , i16 > ( ) ? , ( I32 , I64 ) => self . cast :: < i32 , i64 > ( ) ? , ( I64 , I32 ) => self . cast :: < i64 , i32 > ( ) ? , ( Bool , F32 ) => self . cast :: < bool , f32 > ( ) ? , ( I8 , F32 ) => self . cast :: < i8 , f32 > ( ) ? , ( I16 , F32 ) => self . cast :: < i16 , f32 > ( ) ? , ( I32 , F32 ) => self . cast :: < i32 , f32 > ( ) ? , ( I64 , F32 ) => self . cast :: < i64 , f32 > ( ) ? , ( F32 , String ) => self . cast :: < f32 , std :: string :: String > ( ) ? , ( String , F32 ) => self . cast :: < std :: string :: String , f32 > ( ) ? , _ => bail ! ( " " self dt dt ) , } ; Ok ( Cow :: Owned ( target ) ) }
Optionnaly convert data to a tensor for a new DatumType.
Optionnaly convert data to a tensor for a new DatumType .
&self
dt
DatumType
&self
dt
DatumType