github.com/gopherd/gonum@v0.0.4/lapack/gonum/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 gonum 6 7 import ( 8 "github.com/gopherd/gonum/blas" 9 "github.com/gopherd/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ᵀ * 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 switch { 25 case trans != blas.NoTrans && trans != blas.Trans && trans != blas.ConjTrans: 26 panic(badTrans) 27 case n < 0: 28 panic(nLT0) 29 case nrhs < 0: 30 panic(nrhsLT0) 31 case lda < max(1, n): 32 panic(badLdA) 33 case ldb < max(1, nrhs): 34 panic(badLdB) 35 } 36 37 // Quick return if possible. 38 if n == 0 || nrhs == 0 { 39 return 40 } 41 42 switch { 43 case len(a) < (n-1)*lda+n: 44 panic(shortA) 45 case len(b) < (n-1)*ldb+nrhs: 46 panic(shortB) 47 case len(ipiv) != n: 48 panic(badLenIpiv) 49 } 50 51 bi := blas64.Implementation() 52 53 if trans == blas.NoTrans { 54 // Solve A * X = B. 55 impl.Dlaswp(nrhs, b, ldb, 0, n-1, ipiv, 1) 56 // Solve L * X = B, updating b. 57 bi.Dtrsm(blas.Left, blas.Lower, blas.NoTrans, blas.Unit, 58 n, nrhs, 1, a, lda, b, ldb) 59 // Solve U * X = B, updating b. 60 bi.Dtrsm(blas.Left, blas.Upper, blas.NoTrans, blas.NonUnit, 61 n, nrhs, 1, a, lda, b, ldb) 62 return 63 } 64 // Solve Aᵀ * X = B. 65 // Solve Uᵀ * X = B, updating b. 66 bi.Dtrsm(blas.Left, blas.Upper, blas.Trans, blas.NonUnit, 67 n, nrhs, 1, a, lda, b, ldb) 68 // Solve Lᵀ * X = B, updating b. 69 bi.Dtrsm(blas.Left, blas.Lower, blas.Trans, blas.Unit, 70 n, nrhs, 1, a, lda, b, ldb) 71 impl.Dlaswp(nrhs, b, ldb, 0, n-1, ipiv, -1) 72 }