File: offset_appengine.go

package info (click to toggle)
golang-gonum-v1-gonum 0.15.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 18,792 kB
  • sloc: asm: 6,252; fortran: 5,271; sh: 377; ruby: 211; makefile: 98
file content (40 lines) | stat: -rw-r--r-- 1,270 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Copyright ©2015 The Gonum Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build safe
// +build safe

package mat

import "reflect"

var sizeOfFloat64 = int(reflect.TypeOf(float64(0)).Size())

// offset returns the number of float64 values b[0] is after a[0].
func offset(a, b []float64) 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()) / 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
}