gonum.org/v1/gonum@v0.15.1-0.20240517103525-f853624cb1bb/lapack/gonum/dptsv.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  // Dptsv computes the solution to system of linear equations
     8  //
     9  //	A * X = B
    10  //
    11  // where A is an n×n symmetric positive definite tridiagonal matrix, and X and B
    12  // are n×nrhs matrices. A is factored as A = L*D*Lᵀ, and the factored form of A
    13  // is then used to solve the system of equations.
    14  //
    15  // On entry, d contains the n diagonal elements of A and e contains the (n-1)
    16  // subdiagonal elements of A. On return, d contains the n diagonal elements of
    17  // the diagonal matrix D from the factorization A = L*D*Lᵀ and e contains the
    18  // (n-1) subdiagonal elements of the unit bidiagonal factor L.
    19  //
    20  // Dptsv returns whether the solution X has been successfully computed.
    21  func (impl Implementation) Dptsv(n, nrhs int, d, e []float64, b []float64, ldb int) (ok bool) {
    22  	switch {
    23  	case n < 0:
    24  		panic(nLT0)
    25  	case nrhs < 0:
    26  		panic(nrhsLT0)
    27  	case ldb < max(1, nrhs):
    28  		panic(badLdB)
    29  	}
    30  
    31  	if n == 0 || nrhs == 0 {
    32  		return true
    33  	}
    34  
    35  	switch {
    36  	case len(d) < n:
    37  		panic(shortD)
    38  	case len(e) < n-1:
    39  		panic(shortE)
    40  	case len(b) < (n-1)*ldb+nrhs:
    41  		panic(shortB)
    42  	}
    43  
    44  	ok = impl.Dpttrf(n, d, e)
    45  	if ok {
    46  		impl.Dpttrs(n, nrhs, d, e, b, ldb)
    47  	}
    48  	return ok
    49  }