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