use super::{LowerBoundedSquareMatrix, lower_bounded_sparse_row::LowerBoundedSparseRow};
use crate::{
impls::{CSR2DColumns, CSR2DRows},
traits::{SparseMatrix, SparseMatrix2D, SquareMatrix},
};
impl<M> SparseMatrix for LowerBoundedSquareMatrix<M>
where
M: SquareMatrix + SparseMatrix2D,
{
type SparseIndex = usize;
type SparseCoordinates<'a>
= crate::impls::CSR2DView<'a, Self>
where
Self: 'a;
#[inline]
fn is_empty(&self) -> bool {
self.last_sparse_coordinates().is_none()
}
#[inline]
fn last_sparse_coordinates(&self) -> Option<Self::Coordinates> {
let (last_row, last_column) = self.matrix.last_sparse_coordinates()?;
if last_row < self.index || last_column < self.index {
return None;
}
Some((last_row, last_column))
}
#[inline]
fn sparse_coordinates(&self) -> Self::SparseCoordinates<'_> {
self.into()
}
}
impl<M> SparseMatrix2D for LowerBoundedSquareMatrix<M>
where
M: SquareMatrix + SparseMatrix2D,
{
type SparseRow<'a>
= LowerBoundedSparseRow<'a, M>
where
Self: 'a;
type SparseColumns<'a>
= CSR2DColumns<'a, Self>
where
Self: 'a;
type SparseRows<'a>
= CSR2DRows<'a, Self>
where
Self: 'a;
#[inline]
fn sparse_row(&self, row: Self::RowIndex) -> Self::SparseRow<'_> {
LowerBoundedSparseRow::new(self, row)
}
#[inline]
fn sparse_columns(&self) -> Self::SparseColumns<'_> {
self.into()
}
#[inline]
fn sparse_rows(&self) -> Self::SparseRows<'_> {
self.into()
}
}