gonum.org/v1/gonum@v0.15.1-0.20240517103525-f853624cb1bb/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 as the first m 13 // rows of a product of k elementary reflectors of order n 14 // 15 // Q = H_{k-1} * ... * H_0 16 // 17 // as returned by Dgelqf. 18 // 19 // On entry, tau and the first k rows of A must contain the scalar factors and 20 // the vectors, respectively, which define the elementary reflectors H_i, 21 // i=0,...,k-1, as returned by Dgelqf. On return, A contains the matrix Q. 22 // 23 // tau must have length at least k, work must have length at least m, and it 24 // must hold that 0 <= k <= m <= n, otherwise Dorgl2 will panic. 25 // 26 // Dorgl2 is an internal routine. It is exported for testing purposes. 27 func (impl Implementation) Dorgl2(m, n, k int, a []float64, lda int, tau, work []float64) { 28 switch { 29 case m < 0: 30 panic(mLT0) 31 case n < m: 32 panic(nLTM) 33 case k < 0: 34 panic(kLT0) 35 case k > m: 36 panic(kGTM) 37 case lda < max(1, n): 38 panic(badLdA) 39 } 40 41 if m == 0 { 42 return 43 } 44 45 switch { 46 case len(a) < (m-1)*lda+n: 47 panic(shortA) 48 case len(tau) < k: 49 panic(shortTau) 50 case len(work) < m: 51 panic(shortWork) 52 } 53 54 bi := blas64.Implementation() 55 56 if k < m { 57 for i := k; i < m; i++ { 58 for j := 0; j < n; j++ { 59 a[i*lda+j] = 0 60 } 61 } 62 for j := k; j < m; j++ { 63 a[j*lda+j] = 1 64 } 65 } 66 for i := k - 1; i >= 0; i-- { 67 if i < n-1 { 68 if i < m-1 { 69 a[i*lda+i] = 1 70 impl.Dlarf(blas.Right, m-i-1, n-i, a[i*lda+i:], 1, tau[i], a[(i+1)*lda+i:], lda, work) 71 } 72 bi.Dscal(n-i-1, -tau[i], a[i*lda+i+1:], 1) 73 } 74 a[i*lda+i] = 1 - tau[i] 75 for l := 0; l < i; l++ { 76 a[i*lda+l] = 0 77 } 78 } 79 }