forked from gonum/gonum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dtbtrs.go
77 lines (70 loc) · 1.74 KB
/
dtbtrs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright ©2020 The Gonum Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package gonum
import (
"gonum.org/v1/gonum/blas"
"gonum.org/v1/gonum/blas/blas64"
)
// Dtbtrs solves a triangular system of the form
//
// A * X = B if trans == blas.NoTrans
// Aᵀ * X = B if trans == blas.Trans or blas.ConjTrans
//
// where A is an n×n triangular band matrix with kd super- or subdiagonals, and
// B is an n×nrhs matrix.
//
// Dtbtrs returns whether A is non-singular. If A is singular, no solution X is
// computed.
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) {
switch {
case uplo != blas.Upper && uplo != blas.Lower:
panic(badUplo)
case trans != blas.NoTrans && trans != blas.Trans && trans != blas.ConjTrans:
panic(badTrans)
case diag != blas.NonUnit && diag != blas.Unit:
panic(badDiag)
case n < 0:
panic(nLT0)
case kd < 0:
panic(kdLT0)
case nrhs < 0:
panic(nrhsLT0)
case lda < kd+1:
panic(badLdA)
case ldb < max(1, nrhs):
panic(badLdB)
}
// Quick return if possible.
if n == 0 {
return true
}
switch {
case len(a) < (n-1)*lda+kd+1:
panic(shortA)
case len(b) < (n-1)*ldb+nrhs:
panic(shortB)
}
// Check for singularity.
if diag == blas.NonUnit {
if uplo == blas.Upper {
for i := 0; i < n; i++ {
if a[i*lda] == 0 {
return false
}
}
} else {
for i := 0; i < n; i++ {
if a[i*lda+kd] == 0 {
return false
}
}
}
}
// Solve A * X = B or Aᵀ * X = B.
bi := blas64.Implementation()
for j := 0; j < nrhs; j++ {
bi.Dtbsv(uplo, trans, diag, n, kd, a, lda, b[j:], ldb)
}
return true
}