dlaswp.go 1.4 KB

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