OSDN Git Service

new repo
[bytom/vapor.git] / vendor / gonum.org / v1 / gonum / lapack / gonum / dlapmt.go
1 // Copyright ©2017 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 "gonum.org/v1/gonum/blas/blas64"
8
9 // Dlapmt rearranges the columns of the m×n matrix X as specified by the
10 // permutation k_0, k_1, ..., k_n-1 of the integers 0, ..., n-1.
11 //
12 // If forward is true a forward permutation is performed:
13 //
14 //  X[0:m, k[j]] is moved to X[0:m, j] for j = 0, 1, ..., n-1.
15 //
16 // otherwise a backward permutation is performed:
17 //
18 //  X[0:m, j] is moved to X[0:m, k[j]] for j = 0, 1, ..., n-1.
19 //
20 // k must have length n, otherwise Dlapmt will panic. k is zero-indexed.
21 func (impl Implementation) Dlapmt(forward bool, m, n int, x []float64, ldx int, k []int) {
22         checkMatrix(m, n, x, ldx)
23         if len(k) != n {
24                 panic(badKperm)
25         }
26
27         if n <= 1 {
28                 return
29         }
30
31         for i, v := range k {
32                 v++
33                 k[i] = -v
34         }
35
36         bi := blas64.Implementation()
37
38         if forward {
39                 for j, v := range k {
40                         if v >= 0 {
41                                 continue
42                         }
43                         k[j] = -v
44                         i := -v - 1
45                         for k[i] < 0 {
46                                 bi.Dswap(m, x[j:], ldx, x[i:], ldx)
47
48                                 k[i] = -k[i]
49                                 j = i
50                                 i = k[i] - 1
51                         }
52                 }
53         } else {
54                 for i, v := range k {
55                         if v >= 0 {
56                                 continue
57                         }
58                         k[i] = -v
59                         j := -v - 1
60                         for j != i {
61                                 bi.Dswap(m, x[j:], ldx, x[i:], ldx)
62
63                                 k[j] = -k[j]
64                                 j = k[j] - 1
65                         }
66                 }
67         }
68
69         for i := range k {
70                 k[i]--
71         }
72 }