gonum.org/v1/gonum@v0.14.0/lapack/gonum/dgesv.go (about) 1 // Copyright ©2021 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 "gonum.org/v1/gonum/blas" 8 9 // Dgesv computes the solution to a real system of linear equations 10 // 11 // A * X = B 12 // 13 // where A is an n×n matrix and X and B are n×nrhs matrices. 14 // 15 // The LU decomposition with partial pivoting and row interchanges is used to 16 // factor A as 17 // 18 // A = P * L * U 19 // 20 // where P is a permutation matrix, L is unit lower triangular, and U is upper 21 // triangular. On return, the factors L and U are stored in a; the unit diagonal 22 // elements of L are not stored. The row pivot indices that define the 23 // permutation matrix P are stored in ipiv. 24 // 25 // The factored form of A is then used to solve the system of equations A * X = 26 // B. On entry, b contains the right hand side matrix B. On return, if ok is 27 // true, b contains the solution matrix X. 28 func (impl Implementation) Dgesv(n, nrhs int, a []float64, lda int, ipiv []int, b []float64, ldb int) (ok bool) { 29 switch { 30 case n < 0: 31 panic(nLT0) 32 case nrhs < 0: 33 panic(nrhsLT0) 34 case lda < max(1, n): 35 panic(badLdA) 36 case ldb < max(1, nrhs): 37 panic(badLdB) 38 } 39 40 // Quick return if possible. 41 if n == 0 || nrhs == 0 { 42 return true 43 } 44 45 switch { 46 case len(a) < (n-1)*lda+n: 47 panic(shortAB) 48 case len(ipiv) != n: 49 panic(badLenIpiv) 50 case len(b) < (n-1)*ldb+nrhs: 51 panic(shortB) 52 } 53 54 ok = impl.Dgetrf(n, n, a, lda, ipiv) 55 if ok { 56 impl.Dgetrs(blas.NoTrans, n, nrhs, a, lda, ipiv, b, ldb) 57 } 58 59 return ok 60 }