MCPcopy Create free account
hub / github.com/Axect/Peroxide / block

Method block

src/complex/matrix.rs:2054–2087  ·  view source on GitHub ↗

Block Partition # Examples ```rust #[macro_use] extern crate peroxide; use peroxide::fuga::*; use peroxide::complex::matrix::*; let a = cmatrix(vec![ C64::new(1f64, 1f64), C64::new(2f64, 2f64), C64::new(3f64, 3f64), C64::new(4f64, 4f64) ], 2, 2, Row ); let (m1, m2, m3, m4) = a.block(); assert_eq!(m1, ml_cmatrix("1.0+1.0i")); assert_eq!(m2, ml_cmatrix("2.0+2.0i")); assert_eq!(m3, ml_cmatrix("3.0+

(&self)

Source from the content-addressed store, hash-verified

2052 /// assert_eq!(m4, ml_cmatrix("4.0+4.0i"));
2053 /// ```
2054 fn block(&self) -> (Self, Self, Self, Self) {
2055 let r = self.row;
2056 let c = self.col;
2057 let l_r = self.row / 2;
2058 let l_c = self.col / 2;
2059 let r_l = r - l_r;
2060 let c_l = c - l_c;
2061
2062 let mut m1 = cmatrix(vec![Complex::zero(); l_r * l_c], l_r, l_c, self.shape);
2063 let mut m2 = cmatrix(vec![Complex::zero(); l_r * c_l], l_r, c_l, self.shape);
2064 let mut m3 = cmatrix(vec![Complex::zero(); r_l * l_c], r_l, l_c, self.shape);
2065 let mut m4 = cmatrix(vec![Complex::zero(); r_l * c_l], r_l, c_l, self.shape);
2066
2067 for idx_row in 0..r {
2068 for idx_col in 0..c {
2069 match (idx_row, idx_col) {
2070 (i, j) if (i < l_r) && (j < l_c) => {
2071 m1[(i, j)] = self[(i, j)];
2072 }
2073 (i, j) if (i < l_r) && (j >= l_c) => {
2074 m2[(i, j - l_c)] = self[(i, j)];
2075 }
2076 (i, j) if (i >= l_r) && (j < l_c) => {
2077 m3[(i - l_r, j)] = self[(i, j)];
2078 }
2079 (i, j) if (i >= l_r) && (j >= l_c) => {
2080 m4[(i - l_r, j - l_c)] = self[(i, j)];
2081 }
2082 _ => (),
2083 }
2084 }
2085 }
2086 (m1, m2, m3, m4)
2087 }
2088
2089 /// Inverse of Matrix
2090 ///

Callers 2

complex_inv_lFunction · 0.45
complex_inv_uFunction · 0.45

Calls 1

cmatrixFunction · 0.85

Tested by

no test coverage detected