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
use crate::matrix::Matrix;

use super::{LinearOp, Op};

pub struct MatrixOp<M: Matrix> {
    m: M,
}

impl<M: Matrix> MatrixOp<M> {
    pub fn new(m: M) -> Self {
        Self { m }
    }
}

impl<M: Matrix> Op for MatrixOp<M> {
    type V = M::V;
    type T = M::T;
    type M = M;
    fn nstates(&self) -> usize {
        self.m.nrows()
    }
    fn nout(&self) -> usize {
        self.m.ncols()
    }
    fn nparams(&self) -> usize {
        0
    }
    fn sparsity(&self) -> Option<&<Self::M as Matrix>::Sparsity> {
        self.m.sparsity()
    }
}

impl<M: Matrix> LinearOp for MatrixOp<M> {
    fn gemv_inplace(&self, x: &Self::V, t: Self::T, beta: Self::T, y: &mut Self::V) {
        self.m.gemv(t, x, beta, y);
    }
}