github.com/gonum/lapack@v0.0.0-20181123203213-e4cdc5a0bff9/native/dgetrs.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 native
     6  
     7  import (
     8  	"github.com/gonum/blas"
     9  	"github.com/gonum/blas/blas64"
    10  )
    11  
    12  // Dgetrs solves a system of equations using an LU factorization.
    13  // The system of equations solved is
    14  //  A * X = B if trans == blas.Trans
    15  //  A^T * X = B if trans == blas.NoTrans
    16  // A is a general n×n matrix with stride lda. B is a general matrix of size n×nrhs.
    17  //
    18  // On entry b contains the elements of the matrix B. On exit, b contains the
    19  // elements of X, the solution to the system of equations.
    20  //
    21  // a and ipiv contain the LU factorization of A and the permutation indices as
    22  // computed by Dgetrf. ipiv is zero-indexed.
    23  func (impl Implementation) Dgetrs(trans blas.Transpose, n, nrhs int, a []float64, lda int, ipiv []int, b []float64, ldb int) {
    24  	checkMatrix(n, n, a, lda)
    25  	checkMatrix(n, nrhs, b, ldb)
    26  	if len(ipiv) < n {
    27  		panic(badIpiv)
    28  	}
    29  	if n == 0 || nrhs == 0 {
    30  		return
    31  	}
    32  	if trans != blas.Trans && trans != blas.NoTrans {
    33  		panic(badTrans)
    34  	}
    35  	bi := blas64.Implementation()
    36  	if trans == blas.NoTrans {
    37  		// Solve A * X = B.
    38  		impl.Dlaswp(nrhs, b, ldb, 0, n-1, ipiv, 1)
    39  		// Solve L * X = B, updating b.
    40  		bi.Dtrsm(blas.Left, blas.Lower, blas.NoTrans, blas.Unit,
    41  			n, nrhs, 1, a, lda, b, ldb)
    42  		// Solve U * X = B, updating b.
    43  		bi.Dtrsm(blas.Left, blas.Upper, blas.NoTrans, blas.NonUnit,
    44  			n, nrhs, 1, a, lda, b, ldb)
    45  		return
    46  	}
    47  	// Solve A^T * X = B.
    48  	// Solve U^T * X = B, updating b.
    49  	bi.Dtrsm(blas.Left, blas.Upper, blas.Trans, blas.NonUnit,
    50  		n, nrhs, 1, a, lda, b, ldb)
    51  	// Solve L^T * X = B, updating b.
    52  	bi.Dtrsm(blas.Left, blas.Lower, blas.Trans, blas.Unit,
    53  		n, nrhs, 1, a, lda, b, ldb)
    54  	impl.Dlaswp(nrhs, b, ldb, 0, n-1, ipiv, -1)
    55  }