Function mosek::potrf

source ·
pub fn potrf(uplo_: i32, n_: i32, a_: &mut [f64]) -> Result<(), String>
Expand description

Computes a Cholesky factorization of a dense matrix.

§Arguments

  • uplo_ Indicates whether the upper or lower triangular part of the matrix is stored.

    See Uplo

  • n_ Dimension of the symmetric matrix.

  • a_ A symmetric matrix stored in column-major order.

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

Examples found in repository?
examples/portfolio_6_factor.rs (lines 256-258)
250
251
252
253
254
255
256
257
258
259
260
261
262
263
    pub fn cholesky(&self) -> Option<Matrix> {
        if self.dimi != self.dimj { None }
        else {
            let mut resdata = self.data_by_col();
            // zero data in the non-tril part
            for ((j,i),d) in iproduct!(0..self.dimj,0..self.dimi).zip(resdata.iter_mut()) { if i < j {*d = 0.0}; }
            if let Ok(_) = mosek::potrf(mosek::Uplo::LO,
                                        self.dimi.try_into().unwrap(),
                                        resdata.as_mut_slice()) {
                Some(Matrix{fmt:MatrixOrder::ByCol,dimi:self.dimi,dimj:self.dimj,data:resdata})
            }
            else { None }
        }
    }
More examples
Hide additional examples
examples/blas_lapack.rs (line 72)
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(())
}