github.com/gopherd/gonum@v0.0.4/lapack/gonum/dtrtrs.go (about)

     1  // Copyright ©2015 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  // Dtrtrs solves a triangular system of the form A * X = B or Aᵀ * X = B. Dtrtrs
    13  // returns whether the solve completed successfully. If A is singular, no solve is performed.
    14  func (impl Implementation) Dtrtrs(uplo blas.Uplo, trans blas.Transpose, diag blas.Diag, n, nrhs int, a []float64, lda int, b []float64, ldb int) (ok bool) {
    15  	switch {
    16  	case uplo != blas.Upper && uplo != blas.Lower:
    17  		panic(badUplo)
    18  	case trans != blas.NoTrans && trans != blas.Trans && trans != blas.ConjTrans:
    19  		panic(badTrans)
    20  	case diag != blas.NonUnit && diag != blas.Unit:
    21  		panic(badDiag)
    22  	case n < 0:
    23  		panic(nLT0)
    24  	case nrhs < 0:
    25  		panic(nrhsLT0)
    26  	case lda < max(1, n):
    27  		panic(badLdA)
    28  	case ldb < max(1, nrhs):
    29  		panic(badLdB)
    30  	}
    31  
    32  	if n == 0 {
    33  		return true
    34  	}
    35  
    36  	switch {
    37  	case len(a) < (n-1)*lda+n:
    38  		panic(shortA)
    39  	case len(b) < (n-1)*ldb+nrhs:
    40  		panic(shortB)
    41  	}
    42  
    43  	// Check for singularity.
    44  	nounit := diag == blas.NonUnit
    45  	if nounit {
    46  		for i := 0; i < n; i++ {
    47  			if a[i*lda+i] == 0 {
    48  				return false
    49  			}
    50  		}
    51  	}
    52  	bi := blas64.Implementation()
    53  	bi.Dtrsm(blas.Left, uplo, trans, diag, n, nrhs, 1, a, lda, b, ldb)
    54  	return true
    55  }