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