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