gonum.org/v1/gonum@v0.14.0/lapack/gonum/dorgl2.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 // Dorgl2 generates an m×n matrix Q with orthonormal rows defined by the 13 // first m rows product of elementary reflectors as computed by Dgelqf. 14 // 15 // Q = H_0 * H_1 * ... * H_{k-1} 16 // 17 // len(tau) >= k, 0 <= k <= m, 0 <= m <= n, len(work) >= m. 18 // Dorgl2 will panic if these conditions are not met. 19 // 20 // Dorgl2 is an internal routine. It is exported for testing purposes. 21 func (impl Implementation) Dorgl2(m, n, k int, a []float64, lda int, tau, work []float64) { 22 switch { 23 case m < 0: 24 panic(mLT0) 25 case n < m: 26 panic(nLTM) 27 case k < 0: 28 panic(kLT0) 29 case k > m: 30 panic(kGTM) 31 case lda < max(1, m): 32 panic(badLdA) 33 } 34 35 if m == 0 { 36 return 37 } 38 39 switch { 40 case len(a) < (m-1)*lda+n: 41 panic(shortA) 42 case len(tau) < k: 43 panic(shortTau) 44 case len(work) < m: 45 panic(shortWork) 46 } 47 48 bi := blas64.Implementation() 49 50 if k < m { 51 for i := k; i < m; i++ { 52 for j := 0; j < n; j++ { 53 a[i*lda+j] = 0 54 } 55 } 56 for j := k; j < m; j++ { 57 a[j*lda+j] = 1 58 } 59 } 60 for i := k - 1; i >= 0; i-- { 61 if i < n-1 { 62 if i < m-1 { 63 a[i*lda+i] = 1 64 impl.Dlarf(blas.Right, m-i-1, n-i, a[i*lda+i:], 1, tau[i], a[(i+1)*lda+i:], lda, work) 65 } 66 bi.Dscal(n-i-1, -tau[i], a[i*lda+i+1:], 1) 67 } 68 a[i*lda+i] = 1 - tau[i] 69 for l := 0; l < i; l++ { 70 a[i*lda+l] = 0 71 } 72 } 73 }