github.com/gopherd/gonum@v0.0.4/lapack/gonum/dormhr.go (about) 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. 4 5 package gonum 6 7 import "github.com/gopherd/gonum/blas" 8 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ᵀ * C if side == blas.Left and trans == blas.Trans, 12 // C * Q if side == blas.Right and trans == blas.NoTrans, 13 // C * Qᵀ if side == blas.Right and trans == blas.Trans, 14 // where nq == m if side == blas.Left and nq == n if side == blas.Right. 15 // 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]. 21 // 22 // ilo and ihi must have the same values as in the previous call of Dgehrd. It 23 // must hold that 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. 28 // 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. 32 // 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 == 35 // blas.Right. 36 // 37 // c and ldc represent the m×n matrix C. On return, c is overwritten by the 38 // product with Q. 39 // 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. 45 // 46 // If lwork == -1, instead of performing Dormhr, only the optimal value of lwork 47 // will be stored in work[0]. 48 // 49 // If any requirement on input sizes is not met, Dormhr will panic. 50 // 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) { 53 nq := n // The order of Q. 54 nw := m // The minimum length of work. 55 if side == blas.Left { 56 nq = m 57 nw = n 58 } 59 switch { 60 case side != blas.Left && side != blas.Right: 61 panic(badSide) 62 case trans != blas.NoTrans && trans != blas.Trans: 63 panic(badTrans) 64 case m < 0: 65 panic(mLT0) 66 case n < 0: 67 panic(nLT0) 68 case ilo < 0 || max(1, nq) <= ilo: 69 panic(badIlo) 70 case ihi < min(ilo, nq-1) || nq <= ihi: 71 panic(badIhi) 72 case lda < max(1, nq): 73 panic(badLdA) 74 case lwork < max(1, nw) && lwork != -1: 75 panic(badLWork) 76 case len(work) < max(1, lwork): 77 panic(shortWork) 78 } 79 80 // Quick return if possible. 81 if m == 0 || n == 0 { 82 work[0] = 1 83 return 84 } 85 86 nh := ihi - ilo 87 var nb int 88 if side == blas.Left { 89 opts := "LN" 90 if trans == blas.Trans { 91 opts = "LT" 92 } 93 nb = impl.Ilaenv(1, "DORMQR", opts, nh, n, nh, -1) 94 } else { 95 opts := "RN" 96 if trans == blas.Trans { 97 opts = "RT" 98 } 99 nb = impl.Ilaenv(1, "DORMQR", opts, m, nh, nh, -1) 100 } 101 lwkopt := max(1, nw) * nb 102 if lwork == -1 { 103 work[0] = float64(lwkopt) 104 return 105 } 106 107 if nh == 0 { 108 work[0] = 1 109 return 110 } 111 112 switch { 113 case len(a) < (nq-1)*lda+nq: 114 panic(shortA) 115 case len(c) < (m-1)*ldc+n: 116 panic(shortC) 117 case len(tau) != nq-1: 118 panic(badLenTau) 119 } 120 121 if side == blas.Left { 122 impl.Dormqr(side, trans, nh, n, nh, a[(ilo+1)*lda+ilo:], lda, 123 tau[ilo:ihi], c[(ilo+1)*ldc:], ldc, work, lwork) 124 } else { 125 impl.Dormqr(side, trans, m, nh, nh, a[(ilo+1)*lda+ilo:], lda, 126 tau[ilo:ihi], c[ilo+1:], ldc, work, lwork) 127 } 128 work[0] = float64(lwkopt) 129 }