gonum.org/v1/gonum@v0.14.0/lapack/gonum/dlaset.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 "gonum.org/v1/gonum/blas" 8 9 // Dlaset sets the off-diagonal elements of A to alpha, and the diagonal 10 // elements to beta. If uplo == blas.Upper, only the elements in the upper 11 // triangular part are set. If uplo == blas.Lower, only the elements in the 12 // lower triangular part are set. If uplo is otherwise, all of the elements of A 13 // are set. 14 // 15 // Dlaset is an internal routine. It is exported for testing purposes. 16 func (impl Implementation) Dlaset(uplo blas.Uplo, m, n int, alpha, beta float64, a []float64, lda int) { 17 switch { 18 case m < 0: 19 panic(mLT0) 20 case n < 0: 21 panic(nLT0) 22 case lda < max(1, n): 23 panic(badLdA) 24 } 25 26 minmn := min(m, n) 27 if minmn == 0 { 28 return 29 } 30 31 if len(a) < (m-1)*lda+n { 32 panic(shortA) 33 } 34 35 switch uplo { 36 case blas.Upper: 37 for i := 0; i < m; i++ { 38 for j := i + 1; j < n; j++ { 39 a[i*lda+j] = alpha 40 } 41 } 42 case blas.Lower: 43 for i := 0; i < m; i++ { 44 for j := 0; j < min(i, n); j++ { 45 a[i*lda+j] = alpha 46 } 47 } 48 default: 49 for i := 0; i < m; i++ { 50 for j := 0; j < n; j++ { 51 a[i*lda+j] = alpha 52 } 53 } 54 } 55 for i := 0; i < minmn; i++ { 56 a[i*lda+i] = beta 57 } 58 }