pub fn mat_vec_mul(
    v: &mut Vector,
    alpha: f64,
    a: &Matrix,
    u: &Vector
) -> Result<(), StrError>
Expand description

Performs the matrix-vector multiplication resulting in a vector

 v  :=  α ⋅  a   ⋅  u
(m)        (m,n)   (n)

Note

The length of vector u must equal the number of columns of matrix a and the length of vector v must equal the number of rows of matrix a.

Example

use russell_lab::{mat_vec_mul, Matrix, Vector, StrError};

fn main() -> Result<(), StrError> {
    let a = Matrix::from(&[
        [ 5.0, -2.0, 1.0],
        [-4.0,  0.0, 2.0],
        [15.0, -6.0, 0.0],
        [ 3.0,  5.0, 1.0],
    ]);
    let u = Vector::from(&[1.0, 2.0, 3.0]);
    let mut v = Vector::new(a.nrow());
    mat_vec_mul(&mut v, 0.5, &a, &u)?;
    let correct = "┌     ┐\n\
                   │   2 │\n\
                   │   1 │\n\
                   │ 1.5 │\n\
                   │   8 │\n\
                   └     ┘";
    assert_eq!(format!("{}", v), correct);
    Ok(())
}