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 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
|
// 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_no_bound_checks.go.
//go:build bounds
// +build bounds
package fftpack
import "fmt"
// 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 {
i, j int
jStride int
data []float64
}
func newTwoArray(i, j int, data []float64) twoArray {
if len(data) < i*j {
panic(fmt.Sprintf("short data: len(data)=%d, i=%d, j=%d", len(data), i, j))
}
return twoArray{
i: i,
j: j,
jStride: i,
data: data[:i*j],
}
}
func (a twoArray) at(i, j int) float64 {
if i < 0 || a.i <= i || j < 0 || a.j <= j {
panic(fmt.Sprintf("out of bounds at(%d, %d): bounds i=%d, j=%d", i, j, a.i, a.j))
}
return a.data[i+a.jStride*j]
}
func (a twoArray) atCmplx(i, j int) complex128 {
if i < 0 || a.i <= i || j < 0 || a.j <= j {
panic(fmt.Sprintf("out of bounds at(%d, %d): bounds i=%d, j=%d", i, j, a.i, a.j))
}
return complex(a.data[i+a.jStride*j], a.data[i+a.jStride*j+1])
}
func (a twoArray) set(i, j int, v float64) {
if i < 0 || a.i <= i || j < 0 || a.j <= j {
panic(fmt.Sprintf("out of bounds set(%d, %d): bounds i=%d, j=%d", i, j, a.i, a.j))
}
a.data[i+a.jStride*j] = v
}
func (a twoArray) setCmplx(i, j int, v complex128) {
if i < 0 || a.i <= i || j < 0 || a.j <= j {
panic(fmt.Sprintf("out of bounds set(%d, %d): bounds i=%d, j=%d", i, j, a.i, a.j))
}
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) {
if i < 0 || a.i <= i || j < 0 || a.j <= j {
panic(fmt.Sprintf("out of bounds set(%d, %d): bounds i=%d, j=%d", i, j, a.i, a.j))
}
a.data[i+a.jStride*j] += v
}
type threeArray struct {
i, j, k int
jStride, kStride int
data []float64
}
func newThreeArray(i, j, k int, data []float64) threeArray {
if len(data) < i*j*k {
panic(fmt.Sprintf("short data: len(data)=%d, i=%d, j=%d, k=%d", len(data), i, j, k))
}
return threeArray{
i: i,
j: j,
k: k,
jStride: i,
kStride: i * j,
data: data[:i*j*k],
}
}
func (a threeArray) at(i, j, k int) float64 {
if i < 0 || a.i <= i || j < 0 || a.j <= j || k < 0 || a.k <= k {
panic(fmt.Sprintf("out of bounds at(%d, %d, %d): bounds i=%d, j=%d, k=%d", i, j, k, a.i, a.j, a.k))
}
return a.data[i+a.jStride*j+a.kStride*k]
}
func (a threeArray) atCmplx(i, j, k int) complex128 {
if i < 0 || a.i <= i || j < 0 || a.j <= j || k < 0 || a.k <= k {
panic(fmt.Sprintf("out of bounds at(%d, %d, %d): bounds i=%d, j=%d, k=%d", i, j, k, a.i, a.j, a.k))
}
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) {
if i < 0 || a.i <= i || j < 0 || a.j <= j || k < 0 || a.k <= k {
panic(fmt.Sprintf("out of bounds set(%d, %d, %d): bounds i=%d, j=%d, k=%d", i, j, k, a.i, a.j, a.k))
}
a.data[i+a.jStride*j+a.kStride*k] = v
}
func (a threeArray) setCmplx(i, j, k int, v complex128) {
if i < 0 || a.i <= i || j < 0 || a.j <= j || k < 0 || a.k <= k {
panic(fmt.Sprintf("out of bounds set(%d, %d, %d): bounds i=%d, j=%d, k=%d", i, j, k, a.i, a.j, a.k))
}
a.data[i+a.jStride*j+a.kStride*k] = real(v)
a.data[i+a.jStride*j+a.kStride*k+1] = imag(v)
}
|