Debian Codegraph @

dsp/fourier/internal/fftpack/array_bounds_checks.go

raw symbols SCIP
1 // Copyright ©2018 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 // This file must be kept in sync with array_no_bound_checks.go.
6
7 //go:build bounds
8 // +build bounds
9
10 package fftpack
11
12 import "fmt"
13
14 // The types in array.go implement Fortran-like arrays for bootstrapping
15 // the implementation of the FFT functions translated from FFTPACK; they
16 // are column-major.
17
18 type twoArray struct {
19 i, j int
20 jStride int
21 data []float64
22 }
23
24 func newTwoArray(i, j int, data []float64) twoArray {
25 if len(data) < i*j {
26 panic(fmt.Sprintf("short data: len(data)=%d, i=%d, j=%d", len(data), i, j))
27 }
28 return twoArray{
29 i: i,
30 j: j,
31 jStride: i,
32 data: data[:i*j],
33 }
34 }
35
36 func (a twoArray) at(i, j int) float64 {
37 if i < 0 || a.i <= i || j < 0 || a.j <= j {
38 panic(fmt.Sprintf("out of bounds at(%d, %d): bounds i=%d, j=%d", i, j, a.i, a.j))
39 }
40 return a.data[i+a.jStride*j]
41 }
42
43 func (a twoArray) atCmplx(i, j int) complex128 {
44 if i < 0 || a.i <= i || j < 0 || a.j <= j {
45 panic(fmt.Sprintf("out of bounds at(%d, %d): bounds i=%d, j=%d", i, j, a.i, a.j))
46 }
47 return complex(a.data[i+a.jStride*j], a.data[i+a.jStride*j+1])
48 }
49
50 func (a twoArray) set(i, j int, v float64) {
51 if i < 0 || a.i <= i || j < 0 || a.j <= j {
52 panic(fmt.Sprintf("out of bounds set(%d, %d): bounds i=%d, j=%d", i, j, a.i, a.j))
53 }
54 a.data[i+a.jStride*j] = v
55 }
56
57 func (a twoArray) setCmplx(i, j int, v complex128) {
58 if i < 0 || a.i <= i || j < 0 || a.j <= j {
59 panic(fmt.Sprintf("out of bounds set(%d, %d): bounds i=%d, j=%d", i, j, a.i, a.j))
60 }
61 a.data[i+a.jStride*j] = real(v)
62 a.data[i+a.jStride*j+1] = imag(v)
63 }
64
65 func (a twoArray) add(i, j int, v float64) {
66 if i < 0 || a.i <= i || j < 0 || a.j <= j {
67 panic(fmt.Sprintf("out of bounds set(%d, %d): bounds i=%d, j=%d", i, j, a.i, a.j))
68 }
69 a.data[i+a.jStride*j] += v
70 }
71
72 type threeArray struct {
73 i, j, k int
74 jStride, kStride int
75 data []float64
76 }
77
78 func newThreeArray(i, j, k int, data []float64) threeArray {
79 if len(data) < i*j*k {
80 panic(fmt.Sprintf("short data: len(data)=%d, i=%d, j=%d, k=%d", len(data), i, j, k))
81 }
82 return threeArray{
83 i: i,
84 j: j,
85 k: k,
86 jStride: i,
87 kStride: i * j,
88 data: data[:i*j*k],
89 }
90 }
91
92 func (a threeArray) at(i, j, k int) float64 {
93 if i < 0 || a.i <= i || j < 0 || a.j <= j || k < 0 || a.k <= k {
94 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))
95 }
96 return a.data[i+a.jStride*j+a.kStride*k]
97 }
98
99 func (a threeArray) atCmplx(i, j, k int) complex128 {
100 if i < 0 || a.i <= i || j < 0 || a.j <= j || k < 0 || a.k <= k {
101 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))
102 }
103 return complex(a.data[i+a.jStride*j+a.kStride*k], a.data[i+a.jStride*j+a.kStride*k+1])
104 }
105
106 func (a threeArray) set(i, j, k int, v float64) {
107 if i < 0 || a.i <= i || j < 0 || a.j <= j || k < 0 || a.k <= k {
108 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))
109 }
110 a.data[i+a.jStride*j+a.kStride*k] = v
111 }
112
113 func (a threeArray) setCmplx(i, j, k int, v complex128) {
114 if i < 0 || a.i <= i || j < 0 || a.j <= j || k < 0 || a.k <= k {
115 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))
116 }
117 a.data[i+a.jStride*j+a.kStride*k] = real(v)
118 a.data[i+a.jStride*j+a.kStride*k+1] = imag(v)
119 }