github.com/gonum/lapack@v0.0.0-20181123203213-e4cdc5a0bff9/native/dorg2r.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 native 6 7 import ( 8 "github.com/gonum/blas" 9 "github.com/gonum/blas/blas64" 10 ) 11 12 // Dorg2r generates an m×n matrix Q with orthonormal columns defined by the 13 // product of elementary reflectors as computed by Dgeqrf. 14 // Q = H_0 * H_1 * ... * H_{k-1} 15 // len(tau) >= k, 0 <= k <= n, 0 <= n <= m, len(work) >= n. 16 // Dorg2r will panic if these conditions are not met. 17 // 18 // Dorg2r is an internal routine. It is exported for testing purposes. 19 func (impl Implementation) Dorg2r(m, n, k int, a []float64, lda int, tau []float64, work []float64) { 20 checkMatrix(m, n, a, lda) 21 if len(tau) < k { 22 panic(badTau) 23 } 24 if len(work) < n { 25 panic(badWork) 26 } 27 if k > n { 28 panic(kGTN) 29 } 30 if n > m { 31 panic(mLTN) 32 } 33 if len(work) < n { 34 panic(badWork) 35 } 36 if n == 0 { 37 return 38 } 39 bi := blas64.Implementation() 40 // Initialize columns k+1:n to columns of the unit matrix. 41 for l := 0; l < m; l++ { 42 for j := k; j < n; j++ { 43 a[l*lda+j] = 0 44 } 45 } 46 for j := k; j < n; j++ { 47 a[j*lda+j] = 1 48 } 49 for i := k - 1; i >= 0; i-- { 50 for i := range work { 51 work[i] = 0 52 } 53 if i < n-1 { 54 a[i*lda+i] = 1 55 impl.Dlarf(blas.Left, m-i, n-i-1, a[i*lda+i:], lda, tau[i], a[i*lda+i+1:], lda, work) 56 } 57 if i < m-1 { 58 bi.Dscal(m-i-1, -tau[i], a[(i+1)*lda+i:], lda) 59 } 60 a[i*lda+i] = 1 - tau[i] 61 for l := 0; l < i; l++ { 62 a[l*lda+i] = 0 63 } 64 } 65 }