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
|
// 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/blas/blas64"
)
// Dorg2r generates an m×n matrix Q with orthonormal columns defined by the
// product of elementary reflectors as computed by Dgeqrf.
//
// Q = H_0 * H_1 * ... * H_{k-1}
//
// len(tau) = k, 0 <= k <= n, 0 <= n <= m, len(work) >= n.
// Dorg2r will panic if these conditions are not met.
//
// Dorg2r is an internal routine. It is exported for testing purposes.
func (impl Implementation) Dorg2r(m, n, k int, a []float64, lda int, tau []float64, work []float64) {
switch {
case m < 0:
panic(mLT0)
case n < 0:
panic(nLT0)
case n > m:
panic(nGTM)
case k < 0:
panic(kLT0)
case k > n:
panic(kGTN)
case lda < max(1, n):
panic(badLdA)
}
if n == 0 {
return
}
switch {
case len(a) < (m-1)*lda+n:
panic(shortA)
case len(tau) != k:
panic(badLenTau)
case len(work) < n:
panic(shortWork)
}
bi := blas64.Implementation()
// Initialize columns k+1:n to columns of the unit matrix.
for l := 0; l < m; l++ {
for j := k; j < n; j++ {
a[l*lda+j] = 0
}
}
for j := k; j < n; j++ {
a[j*lda+j] = 1
}
for i := k - 1; i >= 0; i-- {
for i := range work {
work[i] = 0
}
if i < n-1 {
a[i*lda+i] = 1
impl.Dlarf(blas.Left, m-i, n-i-1, a[i*lda+i:], lda, tau[i], a[i*lda+i+1:], lda, work)
}
if i < m-1 {
bi.Dscal(m-i-1, -tau[i], a[(i+1)*lda+i:], lda)
}
a[i*lda+i] = 1 - tau[i]
for l := 0; l < i; l++ {
a[l*lda+i] = 0
}
}
}
|