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 // Dormqr multiplies an m×n matrix C by an orthogonal matrix Q as
13 // C = Q * C, if side == blas.Left and trans == blas.NoTrans,
14 // C = Q^T * C, if side == blas.Left and trans == blas.Trans,
15 // C = C * Q, if side == blas.Right and trans == blas.NoTrans,
16 // C = C * Q^T, if side == blas.Right and trans == blas.Trans,
17 // where Q is defined as the product of k elementary reflectors
18 // Q = H_0 * H_1 * ... * H_{k-1}.
20 // If side == blas.Left, A is an m×k matrix and 0 <= k <= m.
21 // If side == blas.Right, A is an n×k matrix and 0 <= k <= n.
22 // The ith column of A contains the vector which defines the elementary
23 // reflector H_i and tau[i] contains its scalar factor. tau must have length k
24 // and Dormqr will panic otherwise. Dgeqrf returns A and tau in the required
27 // work must have length at least max(1,lwork), and lwork must be at least n if
28 // side == blas.Left and at least m if side == blas.Right, otherwise Dormqr will
31 // work is temporary storage, and lwork specifies the usable memory length. At
32 // minimum, lwork >= m if side == blas.Left and lwork >= n if side ==
33 // blas.Right, and this function will panic otherwise. Larger values of lwork
34 // will generally give better performance. On return, work[0] will contain the
35 // optimal value of lwork.
37 // If lwork is -1, instead of performing Dormqr, the optimal workspace size will
38 // be stored into work[0].
39 func (impl Implementation) Dormqr(side blas.Side, trans blas.Transpose, m, n, k int, a []float64, lda int, tau, c []float64, ldc int, work []float64, lwork int) {
52 case trans != blas.NoTrans && trans != blas.Trans:
57 panic("lapack: invalid value of k")
58 case len(work) < lwork:
60 case lwork < max(1, nw) && lwork != -1:
64 checkMatrix(nq, k, a, lda)
65 checkMatrix(m, n, c, ldc)
71 if m == 0 || n == 0 || k == 0 {
81 opts := string(side) + string(trans)
82 nb := min(nbmax, impl.Ilaenv(1, "DORMQR", opts, m, n, k, -1))
83 lworkopt := max(1, nw)*nb + tsize
85 work[0] = float64(lworkopt)
91 if lwork < nw*nb+tsize {
92 nb = (lwork - tsize) / nw
93 nbmin = max(2, impl.Ilaenv(2, "DORMQR", opts, m, n, k, -1))
97 if nb < nbmin || k <= nb {
98 // Call unblocked code.
99 impl.Dorm2r(side, trans, m, n, k, a, lda, tau, c, ldc, work)
100 work[0] = float64(lworkopt)
106 left = side == blas.Left
107 notran = trans == blas.NoTrans
111 for i := ((k - 1) / nb) * nb; i >= 0; i -= nb {
113 impl.Dlarft(lapack.Forward, lapack.ColumnWise, m-i, ib,
117 impl.Dlarfb(side, trans, lapack.Forward, lapack.ColumnWise, m-i, n, ib,
121 work[tsize:], ldwork)
124 case left && !notran:
125 for i := 0; i < k; i += nb {
127 impl.Dlarft(lapack.Forward, lapack.ColumnWise, m-i, ib,
131 impl.Dlarfb(side, trans, lapack.Forward, lapack.ColumnWise, m-i, n, ib,
135 work[tsize:], ldwork)
138 case !left && notran:
139 for i := 0; i < k; i += nb {
141 impl.Dlarft(lapack.Forward, lapack.ColumnWise, n-i, ib,
145 impl.Dlarfb(side, trans, lapack.Forward, lapack.ColumnWise, m, n-i, ib,
149 work[tsize:], ldwork)
152 case !left && !notran:
153 for i := ((k - 1) / nb) * nb; i >= 0; i -= nb {
155 impl.Dlarft(lapack.Forward, lapack.ColumnWise, n-i, ib,
159 impl.Dlarfb(side, trans, lapack.Forward, lapack.ColumnWise, m, n-i, ib,
163 work[tsize:], ldwork)
166 work[0] = float64(lworkopt)