github.com/jingcheng-WU/gonum@v0.9.1-0.20210323123734-f1a2a11a8f7b/lapack/gonum/dlauu2.go (about)

     1  // Copyright ©2018 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/jingcheng-WU/gonum/blas"
     9  	"github.com/jingcheng-WU/gonum/blas/blas64"
    10  )
    11  
    12  // Dlauu2 computes the product
    13  //  U * Uᵀ  if uplo is blas.Upper
    14  //  Lᵀ * L  if uplo is blas.Lower
    15  // where U or L is stored in the upper or lower triangular part of A.
    16  // Only the upper or lower triangle of the result is stored, overwriting
    17  // the corresponding factor in A.
    18  func (impl Implementation) Dlauu2(uplo blas.Uplo, n int, a []float64, lda int) {
    19  	switch {
    20  	case uplo != blas.Upper && uplo != blas.Lower:
    21  		panic(badUplo)
    22  	case n < 0:
    23  		panic(nLT0)
    24  	case lda < max(1, n):
    25  		panic(badLdA)
    26  	}
    27  
    28  	// Quick return if possible.
    29  	if n == 0 {
    30  		return
    31  	}
    32  
    33  	if len(a) < (n-1)*lda+n {
    34  		panic(shortA)
    35  	}
    36  
    37  	bi := blas64.Implementation()
    38  
    39  	if uplo == blas.Upper {
    40  		// Compute the product U*Uᵀ.
    41  		for i := 0; i < n; i++ {
    42  			aii := a[i*lda+i]
    43  			if i < n-1 {
    44  				a[i*lda+i] = bi.Ddot(n-i, a[i*lda+i:], 1, a[i*lda+i:], 1)
    45  				bi.Dgemv(blas.NoTrans, i, n-i-1, 1, a[i+1:], lda, a[i*lda+i+1:], 1,
    46  					aii, a[i:], lda)
    47  			} else {
    48  				bi.Dscal(i+1, aii, a[i:], lda)
    49  			}
    50  		}
    51  	} else {
    52  		// Compute the product Lᵀ*L.
    53  		for i := 0; i < n; i++ {
    54  			aii := a[i*lda+i]
    55  			if i < n-1 {
    56  				a[i*lda+i] = bi.Ddot(n-i, a[i*lda+i:], lda, a[i*lda+i:], lda)
    57  				bi.Dgemv(blas.Trans, n-i-1, i, 1, a[(i+1)*lda:], lda, a[(i+1)*lda+i:], lda,
    58  					aii, a[i*lda:], 1)
    59  			} else {
    60  				bi.Dscal(i+1, aii, a[i*lda:], 1)
    61  			}
    62  		}
    63  	}
    64  }