1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
use crate::matrix::Matrix; use crate::number::Number; use std::{fmt::Debug, mem::transmute}; pub trait Type: Clone + Copy + Debug + Default + Send + Sync {} #[derive(Clone, Copy, Debug, Default)] pub struct Standard; #[derive(Clone, Copy, Debug, Default)] pub struct Square; #[derive(Clone, Copy, Debug, Default)] pub struct UpperTriangle; #[derive(Clone, Copy, Debug, Default)] pub struct LowerTriangle; #[derive(Clone, Copy, Debug, Default)] pub struct Diagonal; #[derive(Clone, Copy, Debug, Default)] pub struct PositiveDefinite; #[derive(Clone, Copy, Debug, Default)] pub struct PositiveSemiDefinite; impl Type for Standard {} impl Type for Square {} impl Type for UpperTriangle {} impl Type for LowerTriangle {} impl Type for Diagonal {} impl Type for PositiveDefinite {} impl Type for PositiveSemiDefinite {} impl<T, U> Matrix<T, U> where T: Type, U: Number, { pub fn transmute<V: Type>(self) -> Matrix<V, U> { unsafe { transmute::<Self, Matrix<V, U>>(self) } } pub fn transmute_ref<V: Type>(&self) -> &Matrix<V, U> { unsafe { transmute::<&Self, &Matrix<V, U>>(self) } } }