gonum.org/v1/gonum@v0.14.0/lapack/gonum/dlaswp.go (about)

     1  // Copyright ©2015 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  // Dlaswp swaps the rows k1 to k2 of a rectangular matrix A according to the
    10  // indices in ipiv so that row k is swapped with ipiv[k].
    11  //
    12  // n is the number of columns of A and incX is the increment for ipiv. If incX
    13  // is 1, the swaps are applied from k1 to k2. If incX is -1, the swaps are
    14  // applied in reverse order from k2 to k1. For other values of incX Dlaswp will
    15  // panic. ipiv must have length k2+1, otherwise Dlaswp will panic.
    16  //
    17  // The indices k1, k2, and the elements of ipiv are zero-based.
    18  //
    19  // Dlaswp is an internal routine. It is exported for testing purposes.
    20  func (impl Implementation) Dlaswp(n int, a []float64, lda int, k1, k2 int, ipiv []int, incX int) {
    21  	switch {
    22  	case n < 0:
    23  		panic(nLT0)
    24  	case k1 < 0:
    25  		panic(badK1)
    26  	case k2 < k1:
    27  		panic(badK2)
    28  	case lda < max(1, n):
    29  		panic(badLdA)
    30  	case len(a) < k2*lda+n: // A must have at least k2+1 rows.
    31  		panic(shortA)
    32  	case len(ipiv) != k2+1:
    33  		panic(badLenIpiv)
    34  	case incX != 1 && incX != -1:
    35  		panic(absIncNotOne)
    36  	}
    37  
    38  	if n == 0 {
    39  		return
    40  	}
    41  
    42  	bi := blas64.Implementation()
    43  	if incX == 1 {
    44  		for k := k1; k <= k2; k++ {
    45  			if k == ipiv[k] {
    46  				continue
    47  			}
    48  			bi.Dswap(n, a[k*lda:], 1, a[ipiv[k]*lda:], 1)
    49  		}
    50  		return
    51  	}
    52  	for k := k2; k >= k1; k-- {
    53  		if k == ipiv[k] {
    54  			continue
    55  		}
    56  		bi.Dswap(n, a[k*lda:], 1, a[ipiv[k]*lda:], 1)
    57  	}
    58  }