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.
8 "gonum.org/v1/gonum/blas"
9 "gonum.org/v1/gonum/blas/blas64"
12 // Dgetrf computes the LU decomposition of the m×n matrix A.
13 // The LU decomposition is a factorization of A into
15 // where P is a permutation matrix, L is a unit lower triangular matrix, and
16 // U is a (usually) non-unit upper triangular matrix. On exit, L and U are stored
19 // ipiv is a permutation vector. It indicates that row i of the matrix was
20 // changed with ipiv[i]. ipiv must have length at least min(m,n), and will panic
21 // otherwise. ipiv is zero-indexed.
23 // Dgetrf is the blocked version of the algorithm.
25 // Dgetrf returns whether the matrix A is singular. The LU decomposition will
26 // be computed regardless of the singularity of A, but division by zero
27 // will occur if the false is returned and the result is used to solve a
28 // system of equations.
29 func (impl Implementation) Dgetrf(m, n int, a []float64, lda int, ipiv []int) (ok bool) {
31 checkMatrix(m, n, a, lda)
38 bi := blas64.Implementation()
39 nb := impl.Ilaenv(1, "DGETRF", " ", m, n, -1, -1)
40 if nb <= 1 || nb >= min(m, n) {
41 // Use the unblocked algorithm.
42 return impl.Dgetf2(m, n, a, lda, ipiv)
45 for j := 0; j < mn; j += nb {
47 blockOk := impl.Dgetf2(m-j, jb, a[j*lda+j:], lda, ipiv[j:])
51 for i := j; i <= min(m-1, j+jb-1); i++ {
54 impl.Dlaswp(j, a, lda, j, j+jb-1, ipiv[:j+jb], 1)
56 impl.Dlaswp(n-j-jb, a[j+jb:], lda, j, j+jb-1, ipiv[:j+jb], 1)
57 bi.Dtrsm(blas.Left, blas.Lower, blas.NoTrans, blas.Unit,
62 bi.Dgemm(blas.NoTrans, blas.NoTrans, m-j-jb, n-j-jb, jb, -1,
63 a[(j+jb)*lda+j:], lda,
65 1, a[(j+jb)*lda+j+jb:], lda)