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.
8 "gonum.org/v1/gonum/blas/blas64"
9 "gonum.org/v1/gonum/lapack"
12 // Dgebak updates an n×m matrix V as
13 // V = P D V, if side == lapack.RightEV,
14 // V = P D^{-1} V, if side == lapack.LeftEV,
15 // where P and D are n×n permutation and scaling matrices, respectively,
16 // implicitly represented by job, scale, ilo and ihi as returned by Dgebal.
18 // Typically, columns of the matrix V contain the right or left (determined by
19 // side) eigenvectors of the balanced matrix output by Dgebal, and Dgebak forms
20 // the eigenvectors of the original matrix.
22 // Dgebak is an internal routine. It is exported for testing purposes.
23 func (impl Implementation) Dgebak(job lapack.Job, side lapack.EVSide, n, ilo, ihi int, scale []float64, m int, v []float64, ldv int) {
27 case lapack.None, lapack.Permute, lapack.Scale, lapack.PermuteScale:
32 case lapack.LeftEV, lapack.RightEV:
34 checkMatrix(n, m, v, ldv)
36 case ilo < 0 || max(0, n-1) < ilo:
38 case ihi < min(ilo, n-1) || n <= ihi:
42 // Quick return if possible.
43 if n == 0 || m == 0 || job == lapack.None {
47 bi := blas64.Implementation()
48 if ilo != ihi && job != lapack.Permute {
50 if side == lapack.RightEV {
51 for i := ilo; i <= ihi; i++ {
52 bi.Dscal(m, scale[i], v[i*ldv:], 1)
55 for i := ilo; i <= ihi; i++ {
56 bi.Dscal(m, 1/scale[i], v[i*ldv:], 1)
60 if job == lapack.Scale {
63 // Backward permutation.
64 for i := ilo - 1; i >= 0; i-- {
69 bi.Dswap(m, v[i*ldv:], 1, v[k*ldv:], 1)
71 for i := ihi + 1; i < n; i++ {
76 bi.Dswap(m, v[i*ldv:], 1, v[k*ldv:], 1)