1 // Copyright ©2017 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.
7 import "gonum.org/v1/gonum/blas"
9 // Dgerq2 computes an RQ factorization of the m×n matrix A,
11 // On exit, if m <= n, the upper triangle of the subarray
12 // A[0:m, n-m:n] contains the m×m upper triangular matrix R.
13 // If m >= n, the elements on and above the (m-n)-th subdiagonal
14 // contain the m×n upper trapezoidal matrix R.
15 // The remaining elements, with tau, represent the
16 // orthogonal matrix Q as a product of min(m,n) elementary
19 // The matrix Q is represented as a product of elementary reflectors
20 // Q = H_0 H_1 . . . H_{min(m,n)-1}.
21 // Each H(i) has the form
22 // H_i = I - tau_i * v * v^T
23 // where v is a vector with v[0:n-k+i-1] stored in A[m-k+i, 0:n-k+i-1],
24 // v[n-k+i:n] = 0 and v[n-k+i] = 1.
26 // tau must have length min(m,n) and work must have length m, otherwise
29 // Dgerq2 is an internal routine. It is exported for testing purposes.
30 func (impl Implementation) Dgerq2(m, n int, a []float64, lda int, tau, work []float64) {
31 checkMatrix(m, n, a, lda)
40 for i := k - 1; i >= 0; i-- {
41 // Generate elementary reflector H[i] to annihilate
42 // A[m-k+i, 0:n-k+i-1].
46 aii, tau[i] = impl.Dlarfg(nki+1, a[mki*lda+nki], a[mki*lda:], 1)
48 // Apply H[i] to A[0:m-k+i-1, 0:n-k+i] from the right.
50 impl.Dlarf(blas.Right, mki, nki+1, a[mki*lda:], 1, tau[i], a, lda, work)