zfs-localpv/vendor/gonum.org/v1/gonum/lapack/gonum/dlapmt.go
prateekpandey14 fa76b346a0 feat(modules): migrate to go modules and bump go version 1.14.4
- migrate to go module
- bump go version 1.14.4

Signed-off-by: prateekpandey14 <prateek.pandey@mayadata.io>
2020-06-09 22:27:01 +05:30

89 lines
1.6 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 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]--
}
}