-
Notifications
You must be signed in to change notification settings - Fork 0
/
array_no_bounds_checks.go
83 lines (66 loc) · 1.86 KB
/
array_no_bounds_checks.go
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Copyright ©2018 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.
// This file must be kept in sync with array_bound_checks.go.
//go:build !bounds
// +build !bounds
package fftpack
// The types in array.go implement Fortran-like arrays for bootstrapping
// the implementation of the FFT functions translated from FFTPACK; they
// are column-major.
type twoArray struct {
jStride int
data []float64
}
func newTwoArray(i, j int, data []float64) twoArray {
if len(data) < i*j {
panic("fourier: short data")
}
return twoArray{
jStride: i,
data: data[:i*j],
}
}
func (a twoArray) at(i, j int) float64 {
return a.data[i+a.jStride*j]
}
func (a twoArray) atCmplx(i, j int) complex128 {
return complex(a.data[i+a.jStride*j], a.data[i+a.jStride*j+1])
}
func (a twoArray) set(i, j int, v float64) {
a.data[i+a.jStride*j] = v
}
func (a twoArray) setCmplx(i, j int, v complex128) {
a.data[i+a.jStride*j] = real(v)
a.data[i+a.jStride*j+1] = imag(v)
}
func (a twoArray) add(i, j int, v float64) {
a.data[i+a.jStride*j] += v
}
type threeArray struct {
jStride, kStride int
data []float64
}
func newThreeArray(i, j, k int, data []float64) threeArray {
if len(data) < i*j*k {
panic("fourier: short data")
}
return threeArray{
jStride: i,
kStride: i * j,
data: data[:i*j*k],
}
}
func (a threeArray) at(i, j, k int) float64 {
return a.data[i+a.jStride*j+a.kStride*k]
}
func (a threeArray) atCmplx(i, j, k int) complex128 {
return complex(a.data[i+a.jStride*j+a.kStride*k], a.data[i+a.jStride*j+a.kStride*k+1])
}
func (a threeArray) set(i, j, k int, v float64) {
a.data[i+a.jStride*j+a.kStride*k] = v
}
func (a threeArray) setCmplx(i, j, k int, v complex128) {
a.data[i+a.jStride*j+a.kStride*k] = real(v)
a.data[i+a.jStride*j+a.kStride*k+1] = imag(v)
}