dlauu2.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Copyright ©2018 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 (
  6. "gonum.org/v1/gonum/blas"
  7. "gonum.org/v1/gonum/blas/blas64"
  8. )
  9. // Dlauu2 computes the product
  10. // U * Uᵀ if uplo is blas.Upper
  11. // Lᵀ * L if uplo is blas.Lower
  12. // where U or L is stored in the upper or lower triangular part of A.
  13. // Only the upper or lower triangle of the result is stored, overwriting
  14. // the corresponding factor in A.
  15. func (impl Implementation) Dlauu2(uplo blas.Uplo, n int, a []float64, lda int) {
  16. switch {
  17. case uplo != blas.Upper && uplo != blas.Lower:
  18. panic(badUplo)
  19. case n < 0:
  20. panic(nLT0)
  21. case lda < max(1, n):
  22. panic(badLdA)
  23. }
  24. // Quick return if possible.
  25. if n == 0 {
  26. return
  27. }
  28. if len(a) < (n-1)*lda+n {
  29. panic(shortA)
  30. }
  31. bi := blas64.Implementation()
  32. if uplo == blas.Upper {
  33. // Compute the product U*Uᵀ.
  34. for i := 0; i < n; i++ {
  35. aii := a[i*lda+i]
  36. if i < n-1 {
  37. a[i*lda+i] = bi.Ddot(n-i, a[i*lda+i:], 1, a[i*lda+i:], 1)
  38. bi.Dgemv(blas.NoTrans, i, n-i-1, 1, a[i+1:], lda, a[i*lda+i+1:], 1,
  39. aii, a[i:], lda)
  40. } else {
  41. bi.Dscal(i+1, aii, a[i:], lda)
  42. }
  43. }
  44. } else {
  45. // Compute the product Lᵀ*L.
  46. for i := 0; i < n; i++ {
  47. aii := a[i*lda+i]
  48. if i < n-1 {
  49. a[i*lda+i] = bi.Ddot(n-i, a[i*lda+i:], lda, a[i*lda+i:], lda)
  50. bi.Dgemv(blas.Trans, n-i-1, i, 1, a[(i+1)*lda:], lda, a[(i+1)*lda+i:], lda,
  51. aii, a[i*lda:], 1)
  52. } else {
  53. bi.Dscal(i+1, aii, a[i*lda:], 1)
  54. }
  55. }
  56. }
  57. }