JuliaMath / JuliaMath/FFTW.jl

views and padding with complex floats

Open
#115 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Julia
Stars
300
Forks
61
PR merge metrics
No merged PRs in 30d

Description

I want to zero pad before transforming. If my data is real then:

```julia
julia> using FFTW, LazyArrays, FillArrays

julia> x=randn(4,5)
4×5 Array{Float64,2}:
-0.378035 0.670349 1.12253 -1.36774 -0.173416
1.75424 0.318407 -0.292364 1.45804 0.80958
0.380079 1.54177 0.150129 -0.830847 -1.8718
-0.710417 -0.57236 -0.0898031 -2.03682 0.531457

julia> y = Hcat(x,Zeros{Float64}(4,4))
4×9 ApplyArray{Float64,2,typeof(hcat),Tuple{Array{Float64,2},Zeros{Float64,2,Tuple{Base.OneTo{Int64},Base.OneTo{Int64}}}}}:
-0.378035 0.670349 1.12253 -1.36774 -0.173416 0.0 0.0 0.0 0.0
1.75424 0.318407 -0.292364 1.45804 0.80958 0.0 0.0 0.0 0.0
0.380079 1.54177 0.150129 -0.830847 -1.8718 0.0 0.0 0.0 0.0
-0.710417 -0.57236 -0.0898031 -2.03682 0.531457 0.0 0.0 0.0 0.0

julia> fft(y)
4×9 Array{Complex{Float64},2}:
0.412982+0.0im 4.75093+0.51046im … 4.75093-0.51046im
0.504358-6.92585im -6.07917-1.61647im 0.910541-0.589654im
-1.92693+0.0im 5.12664-0.653888im 5.12664+0.653888im
0.504358+6.92585im 0.910541+0.589654im -6.07917+1.61647im
```
works fine.

However, if the data is complex:
```julia
julia> x=randn(4,5) |> complex
4×5 Array{Complex{Float64},2}:
1.19937+0.0im -0.186707+0.0im 0.540344+0.0im -0.452131+0.0im -0.887593+0.0im
-0.021565+0.0im 1.82495+0.0im -0.437441+0.0im -1.60317+0.0im -2.13965+0.0im
-0.6327+0.0im 2.22139+0.0im 1.02815+0.0im -2.15875+0.0im -1.8183+0.0im
1.62291+0.0im -0.633302+0.0im -2.99322+0.0im -0.580422+0.0im -0.514297+0.0im

julia> y = Hcat(x,Zeros{Complex{Float64}}(4,4))
4×9 ApplyArray{Complex{Float64},2,typeof(hcat),Tuple{Array{Complex{Float64},2},Zeros{Complex{Float64},2,Tuple{Base.OneTo{Int64},Base.OneTo{Int64}}}}}:
1.19937+0.0im -0.186707+0.0im 0.540344+0.0im … 0.0+0.0im 0.0+0.0im 0.0+0.0im 0.0+0.0im
-0.021565+0.0im 1.82495+0.0im -0.437441+0.0im 0.0+0.0im 0.0+0.0im 0.0+0.0im 0.0+0.0im
-0.6327+0.0im 2.22139+0.0im 1.02815+0.0im 0.0+0.0im 0.0+0.0im 0.0+0.0im 0.0+0.0im
1.62291+0.0im -0.633302+0.0im -2.99322+0.0im 0.0+0.0im 0.0+0.0im 0.0+0.0im 0.0+0.0im

julia> fft(y)
ERROR: MethodError: no method matching plan_fft(::ApplyArray{Complex{Float64},2,typeof(hcat),Tuple{Array{Complex{Float64},2},Zeros{Complex{Float64},2,Tuple{Base.OneTo{Int64},Base.OneTo{Int64}}}}}, ::UnitRange{Int64})
Closest candidates are:
plan_fft(::Union{DenseArray{T<:Union{Complex{Float32}, Complex{Float64}},N}, Base.ReinterpretArray{T<:Union{Complex{Float32}, Complex{Float64}},N,S,A} where S where A<:Union{SubArray{T,N,A,I,true} where I<:Union{Tuple{Vararg{Real,N} where N}, Tuple{AbstractUnitRange,Vararg{Any,N} where N}} where A<:DenseArray where N where T, DenseArray}, Base.ReshapedArray{T<:Union{Complex{Float32}, Complex{Float64}},N,A,MI} where MI<:Tuple{Vararg{Base.MultiplicativeInverses.SignedMultiplicativeInverse{Int64},N} where N} where A<:Union{Base.ReinterpretArray{T,N,S,A} where S where A<:Union{SubArray{T,N,A,I,true} where I<:Union{Tuple{Vararg{Real,N} where N}, Tuple{AbstractUnitRange,Vararg{Any,N} where N}} where A<:DenseArray where N where T, DenseArray} where N where T, SubArray{T,N,A,I,true} where I<:Union{Tuple{Vararg{Real,N} where N}, Tuple{AbstractUnitRange,Vararg{Any,N} where N}} where A<:DenseArray where N where T, DenseArray}, SubArray{T<:Union{Complex{Float32}, Complex{Float64}},N,A,I,L} where L where I<:Tuple{Vararg{Union{Int64, AbstractRange{Int64}, Base.AbstractCartesianIndex},N} where N} where A<:Union{Base.ReinterpretArray{T,N,S,A} where S where A<:Union{SubArray{T,N,A,I,true} where I<:Union{Tuple{Vararg{Real,N} where N}, Tuple{AbstractUnitRange,Vararg{Any,N} where N}} where A<:DenseArray where N where T, DenseArray} where N where T, Base.ReshapedArray{T,N,A,MI} where MI<:Tuple{Vararg{Base.MultiplicativeInverses.SignedMultiplicativeInverse{Int64},N} where N} where A<:Union{Base.ReinterpretArray{T,N,S,A} where S where A<:Union{SubArray{T,N,A,I,true} where I<:Union{Tuple{Vararg{Real,N} where N}, Tuple{AbstractUnitRange,Vararg{Any,N} where N}} where A<:DenseArray where N where T, DenseArray} where N where T, SubArray{T,N,A,I,true} where I<:Union{Tuple{Vararg{Real,N} where N}, Tuple{AbstractUnitRange,Vararg{Any,N} where N}} where A<:DenseArray where N where T, DenseArray} where N where T, DenseArray}}, ::Any; flags, timelimit) where {T<:Union{Complex{Float32}, Complex{Float64}}, N} at /Users/abradley/.julia/packages/FFTW/MJ7kl/src/fft.jl:619
plan_fft(::AbstractArray{#s16,N} where N where #s16<:Real, ::Any; kws...) at /Users/abradley/.julia/packages/AbstractFFTs/PUqOK/src/definitions.jl:199
plan_fft(::AbstractArray{#s25,N} where N where #s25<:(Complex{#s26} where #s26<:Union{Integer, Rational}), ::Any; kws...) at /Users/abradley/.julia/packages/AbstractFFTs/PUqOK/src/definitions.jl:201
...
Stacktrace:
[1] #plan_fft#1(::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::typeof(plan_fft), ::ApplyArray{Complex{Float64},2,typeof(hcat),Tuple{Array{Complex{Float64},2},Zeros{Complex{Float64},2,Tuple{Base.OneTo{Int64},Base.OneTo{Int64}}}}}) at /Users/abradley/.julia/packages/AbstractFFTs/PUqOK/src/definitions.jl:52
[2] plan_fft(::ApplyArray{Complex{Float64},2,typeof(hcat),Tuple{Array{Complex{Float64},2},Zeros{Complex{Float64},2,Tuple{Base.OneTo{Int64},Base.OneTo{Int64}}}}}) at /Users/abradley/.julia/packages/AbstractFFTs/PUqOK/src/definitions.jl:52
[3] fft(::ApplyArray{Complex{Float64},2,typeof(hcat),Tuple{Array{Complex{Float64},2},Zeros{Complex{Float64},2,Tuple{Base.OneTo{Int64},Base.OneTo{Int64}}}}}) at /Users/abradley/.julia/packages/AbstractFFTs/PUqOK/src/definitions.jl:50
[4] top-level scope at REPL[7]:1
```

changing to `y = Hcat(view(x,:,:),Zeros{Complex{Float64}}(4,4))` doesn't help here either.

Is there any obvious method to add for complex, or a fundamental problem?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.