From 76607775dbd967e8b144340036b4c387121b49cc Mon Sep 17 00:00:00 2001 From: Martin Holters Date: Thu, 19 Apr 2018 10:01:49 +0200 Subject: [PATCH] Fix check of `UNALIGNED` flag in `assert_applicable` --- src/fft.jl | 4 ++-- test/runtests.jl | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/fft.jl b/src/fft.jl index 676a7a2..2193566 100644 --- a/src/fft.jl +++ b/src/fft.jl @@ -353,7 +353,7 @@ function assert_applicable(p::FFTWPlan{T}, X::StridedArray{T}) where T throw(ArgumentError("FFTW plan applied to wrong-size array")) elseif strides(X) != p.istride throw(ArgumentError("FFTW plan applied to wrong-strides array")) - elseif alignment_of(X) != p.ialign || p.flags & UNALIGNED != 0 + elseif alignment_of(X) != p.ialign && p.flags & UNALIGNED == 0 throw(ArgumentError("FFTW plan applied to array with wrong memory alignment")) end end @@ -364,7 +364,7 @@ function assert_applicable(p::FFTWPlan{T,K,inplace}, X::StridedArray{T}, Y::Stri throw(ArgumentError("FFTW plan applied to wrong-size output")) elseif strides(Y) != p.ostride throw(ArgumentError("FFTW plan applied to wrong-strides output")) - elseif alignment_of(Y) != p.oalign || p.flags & UNALIGNED != 0 + elseif alignment_of(Y) != p.oalign && p.flags & UNALIGNED == 0 throw(ArgumentError("FFTW plan applied to output with wrong memory alignment")) elseif inplace != (pointer(X) == pointer(Y)) throw(ArgumentError(string("FFTW ", diff --git a/test/runtests.jl b/test/runtests.jl index 40fa645..e2b9421 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -485,3 +485,30 @@ if fftw_vendor() != :mkl @test psXdct![i] ≈ true_Xdct[i] end end # fftw_vendor() != :mkl + +# test UNALIGNED flag +let A = rand(Float32, 35), Ac = rand(Complex{Float32}, 35) + Y = Array{Complex{Float32}}(undef, 20) + Yc = Array{Complex{Float32}}(undef, 35) + planr = plan_rfft(Array{Float32}(undef, 32), flags=FFTW.UNALIGNED) + planc = plan_fft(Array{Complex{Float32}}(undef, 32), flags=FFTW.UNALIGNED) + for ioff in 0:3 + ii = 1+ioff:32+ioff + @test planr * view(A, ii) ≈ planr * A[ii] ≈ rfft(view(A, ii)) ≈ rfft(A[ii]) + @test planc * view(Ac, ii) ≈ planc * Ac[ii] ≈ fft(view(Ac, ii)) ≈ fft(Ac[ii]) + for ooff in 0:3 + io = 1+ooff:17+ooff + FFTW.mul!(view(Y, io), planr, view(A, ii)) + @test Y[io] ≈ rfft(A[ii]) + FFTW.mul!(view(Y, io), planr, A[ii]) + @test Y[io] ≈ rfft(A[ii]) + io = 1+ooff:32+ooff + FFTW.mul!(view(Yc, io), planc, view(Ac, ii)) + @test Yc[io] ≈ fft(Ac[ii]) + FFTW.mul!(view(Yc, io), planc, Ac[ii]) + @test Yc[io] ≈ fft(Ac[ii]) + end + end + @test_throws ArgumentError plan_rfft(Array{Float32}(undef, 32)) * view(A, 2:33) + @test_throws ArgumentError plan_fft(Array{Complex{Float32}}(undef, 32)) * view(Ac, 2:33) +end