pub trait MatrixShape {
fn nrows(&self) -> usize;
fn ncols(&self) -> usize;
}
pub trait MatVec<V>: MatrixShape {
fn matvec(&self, x: &V) -> V;
}
pub trait MatVecInto<X, Y = X>: MatrixShape {
fn matvec_into(&self, x: &X, out: &mut Y);
}
pub trait MatTransposeVec<V>: MatrixShape {
fn mat_transpose_vec(&self, x: &V) -> V;
}
pub trait MatTransposeVecInto<X, Y = X>: MatrixShape {
fn mat_transpose_vec_into(&self, x: &X, out: &mut Y);
}
impl<M: MatrixShape + ?Sized> MatrixShape for &M {
fn nrows(&self) -> usize {
(**self).nrows()
}
fn ncols(&self) -> usize {
(**self).ncols()
}
}
impl<M, V> MatVec<V> for &M
where
M: MatVec<V> + ?Sized,
{
fn matvec(&self, x: &V) -> V {
(**self).matvec(x)
}
}
impl<M, X, Y> MatVecInto<X, Y> for &M
where
M: MatVecInto<X, Y> + ?Sized,
{
fn matvec_into(&self, x: &X, out: &mut Y) {
(**self).matvec_into(x, out);
}
}
impl<M, V> MatTransposeVec<V> for &M
where
M: MatTransposeVec<V> + ?Sized,
{
fn mat_transpose_vec(&self, x: &V) -> V {
(**self).mat_transpose_vec(x)
}
}
impl<M, X, Y> MatTransposeVecInto<X, Y> for &M
where
M: MatTransposeVecInto<X, Y> + ?Sized,
{
fn mat_transpose_vec_into(&self, x: &X, out: &mut Y) {
(**self).mat_transpose_vec_into(x, out);
}
}