offset_appengine.go 728 B

12345678910111213141516171819202122232425
  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. // +build appengine safe
  5. package mat
  6. import "reflect"
  7. var sizeOfFloat64 = int(reflect.TypeOf(float64(0)).Size())
  8. // offset returns the number of float64 values b[0] is after a[0].
  9. func offset(a, b []float64) int {
  10. va0 := reflect.ValueOf(a).Index(0)
  11. vb0 := reflect.ValueOf(b).Index(0)
  12. if va0.Addr() == vb0.Addr() {
  13. return 0
  14. }
  15. // This expression must be atomic with respect to GC moves.
  16. // At this stage this is true, because the GC does not
  17. // move. See https://golang.org/issue/12445.
  18. return int(vb0.UnsafeAddr()-va0.UnsafeAddr()) / sizeOfFloat64
  19. }