use multi_ranged::Step;
use num_traits::AsPrimitive;
use super::{Matrix2D, SparseMatrix2D, SymmetricMatrix2D};
use crate::traits::PositiveInteger;
pub trait SquareMatrix: Matrix2D<RowIndex = Self::Index, ColumnIndex = Self::Index> {
type Index: Step + PositiveInteger + AsPrimitive<usize>;
fn order(&self) -> Self::Index;
}
impl<M: SquareMatrix> SquareMatrix for &M {
type Index = M::Index;
#[inline]
fn order(&self) -> Self::Index {
(*self).order()
}
}
pub trait SparseSquareMatrix: SquareMatrix + SparseMatrix2D {
fn number_of_defined_diagonal_values(&self) -> Self::Index;
#[inline]
fn is_symmetric(&self) -> bool {
self.row_indices().all(|row| {
self.sparse_row(row).all(|column| row == column || self.has_entry(column, row))
})
}
}
impl<M: SparseSquareMatrix> SparseSquareMatrix for &M {
#[inline]
fn number_of_defined_diagonal_values(&self) -> Self::Index {
(*self).number_of_defined_diagonal_values()
}
#[inline]
fn is_symmetric(&self) -> bool {
(*self).is_symmetric()
}
}
pub trait Symmetrize<M: SymmetricMatrix2D>: SquareMatrix {
fn symmetrize(&self) -> M;
}