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.
7 import "gonum.org/v1/gonum/blas"
9 // Dgeqr2 computes a QR factorization of the m×n matrix A.
11 // In a QR factorization, Q is an m×m orthonormal matrix, and R is an
12 // upper triangular m×n matrix.
14 // A is modified to contain the information to construct Q and R.
15 // The upper triangle of a contains the matrix R. The lower triangular elements
16 // (not including the diagonal) contain the elementary reflectors. tau is modified
17 // to contain the reflector scales. tau must have length at least min(m,n), and
18 // this function will panic otherwise.
20 // The ith elementary reflector can be explicitly constructed by first extracting
24 // v[j] = a[j*lda+i] j > i
25 // and computing H_i = I - tau[i] * v * v^T.
27 // The orthonormal matrix Q can be constructed from a product of these elementary
28 // reflectors, Q = H_0 * H_1 * ... * H_{k-1}, where k = min(m,n).
30 // work is temporary storage of length at least n and this function will panic otherwise.
32 // Dgeqr2 is an internal routine. It is exported for testing purposes.
33 func (impl Implementation) Dgeqr2(m, n int, a []float64, lda int, tau, work []float64) {
34 // TODO(btracey): This is oriented such that columns of a are eliminated.
35 // This likely could be re-arranged to take better advantage of row-major
37 checkMatrix(m, n, a, lda)
45 for i := 0; i < k; i++ {
46 // Generate elementary reflector H_i.
47 a[i*lda+i], tau[i] = impl.Dlarfg(m-i, a[i*lda+i], a[min((i+1), m-1)*lda+i:], lda)
51 impl.Dlarf(blas.Left, m-i, n-i-1,