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 // Dormlq multiplies the matrix C by the orthogonal matrix Q defined by the
13 // slices a and tau. A and tau are as returned from Dgelqf.
14 // C = Q * C if side == blas.Left and trans == blas.NoTrans
15 // C = Q^T * C if side == blas.Left and trans == blas.Trans
16 // C = C * Q if side == blas.Right and trans == blas.NoTrans
17 // C = C * Q^T if side == blas.Right and trans == blas.Trans
18 // If side == blas.Left, A is a matrix of side k×m, and if side == blas.Right
19 // A is of size k×n. This uses a blocked algorithm.
21 // work is temporary storage, and lwork specifies the usable memory length.
22 // At minimum, lwork >= m if side == blas.Left and lwork >= n if side == blas.Right,
23 // and this function will panic otherwise.
24 // Dormlq uses a block algorithm, but the block size is limited
25 // by the temporary space available. If lwork == -1, instead of performing Dormlq,
26 // the optimal work length will be stored into work[0].
28 // tau contains the Householder scales and must have length at least k, and
29 // this function will panic otherwise.
30 func (impl Implementation) Dormlq(side blas.Side, trans blas.Transpose, m, n, k int, a []float64, lda int, tau, c []float64, ldc int, work []float64, lwork int) {
31 if side != blas.Left && side != blas.Right {
34 if trans != blas.Trans && trans != blas.NoTrans {
37 left := side == blas.Left
39 checkMatrix(k, m, a, lda)
41 checkMatrix(k, n, a, lda)
43 checkMatrix(m, n, c, ldc)
47 if len(work) < lwork {
54 if lwork < max(1, nw) && lwork != -1 {
58 if m == 0 || n == 0 || k == 0 {
68 opts := string(side) + string(trans)
69 nb := min(nbmax, impl.Ilaenv(1, "DORMLQ", opts, m, n, k, -1))
70 lworkopt := max(1, nw)*nb + tsize
72 work[0] = float64(lworkopt)
80 nb = (lwork - tsize) / nw
81 nbmin = max(2, impl.Ilaenv(2, "DORMLQ", opts, m, n, k, -1))
84 if nb < nbmin || k <= nb {
85 // Call unblocked code.
86 impl.Dorml2(side, trans, m, n, k, a, lda, tau, c, ldc, work)
87 work[0] = float64(lworkopt)
95 notran := trans == blas.NoTrans
96 transt := blas.NoTrans
103 for i := 0; i < k; i += nb {
105 impl.Dlarft(lapack.Forward, lapack.RowWise, m-i, ib,
109 impl.Dlarfb(side, transt, lapack.Forward, lapack.RowWise, m-i, n, ib,
116 case left && !notran:
117 for i := ((k - 1) / nb) * nb; i >= 0; i -= nb {
119 impl.Dlarft(lapack.Forward, lapack.RowWise, m-i, ib,
123 impl.Dlarfb(side, transt, lapack.Forward, lapack.RowWise, m-i, n, ib,
130 case !left && notran:
131 for i := ((k - 1) / nb) * nb; i >= 0; i -= nb {
133 impl.Dlarft(lapack.Forward, lapack.RowWise, n-i, ib,
137 impl.Dlarfb(side, transt, lapack.Forward, lapack.RowWise, m, n-i, ib,
144 case !left && !notran:
145 for i := 0; i < k; i += nb {
147 impl.Dlarft(lapack.Forward, lapack.RowWise, n-i, ib,
151 impl.Dlarfb(side, transt, lapack.Forward, lapack.RowWise, m, n-i, ib,
158 work[0] = float64(lworkopt)