Function russell_lab::matvec::vec_outer

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

(dger) Performs the outer (tensor) product between two vectors resulting in a matrix

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

See also: https://www.netlib.org/lapack/explore-html/dc/da8/dger_8f.html

§Note

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

§Examples

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

fn main() -> Result<(), StrError> {
    let u = Vector::from(&[1.0, 2.0, 3.0]);
    let v = Vector::from(&[5.0, -2.0, 0.0, 1.0]);
    let mut a = Matrix::new(u.dim(), v.dim());
    vec_outer(&mut a, 1.0, &u, &v)?;
    let correct = "┌             ┐\n\
                   │  5 -2  0  1 │\n\
                   │ 10 -4  0  2 │\n\
                   │ 15 -6  0  3 │\n\
                   └             ┘";
    assert_eq!(format!("{}", a), correct);
    Ok(())
}