use std::fmt; use super::csc::CscMatrix; /// COOrdinate format (aka IJV, triplet format) #[derive(Clone, PartialEq, Eq)] pub struct CooMatrix { shape: (usize, usize), data: Vec, row: Vec, // COO format row index array of the matrix col: Vec // COO format column index array of the matrix } impl CooMatrix { pub fn new(shape: (usize,usize), data: Vec, ij: Vec<(usize,usize)>) -> Self { CooMatrix { shape: shape, data: data, row: ij.iter().map(|&(row,_col)| row).collect(), col: ij.iter().map(|&(_row,col)| col).collect() } } pub fn empty(shape: (usize,usize)) -> Self { CooMatrix { shape: shape, data: vec![], row: vec![], col: vec![] } } pub fn nnz(&self) -> usize { self.data.len() } pub fn shape(&self) -> (usize,usize) { self.shape } // converstion pub fn to_bsr(&self) -> () { unimplemented!() } pub fn to_coo(&self) -> Self { self.clone() } pub fn to_csc(&self) -> CscMatrix { unimplemented!() } } impl fmt::Display for CooMatrix { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { for i in 0 .. self.data.len() { try!(writeln!(f, " {:?}\t{}", (self.row[i], self.col[i]), self.data[i])); } Ok(()) } } #[test] fn test_coo() { }