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.
8 "gonum.org/v1/gonum/blas"
9 "gonum.org/v1/gonum/lapack"
12 // Dorglq generates an m×n matrix Q with orthonormal columns defined by the
13 // product of elementary reflectors as computed by Dgelqf.
14 // Q = H_0 * H_1 * ... * H_{k-1}
15 // Dorglq is the blocked version of Dorgl2 that makes greater use of level-3 BLAS
18 // len(tau) >= k, 0 <= k <= n, and 0 <= n <= m.
20 // work is temporary storage, and lwork specifies the usable memory length. At minimum,
21 // lwork >= m, and the amount of blocking is limited by the usable length.
22 // If lwork == -1, instead of computing Dorglq the optimal work length is stored
25 // Dorglq will panic if the conditions on input values are not met.
27 // Dorglq is an internal routine. It is exported for testing purposes.
28 func (impl Implementation) Dorglq(m, n, k int, a []float64, lda int, tau, work []float64, lwork int) {
29 nb := impl.Ilaenv(1, "DORGLQ", " ", m, n, k, -1)
30 // work is treated as an n×nb matrix
32 work[0] = float64(max(1, m) * nb)
35 checkMatrix(m, n, a, lda)
48 if len(work) < lwork {
57 nbmin := 2 // Minimum number of blocks
58 var nx int // Minimum number of rows
59 iws := m // Length of work needed
62 nx = max(0, impl.Ilaenv(3, "DORGLQ", " ", m, n, k, -1))
69 nbmin = max(2, impl.Ilaenv(2, "DORGLQ", " ", m, n, k, -1))
74 if nb >= nbmin && nb < k && nx < k {
75 // The first kk rows are handled by the blocked method.
76 // Note: lapack has nx here, but this means the last nx rows are handled
77 // serially which could be quite different than nb.
78 ki = ((k - nb - 1) / nb) * nb
80 for i := kk; i < m; i++ {
81 for j := 0; j < kk; j++ {
87 // Perform the operation on colums kk to the end.
88 impl.Dorgl2(m-kk, n-kk, k-kk, a[kk*lda+kk:], lda, tau[kk:], work)
93 // Perform the operation on column-blocks
94 for i := ki; i >= 0; i -= nb {
97 impl.Dlarft(lapack.Forward, lapack.RowWise,
103 impl.Dlarfb(blas.Right, blas.Trans, lapack.Forward, lapack.RowWise,
107 a[(i+ib)*lda+i:], lda,
108 work[ib*ldwork:], ldwork)
110 impl.Dorgl2(ib, n-i, ib, a[i*lda+i:], lda, tau[i:], work)
111 for l := i; l < i+ib; l++ {
112 for j := 0; j < i; j++ {