gonum.org/v1/gonum@v0.14.0/lapack/gonum/dgeql2.go (about) 1 // Copyright ©2016 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 // Dgeql2 computes the QL factorization of the m×n matrix A. That is, Dgeql2 10 // computes Q and L such that 11 // 12 // A = Q * L 13 // 14 // where Q is an m×m orthonormal matrix and L is a lower trapezoidal matrix. 15 // 16 // Q is represented as a product of elementary reflectors, 17 // 18 // Q = H_{k-1} * ... * H_1 * H_0 19 // 20 // where k = min(m,n) and each H_i has the form 21 // 22 // H_i = I - tau[i] * v_i * v_iᵀ 23 // 24 // Vector v_i has v[m-k+i+1:m] = 0, v[m-k+i] = 1, and v[:m-k+i+1] is stored on 25 // exit in A[0:m-k+i-1, n-k+i]. 26 // 27 // tau must have length at least min(m,n), and Dgeql2 will panic otherwise. 28 // 29 // work is temporary memory storage and must have length at least n. 30 // 31 // Dgeql2 is an internal routine. It is exported for testing purposes. 32 func (impl Implementation) Dgeql2(m, n int, a []float64, lda int, tau, work []float64) { 33 switch { 34 case m < 0: 35 panic(mLT0) 36 case n < 0: 37 panic(nLT0) 38 case lda < max(1, n): 39 panic(badLdA) 40 } 41 42 // Quick return if possible. 43 k := min(m, n) 44 if k == 0 { 45 return 46 } 47 48 switch { 49 case len(a) < (m-1)*lda+n: 50 panic(shortA) 51 case len(tau) < k: 52 panic(shortTau) 53 case len(work) < n: 54 panic(shortWork) 55 } 56 57 var aii float64 58 for i := k - 1; i >= 0; i-- { 59 // Generate elementary reflector H_i to annihilate A[0:m-k+i-1, n-k+i]. 60 aii, tau[i] = impl.Dlarfg(m-k+i+1, a[(m-k+i)*lda+n-k+i], a[n-k+i:], lda) 61 62 // Apply H_i to A[0:m-k+i, 0:n-k+i-1] from the left. 63 a[(m-k+i)*lda+n-k+i] = 1 64 impl.Dlarf(blas.Left, m-k+i+1, n-k+i, a[n-k+i:], lda, tau[i], a, lda, work) 65 a[(m-k+i)*lda+n-k+i] = aii 66 } 67 }