Skip to main content

blas_dgemm

Function blas_dgemm 

Source
pub fn blas_dgemm(
    transpose_a: bool,
    transpose_b: bool,
    alpha: f64,
    a: &Matrix,
    b: &Matrix,
    beta: f64,
    c: Option<&Matrix>,
) -> Result<Matrix>
Expand description

Matrix-matrix product alpha * op(A) * op(B) + beta * C, where op(X) is X or its transpose (igraph_blas_dgemm). c may be None when beta is zero (or to mean a zero matrix).

igraph 1.0.0 and 1.0.1 check the shape of C against the wrong dimension when beta != 0; this wrapper validates the shapes itself and adds beta * C on the Rust side when igraph would reject a correct call.

Time complexity: O(nmk) for an n × k times k × m product.

Binds igraph_blas_dgemm.

§Examples

use igraph::{linalg::blas_dgemm, prelude::*};
let a = Matrix::from_rows(&[[1.0, 2.0, 3.0]]).unwrap(); // 1x3
let b = Matrix::from_rows(&[[1.0], [1.0], [1.0]]).unwrap(); // 3x1
let ab = blas_dgemm(false, false, 1.0, &a, &b, 0.0, None).unwrap();
assert_eq!(ab.to_rows(), vec![vec![6.0]]);
// The outer product B A is 3x3.
let ba = blas_dgemm(false, false, 1.0, &b, &a, 0.0, None).unwrap();
assert_eq!(ba.shape(), (3, 3));
// A' A with transposition flags.
let ata = blas_dgemm(true, false, 1.0, &a, &a, 0.0, None).unwrap();
assert_eq!(ata[(2, 1)], 6.0);