github.com/jingcheng-WU/gonum@v0.9.1-0.20210323123734-f1a2a11a8f7b/lapack/gonum/dpotrf.go (about) 1 // Copyright ©2015 The Gonum Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package gonum 6 7 import ( 8 "github.com/jingcheng-WU/gonum/blas" 9 "github.com/jingcheng-WU/gonum/blas/blas64" 10 ) 11 12 // Dpotrf computes the Cholesky decomposition of the symmetric positive definite 13 // matrix a. If ul == blas.Upper, then a is stored as an upper-triangular matrix, 14 // and a = Uᵀ U is stored in place into a. If ul == blas.Lower, then a = L Lᵀ 15 // is computed and stored in-place into a. If a is not positive definite, false 16 // is returned. This is the blocked version of the algorithm. 17 func (impl Implementation) Dpotrf(ul blas.Uplo, n int, a []float64, lda int) (ok bool) { 18 switch { 19 case ul != blas.Upper && ul != blas.Lower: 20 panic(badUplo) 21 case n < 0: 22 panic(nLT0) 23 case lda < max(1, n): 24 panic(badLdA) 25 } 26 27 // Quick return if possible. 28 if n == 0 { 29 return true 30 } 31 32 if len(a) < (n-1)*lda+n { 33 panic(shortA) 34 } 35 36 nb := impl.Ilaenv(1, "DPOTRF", string(ul), n, -1, -1, -1) 37 if nb <= 1 || n <= nb { 38 return impl.Dpotf2(ul, n, a, lda) 39 } 40 bi := blas64.Implementation() 41 if ul == blas.Upper { 42 for j := 0; j < n; j += nb { 43 jb := min(nb, n-j) 44 bi.Dsyrk(blas.Upper, blas.Trans, jb, j, 45 -1, a[j:], lda, 46 1, a[j*lda+j:], lda) 47 ok = impl.Dpotf2(blas.Upper, jb, a[j*lda+j:], lda) 48 if !ok { 49 return ok 50 } 51 if j+jb < n { 52 bi.Dgemm(blas.Trans, blas.NoTrans, jb, n-j-jb, j, 53 -1, a[j:], lda, a[j+jb:], lda, 54 1, a[j*lda+j+jb:], lda) 55 bi.Dtrsm(blas.Left, blas.Upper, blas.Trans, blas.NonUnit, jb, n-j-jb, 56 1, a[j*lda+j:], lda, 57 a[j*lda+j+jb:], lda) 58 } 59 } 60 return true 61 } 62 for j := 0; j < n; j += nb { 63 jb := min(nb, n-j) 64 bi.Dsyrk(blas.Lower, blas.NoTrans, jb, j, 65 -1, a[j*lda:], lda, 66 1, a[j*lda+j:], lda) 67 ok := impl.Dpotf2(blas.Lower, jb, a[j*lda+j:], lda) 68 if !ok { 69 return ok 70 } 71 if j+jb < n { 72 bi.Dgemm(blas.NoTrans, blas.Trans, n-j-jb, jb, j, 73 -1, a[(j+jb)*lda:], lda, a[j*lda:], lda, 74 1, a[(j+jb)*lda+j:], lda) 75 bi.Dtrsm(blas.Right, blas.Lower, blas.Trans, blas.NonUnit, n-j-jb, jb, 76 1, a[j*lda+j:], lda, 77 a[(j+jb)*lda+j:], lda) 78 } 79 } 80 return true 81 }