Function mosek::gemm

source ·
pub fn gemm(
    transa_: i32,
    transb_: i32,
    m_: i32,
    n_: i32,
    k_: i32,
    alpha_: f64,
    a_: &[f64],
    b_: &[f64],
    beta_: f64,
    c_: &mut [f64]
) -> Result<(), String>
Expand description

Performs a dense matrix multiplication.

§Arguments

  • transa_ Indicates whether the matrix A must be transposed.

    See Transpose

  • transb_ Indicates whether the matrix B must be transposed.

    See Transpose

  • m_ Indicates the number of rows of matrix C.

  • n_ Indicates the number of columns of matrix C.

  • k_ Specifies the common dimension along which op(A) and op(B) are multiplied.

  • alpha_ A scalar value multiplying the result of the matrix multiplication.

  • a_ The pointer to the array storing matrix A in a column-major format.

  • b_ The pointer to the array storing matrix B in a column-major format.

  • beta_ A scalar value that multiplies C.

  • c_ The pointer to the array storing matrix C in a column-major format.

Full documentation: https://docs.mosek.com/latest/capi/alphabetic-functionalities.html#mosek.env.gemm

Examples found in repository?
examples/portfolio_6_factor.rs (lines 269-278)
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
    pub fn mul(&self,other : &Matrix) -> Option<Matrix> {
        if self.dimj != other.dimi { None }
        else {
            let mut resdata = vec![0.0; self.dimi * other.dimj];
            if let Ok(_) = mosek::gemm(match self.fmt { MatrixOrder::ByCol => Transpose::NO, MatrixOrder::ByRow => Transpose::YES },
                                       match other.fmt { MatrixOrder::ByCol => Transpose::NO, MatrixOrder::ByRow => Transpose::YES },
                                       self.dimi.try_into().unwrap(),
                                       other.dimj.try_into().unwrap(),
                                       self.dimj.try_into().unwrap(),
                                       1.0,
                                       self.data.as_slice(),
                                       other.data.as_slice(),
                                       1.0,
                                       resdata.as_mut_slice()) {
                Matrix::new_by_col(self.dimi,other.dimj,resdata)
            }
            else {
                None
            }
        }
    }
More examples
Hide additional examples
examples/blas_lapack.rs (line 62)
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
fn main() -> Result<(),String> {

    let n = 3i32;
    let m = 2i32;
    let k = 3i32;

    let alpha = 2.0;
    let beta  = 0.5;
    let x    = &[1.0, 1.0, 1.0];
    let mut y = vec![1.0, 2.0, 3.0];
    let mut z = vec![1.0, 1.0];
    let A    = &[1.0, 1.0, 2.0, 2.0, 3.0, 3.0];
    let B    = &[1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0];
    let mut C = vec![1.0, 2.0, 3.0, 4.0, 5.0, 6.0];
    let mut D = vec![1.0, 1.0, 1.0, 1.0];
    let mut Q = vec![1.0, 0.0, 0.0, 2.0];
    let mut v = vec![0.0, 0.0, 0.0];

    let mut xy : f64 = 0.0;

    /* BLAS routines*/
    println!("n={} m={} k={}", m, n, k);
    println!("alpha={}", alpha);
    println!("beta={}", beta);

    mosek::dot(n,x,y.as_slice(),& mut xy)?;
    println!("dot results = {}\n", xy);

    print_matrix(x, 1, n);
    print_matrix(y.as_slice(), 1, n);

    mosek::axpy(n, alpha, x, y.as_mut_slice())?;
    println!("axpy results is:\n");
    print_matrix(y.as_slice(), 1, n);


    mosek::gemv(mosek::Transpose::NO, m, n, alpha, A, x, beta, z.as_mut_slice())?;
    println!("gemv results is:");
    print_matrix(z.as_slice(), 1, m);

    mosek::gemm(mosek::Transpose::NO, mosek::Transpose::NO, m, n, k, alpha, A, B, beta, C.as_mut_slice())?;
    println!("gemm results is");
    print_matrix(C.as_slice(), m, n);

    mosek::syrk(mosek::Uplo::LO, mosek::Transpose::NO, m, k, 1., A, beta, D.as_mut_slice())?;
    println!("syrk results is");
    print_matrix(D.as_slice(), m, m);

    /* LAPACK routines*/

    mosek::potrf(mosek::Uplo::LO, m, Q.as_mut_slice())?;
    println!("potrf results is");
    print_matrix(Q.as_slice(), m, m);

    mosek::syeig(mosek::Uplo::LO, m, Q.as_slice(), & mut v[0..m as usize])?;
    println!("syeig results is");
    print_matrix(v.as_slice(), 1, m);

    mosek::syevd(mosek::Uplo::LO, m, Q.as_mut_slice(), &mut v[0..m as usize])?;
    println!("syevd results is");
    print_matrix(v.as_slice(), 1, m);
    print_matrix(Q.as_slice(), m, m);

    Ok(())
}