gonum.org/v1/gonum@v0.14.0/lapack/gonum/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 gonum 6 7 import ( 8 "gonum.org/v1/gonum/blas" 9 "gonum.org/v1/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 // 15 // Q = H_0 * H_1 * ... * H_{k-1} 16 // 17 // len(tau) >= k, 0 <= k <= n, 0 <= n <= m, len(work) >= n. 18 // Dorg2r will panic if these conditions are not met. 19 // 20 // Dorg2r is an internal routine. It is exported for testing purposes. 21 func (impl Implementation) Dorg2r(m, n, k int, a []float64, lda int, tau []float64, work []float64) { 22 switch { 23 case m < 0: 24 panic(mLT0) 25 case n < 0: 26 panic(nLT0) 27 case n > m: 28 panic(nGTM) 29 case k < 0: 30 panic(kLT0) 31 case k > n: 32 panic(kGTN) 33 case lda < max(1, n): 34 panic(badLdA) 35 } 36 37 if n == 0 { 38 return 39 } 40 41 switch { 42 case len(a) < (m-1)*lda+n: 43 panic(shortA) 44 case len(tau) < k: 45 panic(shortTau) 46 case len(work) < n: 47 panic(shortWork) 48 } 49 50 bi := blas64.Implementation() 51 52 // Initialize columns k+1:n to columns of the unit matrix. 53 for l := 0; l < m; l++ { 54 for j := k; j < n; j++ { 55 a[l*lda+j] = 0 56 } 57 } 58 for j := k; j < n; j++ { 59 a[j*lda+j] = 1 60 } 61 for i := k - 1; i >= 0; i-- { 62 for i := range work { 63 work[i] = 0 64 } 65 if i < n-1 { 66 a[i*lda+i] = 1 67 impl.Dlarf(blas.Left, m-i, n-i-1, a[i*lda+i:], lda, tau[i], a[i*lda+i+1:], lda, work) 68 } 69 if i < m-1 { 70 bi.Dscal(m-i-1, -tau[i], a[(i+1)*lda+i:], lda) 71 } 72 a[i*lda+i] = 1 - tau[i] 73 for l := 0; l < i; l++ { 74 a[l*lda+i] = 0 75 } 76 } 77 }