shadow_complex.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. // TODO(kortschak): Generate this file from shadow.go when all complex type are available.
  5. package mat
  6. import "gonum.org/v1/gonum/blas/cblas128"
  7. // checkOverlapComplex returns false if the receiver does not overlap data elements
  8. // referenced by the parameter and panics otherwise.
  9. //
  10. // checkOverlapComplex methods return a boolean to allow the check call to be added to a
  11. // boolean expression, making use of short-circuit operators.
  12. func checkOverlapComplex(a, b cblas128.General) bool {
  13. if cap(a.Data) == 0 || cap(b.Data) == 0 {
  14. return false
  15. }
  16. off := offsetComplex(a.Data[:1], b.Data[:1])
  17. if off == 0 {
  18. // At least one element overlaps.
  19. if a.Cols == b.Cols && a.Rows == b.Rows && a.Stride == b.Stride {
  20. panic(regionIdentity)
  21. }
  22. panic(regionOverlap)
  23. }
  24. if off > 0 && len(a.Data) <= off {
  25. // We know a is completely before b.
  26. return false
  27. }
  28. if off < 0 && len(b.Data) <= -off {
  29. // We know a is completely after b.
  30. return false
  31. }
  32. if a.Stride != b.Stride && a.Stride != 1 && b.Stride != 1 {
  33. // Too hard, so assume the worst; if either stride
  34. // is one it will be caught in rectanglesOverlap.
  35. panic(mismatchedStrides)
  36. }
  37. if off < 0 {
  38. off = -off
  39. a.Cols, b.Cols = b.Cols, a.Cols
  40. }
  41. if rectanglesOverlap(off, a.Cols, b.Cols, min(a.Stride, b.Stride)) {
  42. panic(regionOverlap)
  43. }
  44. return false
  45. }
  46. func (m *CDense) checkOverlapComplex(a cblas128.General) bool {
  47. return checkOverlapComplex(m.RawCMatrix(), a)
  48. }
  49. func (m *CDense) checkOverlapMatrix(a CMatrix) bool {
  50. if m == a {
  51. return false
  52. }
  53. var amat cblas128.General
  54. switch ar := a.(type) {
  55. default:
  56. return false
  57. case RawCMatrixer:
  58. amat = ar.RawCMatrix()
  59. }
  60. return m.checkOverlapComplex(amat)
  61. }