1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
|
// Copyright ©2015 The Gonum Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package gonum
import (
"gonum.org/v1/gonum/blas"
"gonum.org/v1/gonum/lapack"
)
// Dormlq multiplies the matrix C by the orthogonal matrix Q defined by the
// slices a and tau. A and tau are as returned from Dgelqf.
//
// C = Q * C if side == blas.Left and trans == blas.NoTrans
// C = Qᵀ * C if side == blas.Left and trans == blas.Trans
// C = C * Q if side == blas.Right and trans == blas.NoTrans
// C = C * Qᵀ if side == blas.Right and trans == blas.Trans
//
// If side == blas.Left, A is a matrix of side k×m, and if side == blas.Right
// A is of size k×n. This uses a blocked algorithm.
//
// work is temporary storage, and lwork specifies the usable memory length.
// At minimum, lwork >= m if side == blas.Left and lwork >= n if side == blas.Right,
// and this function will panic otherwise.
// Dormlq uses a block algorithm, but the block size is limited
// by the temporary space available. If lwork == -1, instead of performing Dormlq,
// the optimal work length will be stored into work[0].
//
// tau contains the Householder scales and must have length at least k, and
// this function will panic otherwise.
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) {
left := side == blas.Left
nw := m
if left {
nw = n
}
switch {
case !left && side != blas.Right:
panic(badSide)
case trans != blas.Trans && trans != blas.NoTrans:
panic(badTrans)
case m < 0:
panic(mLT0)
case n < 0:
panic(nLT0)
case k < 0:
panic(kLT0)
case left && k > m:
panic(kGTM)
case !left && k > n:
panic(kGTN)
case left && lda < max(1, m):
panic(badLdA)
case !left && lda < max(1, n):
panic(badLdA)
case lwork < max(1, nw) && lwork != -1:
panic(badLWork)
case len(work) < max(1, lwork):
panic(shortWork)
}
// Quick return if possible.
if m == 0 || n == 0 || k == 0 {
work[0] = 1
return
}
const (
nbmax = 64
ldt = nbmax
tsize = nbmax * ldt
)
opts := string(side) + string(trans)
nb := min(nbmax, impl.Ilaenv(1, "DORMLQ", opts, m, n, k, -1))
lworkopt := max(1, nw)*nb + tsize
if lwork == -1 {
work[0] = float64(lworkopt)
return
}
switch {
case left && len(a) < (k-1)*lda+m:
panic(shortA)
case !left && len(a) < (k-1)*lda+n:
panic(shortA)
case len(tau) < k:
panic(shortTau)
case len(c) < (m-1)*ldc+n:
panic(shortC)
}
nbmin := 2
if 1 < nb && nb < k {
iws := nw*nb + tsize
if lwork < iws {
nb = (lwork - tsize) / nw
nbmin = max(2, impl.Ilaenv(2, "DORMLQ", opts, m, n, k, -1))
}
}
if nb < nbmin || k <= nb {
// Call unblocked code.
impl.Dorml2(side, trans, m, n, k, a, lda, tau, c, ldc, work)
work[0] = float64(lworkopt)
return
}
t := work[:tsize]
wrk := work[tsize:]
ldwrk := nb
notrans := trans == blas.NoTrans
transt := blas.NoTrans
if notrans {
transt = blas.Trans
}
switch {
case left && notrans:
for i := 0; i < k; i += nb {
ib := min(nb, k-i)
impl.Dlarft(lapack.Forward, lapack.RowWise, m-i, ib,
a[i*lda+i:], lda,
tau[i:],
t, ldt)
impl.Dlarfb(side, transt, lapack.Forward, lapack.RowWise, m-i, n, ib,
a[i*lda+i:], lda,
t, ldt,
c[i*ldc:], ldc,
wrk, ldwrk)
}
case left && !notrans:
for i := ((k - 1) / nb) * nb; i >= 0; i -= nb {
ib := min(nb, k-i)
impl.Dlarft(lapack.Forward, lapack.RowWise, m-i, ib,
a[i*lda+i:], lda,
tau[i:],
t, ldt)
impl.Dlarfb(side, transt, lapack.Forward, lapack.RowWise, m-i, n, ib,
a[i*lda+i:], lda,
t, ldt,
c[i*ldc:], ldc,
wrk, ldwrk)
}
case !left && notrans:
for i := ((k - 1) / nb) * nb; i >= 0; i -= nb {
ib := min(nb, k-i)
impl.Dlarft(lapack.Forward, lapack.RowWise, n-i, ib,
a[i*lda+i:], lda,
tau[i:],
t, ldt)
impl.Dlarfb(side, transt, lapack.Forward, lapack.RowWise, m, n-i, ib,
a[i*lda+i:], lda,
t, ldt,
c[i:], ldc,
wrk, ldwrk)
}
case !left && !notrans:
for i := 0; i < k; i += nb {
ib := min(nb, k-i)
impl.Dlarft(lapack.Forward, lapack.RowWise, n-i, ib,
a[i*lda+i:], lda,
tau[i:],
t, ldt)
impl.Dlarfb(side, transt, lapack.Forward, lapack.RowWise, m, n-i, ib,
a[i*lda+i:], lda,
t, ldt,
c[i:], ldc,
wrk, ldwrk)
}
}
work[0] = float64(lworkopt)
}
|