Skip to content

Commit

Permalink
Test inverse FFT as well.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rémy Oudompheng committed Jul 31, 2017
1 parent 9687aa1 commit 9d65dcd
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions fft_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,22 +86,27 @@ func testFourier(t *testing.T, N int, k uint) {
src[i][p] = Word(rnd.Int63())
}
}
cmpFourier(t, N, k, src)
cmpFourier(t, N, k, src, false)
cmpFourier(t, N, k, src, true)

// Saturated coefficients (b^N-1)
for i := range src {
for p := 0; p < N; p++ {
src[i][p] = ^Word(0)
}
}
cmpFourier(t, N, k, src)
cmpFourier(t, N, k, src, false)
cmpFourier(t, N, k, src, true)
}

// cmpFourier computes the Fourier transform of src
// and compares it to the FFT result.
func cmpFourier(t *testing.T, N int, k uint, src []fermat) {
t.Logf("testFourier(t, %d, %d)", N, k)
func cmpFourier(t *testing.T, N int, k uint, src []fermat, inverse bool) {
t.Logf("testFourier(t, %d, %d, inverse=%v)", N, k, inverse)
ωshift := (4 * N * _W) >> k
if inverse {
ωshift = -ωshift
}
dst1 := make([]fermat, 1<<k)
dst2 := make([]fermat, 1<<k)
for i := range src {
Expand All @@ -120,7 +125,7 @@ func cmpFourier(t *testing.T, N int, k uint, src []fermat) {
}

// fast transform
fourier(dst2, src, false, N, k)
fourier(dst2, src, inverse, N, k)

for i := range src {
if cmpnat(t, nat(dst1[i]), nat(dst2[i])) != 0 {
Expand Down

0 comments on commit 9d65dcd

Please sign in to comment.