mirror of
https://github.com/gonum/gonum.git
synced 2025-10-06 07:37:03 +08:00
mat: add minimal shadow detection for complex matrices
This commit is contained in:
@@ -22,3 +22,18 @@ func offset(a, b []float64) int {
|
||||
// move. See https://golang.org/issue/12445.
|
||||
return int(vb0.UnsafeAddr()-va0.UnsafeAddr()) / sizeOfFloat64
|
||||
}
|
||||
|
||||
var sizeOfComplex128 = int(reflect.TypeOf(complex128(0)).Size())
|
||||
|
||||
// offsetComplex returns the number of complex128 values b[0] is after a[0].
|
||||
func offsetComplex(a, b []complex128) int {
|
||||
va0 := reflect.ValueOf(a).Index(0)
|
||||
vb0 := reflect.ValueOf(b).Index(0)
|
||||
if va0.Addr() == vb0.Addr() {
|
||||
return 0
|
||||
}
|
||||
// This expression must be atomic with respect to GC moves.
|
||||
// At this stage this is true, because the GC does not
|
||||
// move. See https://golang.org/issue/12445.
|
||||
return int(vb0.UnsafeAddr()-va0.UnsafeAddr()) / sizeOfComplex128
|
||||
}
|
||||
|
Reference in New Issue
Block a user