use super::{
BiMatrix2D, SizedSparseBiMatrix2D, SparseMatrix2D, SparseValuedMatrix2D, SymmetricMatrix2D,
ValuedMatrix, ValuedMatrix2D,
};
use crate::traits::TotalOrd;
pub trait ValuedBiMatrix2D:
BiMatrix2D<
Matrix = <Self as ValuedBiMatrix2D>::ValuedMatrix,
TransposedMatrix = <Self as ValuedBiMatrix2D>::ValuedTransposedMatrix,
> + ValuedMatrix2D
{
type ValuedMatrix: ValuedMatrix2D<
RowIndex = Self::RowIndex,
ColumnIndex = Self::ColumnIndex,
Value = Self::Value,
>;
type ValuedTransposedMatrix: ValuedMatrix2D<
RowIndex = Self::ColumnIndex,
ColumnIndex = Self::RowIndex,
Value = Self::Value,
>;
}
pub trait ValuedSizedSparseBiMatrix2D:
ValuedBiMatrix2D<
ValuedMatrix = <Self as ValuedSizedSparseBiMatrix2D>::ValuedSparseMatrix,
ValuedTransposedMatrix = <Self as ValuedSizedSparseBiMatrix2D>::ValuedSparseTransposedMatrix,
> + SizedSparseBiMatrix2D<
SizedSparseMatrix = <Self as ValuedSizedSparseBiMatrix2D>::ValuedSparseMatrix,
SizedSparseTransposedMatrix = <Self as ValuedSizedSparseBiMatrix2D>::ValuedSparseTransposedMatrix,
>
{
type ValuedSparseMatrix: SparseValuedMatrix2D<
RowIndex = Self::RowIndex,
ColumnIndex = Self::ColumnIndex,
Value = Self::Value,
>;
type ValuedSparseTransposedMatrix: SparseValuedMatrix2D<
RowIndex = Self::ColumnIndex,
ColumnIndex = Self::RowIndex,
Value = Self::Value,
>;
#[inline]
fn sparse_column_max_value(
&self,
column: Self::ColumnIndex,
) -> Option<<Self as ValuedMatrix>::Value>
where
Self::Value: TotalOrd,
{
self.sparse_column_values(column).max_by(TotalOrd::total_cmp)
}
#[inline]
fn sparse_column_min_value(&self, column: Self::ColumnIndex) -> Option<Self::Value>
where
Self::Value: TotalOrd,
{
self.sparse_column_values(column).min_by(TotalOrd::total_cmp)
}
#[inline]
fn sparse_column_values(
&self,
column: Self::ColumnIndex,
) -> <Self::ValuedSparseTransposedMatrix as SparseValuedMatrix2D>::SparseRowValues<'_> {
self.transposed().sparse_row_values(column)
}
}
impl<M> ValuedSizedSparseBiMatrix2D for M
where
M: ValuedBiMatrix2D
+ SizedSparseBiMatrix2D<
SizedSparseMatrix = <M as ValuedBiMatrix2D>::ValuedMatrix,
SizedSparseTransposedMatrix = <M as ValuedBiMatrix2D>::ValuedTransposedMatrix,
>,
M::ValuedMatrix: SparseValuedMatrix2D<
RowIndex = Self::RowIndex,
ColumnIndex = Self::ColumnIndex,
SparseIndex = Self::SparseIndex,
Value = Self::Value,
>,
M::ValuedTransposedMatrix: SparseValuedMatrix2D<
RowIndex = Self::ColumnIndex,
ColumnIndex = Self::RowIndex,
SparseIndex = Self::SparseIndex,
Value = Self::Value,
>,
{
type ValuedSparseMatrix = M::ValuedMatrix;
type ValuedSparseTransposedMatrix = M::ValuedTransposedMatrix;
}
pub trait SymmetricValuedMatrix2D:
SymmetricMatrix2D<SymmetricMatrix = <Self as SymmetricValuedMatrix2D>::SymmetricValuedMatrix>
+ ValuedBiMatrix2D<
ValuedMatrix = <Self as SymmetricValuedMatrix2D>::SymmetricValuedMatrix,
ValuedTransposedMatrix = <Self as SymmetricValuedMatrix2D>::SymmetricValuedMatrix,
>
{
type SymmetricValuedMatrix: ValuedMatrix2D<
RowIndex = Self::RowIndex,
ColumnIndex = Self::ColumnIndex,
Value = Self::Value,
>;
}
impl<M> SymmetricValuedMatrix2D for M
where
M: SymmetricMatrix2D
+ ValuedBiMatrix2D<
ValuedMatrix = <M as SymmetricMatrix2D>::SymmetricMatrix,
ValuedTransposedMatrix = <M as SymmetricMatrix2D>::SymmetricMatrix,
>,
M::SymmetricMatrix: ValuedMatrix2D<
RowIndex = Self::RowIndex,
ColumnIndex = Self::ColumnIndex,
Value = Self::Value,
>,
{
type SymmetricValuedMatrix = M::SymmetricMatrix;
}
pub trait SparseSymmetricValuedMatrix2D:
SymmetricValuedMatrix2D<
SymmetricValuedMatrix = <Self as SparseSymmetricValuedMatrix2D>::SymmetricSparseValuedMatrix,
>
{
type SymmetricSparseValuedMatrix: SparseValuedMatrix2D<
RowIndex = Self::RowIndex,
ColumnIndex = Self::ColumnIndex,
Value = Self::Value,
>;
}
impl<M> SparseSymmetricValuedMatrix2D for M
where
M: SymmetricValuedMatrix2D + SparseMatrix2D,
M::SymmetricValuedMatrix: SparseValuedMatrix2D<
RowIndex = Self::RowIndex,
ColumnIndex = Self::ColumnIndex,
Value = Self::Value,
>,
{
type SymmetricSparseValuedMatrix = M::SymmetricValuedMatrix;
}