gonum.org/v1/gonum@v0.14.0/dsp/fourier/internal/fftpack/array_no_bounds_checks.go (about) 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_bound_checks.go. 6 7 //go:build !bounds 8 // +build !bounds 9 10 package fftpack 11 12 // The types in array.go implement Fortran-like arrays for bootstrapping 13 // the implementation of the FFT functions translated from FFTPACK; they 14 // are column-major. 15 16 type twoArray struct { 17 jStride int 18 data []float64 19 } 20 21 func newTwoArray(i, j int, data []float64) twoArray { 22 if len(data) < i*j { 23 panic("fourier: short data") 24 } 25 return twoArray{ 26 jStride: i, 27 data: data[:i*j], 28 } 29 } 30 31 func (a twoArray) at(i, j int) float64 { 32 return a.data[i+a.jStride*j] 33 } 34 35 func (a twoArray) atCmplx(i, j int) complex128 { 36 return complex(a.data[i+a.jStride*j], a.data[i+a.jStride*j+1]) 37 } 38 39 func (a twoArray) set(i, j int, v float64) { 40 a.data[i+a.jStride*j] = v 41 } 42 43 func (a twoArray) setCmplx(i, j int, v complex128) { 44 a.data[i+a.jStride*j] = real(v) 45 a.data[i+a.jStride*j+1] = imag(v) 46 } 47 48 func (a twoArray) add(i, j int, v float64) { 49 a.data[i+a.jStride*j] += v 50 } 51 52 type threeArray struct { 53 jStride, kStride int 54 data []float64 55 } 56 57 func newThreeArray(i, j, k int, data []float64) threeArray { 58 if len(data) < i*j*k { 59 panic("fourier: short data") 60 } 61 return threeArray{ 62 jStride: i, 63 kStride: i * j, 64 data: data[:i*j*k], 65 } 66 } 67 68 func (a threeArray) at(i, j, k int) float64 { 69 return a.data[i+a.jStride*j+a.kStride*k] 70 } 71 72 func (a threeArray) atCmplx(i, j, k int) complex128 { 73 return complex(a.data[i+a.jStride*j+a.kStride*k], a.data[i+a.jStride*j+a.kStride*k+1]) 74 } 75 76 func (a threeArray) set(i, j, k int, v float64) { 77 a.data[i+a.jStride*j+a.kStride*k] = v 78 } 79 80 func (a threeArray) setCmplx(i, j, k int, v complex128) { 81 a.data[i+a.jStride*j+a.kStride*k] = real(v) 82 a.data[i+a.jStride*j+a.kStride*k+1] = imag(v) 83 }