Skip to content

Commit

Permalink
Fix check of UNALIGNED flag in assert_applicable
Browse files Browse the repository at this point in the history
  • Loading branch information
martinholters committed Apr 19, 2018
1 parent 4bb7d0d commit 7660777
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/fft.jl
Expand Up @@ -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
Expand All @@ -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 ",
Expand Down
27 changes: 27 additions & 0 deletions test/runtests.jl
Expand Up @@ -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

0 comments on commit 7660777

Please sign in to comment.