gonum.org/v1/gonum@v0.15.1-0.20240517103525-f853624cb1bb/lapack/gonum/dpttrs.go (about)

     1  // Copyright ©2023 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  // Dpttrs solves a tridiagonal system of the form
     8  //
     9  //	A * X = B
    10  //
    11  // using the L*D*Lᵀ factorization of A computed by Dpttrf. D is a diagonal
    12  // matrix specified in d, L is a unit bidiagonal matrix whose subdiagonal is
    13  // specified in e, and X and B are n×nrhs matrices.
    14  func (impl Implementation) Dpttrs(n, nrhs int, d, e []float64, b []float64, ldb int) {
    15  	switch {
    16  	case n < 0:
    17  		panic(nLT0)
    18  	case nrhs < 0:
    19  		panic(nrhsLT0)
    20  	case ldb < max(1, nrhs):
    21  		panic(badLdB)
    22  	}
    23  
    24  	// Quick return if possible.
    25  	if n == 0 || nrhs == 0 {
    26  		return
    27  	}
    28  
    29  	switch {
    30  	case len(d) < n:
    31  		panic(shortD)
    32  	case len(e) < n-1:
    33  		panic(shortE)
    34  	case len(b) < (n-1)*ldb+nrhs:
    35  		panic(shortB)
    36  	}
    37  
    38  	nb := 1
    39  	if nrhs > 1 {
    40  		nb = max(1, impl.Ilaenv(1, "DPTTRS", " ", n, nrhs, -1, -1))
    41  	}
    42  
    43  	if nb >= nrhs {
    44  		impl.dptts2(n, nrhs, d, e, b, ldb)
    45  	} else {
    46  		for j := 0; j < nrhs; j += nb {
    47  			jb := min(nrhs-j, nb)
    48  			impl.dptts2(n, jb, d, e, b[j:], ldb)
    49  		}
    50  	}
    51  }