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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
//! A sparse implementation of a binary matrix optimized for row operations. //! //! The main objects of this crate are [`matrices`](crate::SparseBinMat) and [`vectors`](crate::SparseBinVecBase). //! All elements in a binary matrix or vector are element of the binary field GF2. //! That is, they are either 0 or 1 and addition is modulo 2. //! //! # Quick start //! //! To instanciate a matrix, you need to specify the number of columns as well //! as the position of 1 in each rows. //! //! ``` //! use sparse_bin_mat::SparseBinMat; //! //! // This is the matrix //! // 1 0 1 0 1 //! // 0 1 0 1 0 //! // 0 0 1 0 0 //! let matrix = SparseBinMat::new(5, vec![vec![0, 2, 4], vec![1, 3], vec![2]]); //! ``` //! //! It is easy to access elements or rows of a matrix. However, //! since the matrix are optimized for row operations, you need //! to transpose the matrix if you want to perform column operations. //! //! ``` //! # use sparse_bin_mat::SparseBinMat; //! let matrix = SparseBinMat::new(5, vec![vec![0, 2, 4], vec![1, 3], vec![2]]); //! assert_eq!(matrix.row(1).unwrap().as_slice(), [1, 3].as_ref()); //! assert_eq!(matrix.get(0, 0), Some(1)); //! assert_eq!(matrix.get(0, 1), Some(0)); //! // The element (0, 7) is out of bound for a 3 x 5 matrix. //! assert_eq!(matrix.get(0, 7), None); //! ``` //! //! Adition and multiplication are implemented between matrix references. //! //! ``` //! # use sparse_bin_mat::SparseBinMat; //! let matrix = SparseBinMat::new(3, vec![vec![0, 1], vec![1, 2], vec![0, 2]]); //! let identity = SparseBinMat::identity(3); //! //! let sum = SparseBinMat::new(3, vec![vec![1], vec![2], vec![0]]); //! assert_eq!(&matrix + &identity, sum); //! //! assert_eq!(&matrix * &identity, matrix); //! ``` //! //! Many useful operations and decompositions are implemented. //! These include, but are not limited to //! - [`rank`](SparseBinMat::rank), //! - [`echelon form`](SparseBinMat::echelon_form), //! - [`nullspace`](SparseBinMat::nullspace), //! - [`tranposition`](SparseBinMat::transposed), //! - [`horizontal`](SparseBinMat::horizontal_concat_with) and //! [`vertical`](SparseBinMat::vertical_concat_with) concatenations, //! - and more ... //! //! Operations are implemented as I need them, //! feel welcome to raise an issue if you need a new functionnality. mod matrix; pub use matrix::{Rows, SparseBinMat}; mod vector; pub use vector::{SparseBinSlice, SparseBinVec, SparseBinVecBase}; type BinaryNumber = u8;