fourier: add direct update optimisation
MODIFY
fourier/array_bounds_checks.go
fourier/array_bounds_checks.go
@@ -46,6 +46,13 @@ func (a twoArray) set(i, j int, v float64) {
a.data[i+a.jStride*j] = 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

MODIFY
fourier/array_no_bounds_checks.go
fourier/array_no_bounds_checks.go
@@ -35,6 +35,10 @@ func (a twoArray) set(i, j int, v float64) {
a.data[i+a.jStride*j] = 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

MODIFY
fourier/cfft.go
fourier/cfft.go
@@ -498,15 +498,15 @@ func passf(ido, ip, l1, idl1 int, cc, c1, c2, ch, ch2, wa []float64) (nac bool)
war := wa[idlj-1]
wai := wa[idlj]
for ik := 0; ik < idl1; ik++ {
- c2m.set(ik, l, c2m.at(ik, l)+war*ch2m.at(ik, j))
- c2m.set(ik, lc, c2m.at(ik, lc)-wai*ch2m.at(ik, jc))
+ c2m.add(ik, l, war*ch2m.at(ik, j))
+ c2m.add(ik, lc, -wai*ch2m.at(ik, jc))
}
}
}
for j := 1; j < ipph; j++ {
for ik := 0; ik < idl1; ik++ {
- ch2m.set(ik, 0, ch2m.at(ik, 0)+ch2m.at(ik, j))
+ ch2m.add(ik, 0, ch2m.at(ik, j))
}
}
@@ -961,15 +961,15 @@ func passb(ido, ip, l1, idl1 int, cc, c1, c2, ch, ch2, wa []float64) (nac bool)
war := wa[idlj-1]
wai := wa[idlj]
for ik := 0; ik < idl1; ik++ {
- c2m.set(ik, l, c2m.at(ik, l)+war*ch2m.at(ik, j))
- c2m.set(ik, lc, c2m.at(ik, lc)+wai*ch2m.at(ik, jc))
+ c2m.add(ik, l, war*ch2m.at(ik, j))
+ c2m.add(ik, lc, wai*ch2m.at(ik, jc))
}
}
}
for j := 1; j < ipph; j++ {
for ik := 0; ik < idl1; ik++ {
- ch2m.set(ik, 0, ch2m.at(ik, 0)+ch2m.at(ik, j))
+ ch2m.add(ik, 0, ch2m.at(ik, j))
}
}

MODIFY
fourier/rfft.go
fourier/rfft.go
@@ -542,14 +542,14 @@ func radfg(ido, ip, l1, idl1 int, cc, c1, c2, ch, ch2, wa []float64) {
ai2 = dc2*ai2 + ds2*ar2
ar2 = ar2h
for ik := 0; ik < idl1; ik++ {
- ch2m.set(ik, l, ch2m.at(ik, l)+ar2*c2m.at(ik, j))
- ch2m.set(ik, lc, ch2m.at(ik, lc)+ai2*c2m.at(ik, jc))
+ ch2m.add(ik, l, ar2*c2m.at(ik, j))
+ ch2m.add(ik, lc, ai2*c2m.at(ik, jc))
}
}
}
for j := 1; j < ipph; j++ {
for ik := 0; ik < idl1; ik++ {
- ch2m.set(ik, 0, ch2m.at(ik, 0)+c2m.at(ik, j))
+ ch2m.add(ik, 0, c2m.at(ik, j))
}
}
@@ -1039,15 +1039,15 @@ func radbg(ido, ip, l1, idl1 int, cc, c1, c2, ch, ch2, wa []float64) {
ai2 = dc2*ai2 + ds2*ar2
ar2 = ar2h
for ik := 0; ik < idl1; ik++ {
- c2m.set(ik, l, c2m.at(ik, l)+ar2*ch2m.at(ik, j))
- c2m.set(ik, lc, c2m.at(ik, lc)+ai2*ch2m.at(ik, jc))
+ c2m.add(ik, l, ar2*ch2m.at(ik, j))
+ c2m.add(ik, lc, ai2*ch2m.at(ik, jc))
}
}
}
for j := 1; j < ipph; j++ {
for ik := 0; ik < idl1; ik++ {
- ch2m.set(ik, 0, ch2m.at(ik, 0)+ch2m.at(ik, j))
+ ch2m.add(ik, 0, ch2m.at(ik, j))
}
}
for j := 1; j < ipph; j++ {

fourier: add direct update optimisation