github.com/jingcheng-WU/gonum@v0.9.1-0.20210323123734-f1a2a11a8f7b/lapack/gonum/dlacpy.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 "github.com/jingcheng-WU/gonum/blas"
     8  
     9  // Dlacpy copies the elements of A specified by uplo into B. Uplo can specify
    10  // a triangular portion with blas.Upper or blas.Lower, or can specify all of the
    11  // elements with blas.All.
    12  //
    13  // Dlacpy is an internal routine. It is exported for testing purposes.
    14  func (impl Implementation) Dlacpy(uplo blas.Uplo, m, n int, a []float64, lda int, b []float64, ldb int) {
    15  	switch {
    16  	case uplo != blas.Upper && uplo != blas.Lower && uplo != blas.All:
    17  		panic(badUplo)
    18  	case m < 0:
    19  		panic(mLT0)
    20  	case n < 0:
    21  		panic(nLT0)
    22  	case lda < max(1, n):
    23  		panic(badLdA)
    24  	case ldb < max(1, n):
    25  		panic(badLdB)
    26  	}
    27  
    28  	if m == 0 || n == 0 {
    29  		return
    30  	}
    31  
    32  	switch {
    33  	case len(a) < (m-1)*lda+n:
    34  		panic(shortA)
    35  	case len(b) < (m-1)*ldb+n:
    36  		panic(shortB)
    37  	}
    38  
    39  	switch uplo {
    40  	case blas.Upper:
    41  		for i := 0; i < m; i++ {
    42  			for j := i; j < n; j++ {
    43  				b[i*ldb+j] = a[i*lda+j]
    44  			}
    45  		}
    46  	case blas.Lower:
    47  		for i := 0; i < m; i++ {
    48  			for j := 0; j < min(i+1, n); j++ {
    49  				b[i*ldb+j] = a[i*lda+j]
    50  			}
    51  		}
    52  	case blas.All:
    53  		for i := 0; i < m; i++ {
    54  			for j := 0; j < n; j++ {
    55  				b[i*ldb+j] = a[i*lda+j]
    56  			}
    57  		}
    58  	}
    59  }