1 // Copyright ©2016 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.
7 import "gonum.org/v1/gonum/blas"
9 // Dgehd2 reduces a block of a general n×n matrix A to upper Hessenberg form H
10 // by an orthogonal similarity transformation Q^T * A * Q = H.
12 // The matrix Q is represented as a product of (ihi-ilo) elementary
14 // Q = H_{ilo} H_{ilo+1} ... H_{ihi-1}.
15 // Each H_i has the form
16 // H_i = I - tau[i] * v * v^T
17 // where v is a real vector with v[0:i+1] = 0, v[i+1] = 1 and v[ihi+1:n] = 0.
18 // v[i+2:ihi+1] is stored on exit in A[i+2:ihi+1,i].
20 // On entry, a contains the n×n general matrix to be reduced. On return, the
21 // upper triangle and the first subdiagonal of A are overwritten with the upper
22 // Hessenberg matrix H, and the elements below the first subdiagonal, with the
23 // slice tau, represent the orthogonal matrix Q as a product of elementary
26 // The contents of A are illustrated by the following example, with n = 7, ilo =
44 // where a denotes an element of the original matrix A, h denotes a
45 // modified element of the upper Hessenberg matrix H, and vi denotes an
46 // element of the vector defining H_i.
48 // ilo and ihi determine the block of A that will be reduced to upper Hessenberg
49 // form. It must hold that 0 <= ilo <= ihi <= max(0, n-1), otherwise Dgehd2 will
52 // On return, tau will contain the scalar factors of the elementary reflectors.
53 // It must have length equal to n-1, otherwise Dgehd2 will panic.
55 // work must have length at least n, otherwise Dgehd2 will panic.
57 // Dgehd2 is an internal routine. It is exported for testing purposes.
58 func (impl Implementation) Dgehd2(n, ilo, ihi int, a []float64, lda int, tau, work []float64) {
59 checkMatrix(n, n, a, lda)
61 case ilo < 0 || ilo > max(0, n-1):
63 case ihi < min(ilo, n-1) || ihi >= n:
71 for i := ilo; i < ihi; i++ {
72 // Compute elementary reflector H_i to annihilate A[i+2:ihi+1,i].
74 aii, tau[i] = impl.Dlarfg(ihi-i, a[(i+1)*lda+i], a[min(i+2, n-1)*lda+i:], lda)
77 // Apply H_i to A[0:ihi+1,i+1:ihi+1] from the right.
78 impl.Dlarf(blas.Right, ihi+1, ihi-i, a[(i+1)*lda+i:], lda, tau[i], a[i+1:], lda, work)
80 // Apply H_i to A[i+1:ihi+1,i+1:n] from the left.
81 impl.Dlarf(blas.Left, ihi-i, n-i-1, a[(i+1)*lda+i:], lda, tau[i], a[(i+1)*lda+i+1:], lda, work)