github.com/gopherd/gonum@v0.0.4/lapack/gonum/dtbtrs.go (about) 1 // Copyright ©2020 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 // Dtbtrs solves a triangular system of the form 13 // A * X = B if trans == blas.NoTrans 14 // Aᵀ * X = B if trans == blas.Trans or blas.ConjTrans 15 // where A is an n×n triangular band matrix with kd super- or subdiagonals, and 16 // B is an n×nrhs matrix. 17 // 18 // Dtbtrs returns whether A is non-singular. If A is singular, no solution X is 19 // computed. 20 func (impl Implementation) Dtbtrs(uplo blas.Uplo, trans blas.Transpose, diag blas.Diag, n, kd, nrhs int, a []float64, lda int, b []float64, ldb int) (ok bool) { 21 switch { 22 case uplo != blas.Upper && uplo != blas.Lower: 23 panic(badUplo) 24 case trans != blas.NoTrans && trans != blas.Trans && trans != blas.ConjTrans: 25 panic(badTrans) 26 case diag != blas.NonUnit && diag != blas.Unit: 27 panic(badDiag) 28 case n < 0: 29 panic(nLT0) 30 case kd < 0: 31 panic(kdLT0) 32 case nrhs < 0: 33 panic(nrhsLT0) 34 case lda < kd+1: 35 panic(badLdA) 36 case ldb < max(1, nrhs): 37 panic(badLdB) 38 } 39 40 // Quick return if possible. 41 if n == 0 { 42 return true 43 } 44 45 switch { 46 case len(a) < (n-1)*lda+kd+1: 47 panic(shortA) 48 case len(b) < (n-1)*ldb+nrhs: 49 panic(shortB) 50 } 51 52 // Check for singularity. 53 if diag == blas.NonUnit { 54 if uplo == blas.Upper { 55 for i := 0; i < n; i++ { 56 if a[i*lda] == 0 { 57 return false 58 } 59 } 60 } else { 61 for i := 0; i < n; i++ { 62 if a[i*lda+kd] == 0 { 63 return false 64 } 65 } 66 } 67 } 68 69 // Solve A * X = B or Aᵀ * X = B. 70 bi := blas64.Implementation() 71 for j := 0; j < nrhs; j++ { 72 bi.Dtbsv(uplo, trans, diag, n, kd, a, lda, b[j:], ldb) 73 } 74 return true 75 }