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