FFTW.jl icon indicating copy to clipboard operation
FFTW.jl copied to clipboard

View bug for idct for large enough matrix on any entry past the first

Open dsweber2 opened this issue 2 years ago • 0 comments

[idct(x) for x in eachslice(randn(641, 500),dims=2)]
idct(view(randn(641, 500), :, 500))

both result in a FFTW plan applied to wrong memory alignment.

Some comparisons where I would've expected the same bug to trigger, but they don't:

    [idct(x) for x in eachslice(randn(100,3),dims=2)]
    [rfft(x) for x in eachslice(randn(641, 500),dims=2)]
    [fft(x) for x in eachslice(randn(641, 500),dims=2)]
    idct(view(randn(641, 500), :, 1))

That last one was pretty striking to me. Running the following

    for ii=1:500
        println(ii)
        idct(view(popul, :, ii))
    end

Gave the error at ii=2.

Full error for the first example, [idct(x) for x in eachslice(randn(641, 500),dims=2)]:

ERROR: ArgumentError: FFTW plan applied to array with wrong memory alignment
Stacktrace:
  [1] assert_applicable(p::FFTW.r2rFFTWPlan{Float64, (4,), false, 1, UnitRange{Int64}}, X::Vector{Float64})
    @ FFTW ~/.julia/packages/FFTW/pHa9y/src/fft.jl:430
  [2] assert_applicable(p::FFTW.r2rFFTWPlan{Float64, (4,), false, 1, UnitRange{Int64}}, X::Vector{Float64}, Y::Vector{Float64})
    @ FFTW ~/.julia/packages/FFTW/pHa9y/src/fft.jl:435
  [3] mul!(y::Vector{Float64}, p::FFTW.DCTPlan{Float64, 4, false}, x::Vector{Float64})
    @ FFTW ~/.julia/packages/FFTW/pHa9y/src/dct.jl:153
  [4] *(p::FFTW.DCTPlan{Float64, 4, false}, x::SubArray{Float64, 1, Matrix{Float64}, Tuple{Base.Slice{Base.OneTo{Int64}}, Int64}, true})
    @ FFTW ~/.julia/packages/FFTW/pHa9y/src/dct.jl:169
  [5] idct
    @ ~/.julia/packages/FFTW/pHa9y/src/dct.jl:124 [inlined]
  [6] iterate(g::Base.Generator{Base.Generator{Base.OneTo{Int64}, Base.var"#198#201"{Matrix{Float64}, Tuple{}, Tuple{Colon}}}, typeof(idct)}, s::Int64)
    @ Base ./generator.jl:47
  [7] collect_to!(dest::Vector{Vector{Float64}}, itr::Base.Generator{Base.Generator{Base.OneTo{Int64}, Base.var"#198#201"{Matrix{Float64}, Tuple{}, Tuple{Colon}}}, typeof(idct)}, offs::Int64, st::Int64)
    @ Base ./array.jl:724
  [8] collect_to_with_first!(dest::Vector{Vector{Float64}}, v1::Vector{Float64}, itr::Base.Generator{Base.Generator{Base.OneTo{Int64}, Base.var"#198#201"{Matrix{Float64}, Tuple{}, Tuple{Colon}}}, typeof(idct)}, st::Int64)
    @ Base ./array.jl:702
  [9] collect(itr::Base.Generator{Base.Generator{Base.OneTo{Int64}, Base.var"#198#201"{Matrix{Float64}, Tuple{}, Tuple{Colon}}}, typeof(idct)})
    @ Base ./array.jl:683
 [10] top-level scope
    @ REPL[2]:1

dsweber2 avatar Oct 29 '21 20:10 dsweber2