1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
// Copyright ©2017 The Gonum Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package gonum
import "gonum.org/v1/gonum/blas/blas64"
// Dlapmt rearranges the columns of the m×n matrix X as specified by the
// permutation k_0, k_1, ..., k_n-1 of the integers 0, ..., n-1.
//
// If forward is true a forward permutation is performed:
//
// X[0:m, k[j]] is moved to X[0:m, j] for j = 0, 1, ..., n-1.
//
// otherwise a backward permutation is performed:
//
// X[0:m, j] is moved to X[0:m, k[j]] for j = 0, 1, ..., n-1.
//
// k must have length n, otherwise Dlapmt will panic. k is zero-indexed.
func (impl Implementation) Dlapmt(forward bool, m, n int, x []float64, ldx int, k []int) {
switch {
case m < 0:
panic(mLT0)
case n < 0:
panic(nLT0)
case ldx < max(1, n):
panic(badLdX)
}
// Quick return if possible.
if m == 0 || n == 0 {
return
}
switch {
case len(x) < (m-1)*ldx+n:
panic(shortX)
case len(k) != n:
panic(badLenK)
}
// Quick return if possible.
if n == 1 {
return
}
for i, v := range k {
v++
k[i] = -v
}
bi := blas64.Implementation()
if forward {
for j, v := range k {
if v >= 0 {
continue
}
k[j] = -v
i := -v - 1
for k[i] < 0 {
bi.Dswap(m, x[j:], ldx, x[i:], ldx)
k[i] = -k[i]
j = i
i = k[i] - 1
}
}
} else {
for i, v := range k {
if v >= 0 {
continue
}
k[i] = -v
j := -v - 1
for j != i {
bi.Dswap(m, x[j:], ldx, x[i:], ldx)
k[j] = -k[j]
j = k[j] - 1
}
}
}
for i := range k {
k[i]--
}
}
|