Function russell_lab::outer[][src]

pub fn outer(
    a: &mut Matrix,
    alpha: f64,
    u: &Vector,
    v: &Vector
) -> Result<(), &'static str>
Expand description

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

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

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

Example

use russell_lab::*;
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());
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);