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 // Dormhr multiplies an m×n general matrix C with an nq×nq orthogonal matrix Q
10 // Q * C, if side == blas.Left and trans == blas.NoTrans,
11 // Q^T * C, if side == blas.Left and trans == blas.Trans,
12 // C * Q, if side == blas.Right and trans == blas.NoTrans,
13 // C * Q^T, if side == blas.Right and trans == blas.Trans,
14 // where nq == m if side == blas.Left and nq == n if side == blas.Right.
16 // Q is defined implicitly as the product of ihi-ilo elementary reflectors, as
17 // returned by Dgehrd:
18 // Q = H_{ilo} H_{ilo+1} ... H_{ihi-1}.
19 // Q is equal to the identity matrix except in the submatrix
20 // Q[ilo+1:ihi+1,ilo+1:ihi+1].
22 // ilo and ihi must have the same values as in the previous call of Dgehrd. It
24 // 0 <= ilo <= ihi < m, if m > 0 and side == blas.Left,
25 // ilo = 0 and ihi = -1, if m = 0 and side == blas.Left,
26 // 0 <= ilo <= ihi < n, if n > 0 and side == blas.Right,
27 // ilo = 0 and ihi = -1, if n = 0 and side == blas.Right.
29 // a and lda represent an m×m matrix if side == blas.Left and an n×n matrix if
30 // side == blas.Right. The matrix contains vectors which define the elementary
31 // reflectors, as returned by Dgehrd.
33 // tau contains the scalar factors of the elementary reflectors, as returned by
34 // Dgehrd. tau must have length m-1 if side == blas.Left and n-1 if side ==
37 // c and ldc represent the m×n matrix C. On return, c is overwritten by the
40 // work must have length at least max(1,lwork), and lwork must be at least
41 // max(1,n), if side == blas.Left, and max(1,m), if side == blas.Right. For
42 // optimum performance lwork should be at least n*nb if side == blas.Left and
43 // m*nb if side == blas.Right, where nb is the optimal block size. On return,
44 // work[0] will contain the optimal value of lwork.
46 // If lwork == -1, instead of performing Dormhr, only the optimal value of lwork
47 // will be stored in work[0].
49 // If any requirement on input sizes is not met, Dormhr will panic.
51 // Dormhr is an internal routine. It is exported for testing purposes.
52 func (impl Implementation) Dormhr(side blas.Side, trans blas.Transpose, m, n, ilo, ihi int, a []float64, lda int, tau, c []float64, ldc int, work []float64, lwork int) {
54 nq int // The order of Q.
55 nw int // The minimum length of work.
68 case trans != blas.NoTrans && trans != blas.Trans:
70 case ilo < 0 || max(1, nq) <= ilo:
72 case ihi < min(ilo, nq-1) || nq <= ihi:
74 case lwork < max(1, nw) && lwork != -1:
76 case len(work) < max(1, lwork):
80 checkMatrix(m, n, c, ldc)
81 checkMatrix(nq, nq, a, lda)
82 if len(tau) != nq-1 && nq > 0 {
90 if side == blas.Left {
92 if trans == blas.Trans {
95 nb = impl.Ilaenv(1, "DORMQR", opts, nh, n, nh, -1)
98 if trans == blas.Trans {
101 nb = impl.Ilaenv(1, "DORMQR", opts, m, nh, nh, -1)
103 lwkopt := max(1, nw) * nb
105 work[0] = float64(lwkopt)
109 if m == 0 || n == 0 || nh == 0 {
113 if side == blas.Left {
114 impl.Dormqr(side, trans, nh, n, nh, a[(ilo+1)*lda+ilo:], lda,
115 tau[ilo:ihi], c[(ilo+1)*ldc:], ldc, work, lwork)
117 impl.Dormqr(side, trans, m, nh, nh, a[(ilo+1)*lda+ilo:], lda,
118 tau[ilo:ihi], c[ilo+1:], ldc, work, lwork)
120 work[0] = float64(lwkopt)