1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
// local imports use matrix::matrix::Matrix; use matrix::traits::*; use algebra::structure::MagmaBase; /// Implements matrix conversion API impl <T:MagmaBase> Conversion<T> for Matrix<T> { /// Converts the matrix to vector from standard library fn to_std_vec(&self) -> Vec<T> { let mut vec: Vec<T> = Vec::with_capacity(self.num_cells()); // We iterate over elements in matrix and push in the vector let ptr = self.as_ptr(); for c in 0..self.num_cols(){ for r in 0..self.num_rows(){ let offset = self.cell_to_offset(r, c); vec.push(unsafe{*ptr.offset(offset)}); } } vec } }