JuliaMath / FFTW.jl

Julia bindings to the FFTW library for fast Fourier transforms
https://juliamath.github.io/FFTW.jl/stable
MIT License
273 stars 55 forks source link

FFT of transposed complex matrix #85

Open ettersi opened 5 years ago

ettersi commented 5 years ago
julia> fft(transpose(rand(ComplexF64,2,2)))
ERROR: MethodError: no method matching plan_fft(::Transpose{Complex{Float64},Array{Complex{Float64},2}}, ::UnitRange{Int64})
Closest candidates are:
  plan_fft(::Union{DenseArray{T<:Union{Complex{Float32}, Complex{Float64}},N}, ReinterpretArray{T<:Union{Complex{Float32}, Complex{Float64}},N,S,A} where S where A<:Union{SubArray{T,N,A,I,true} where I<:Tuple{AbstractUnitRange,Vararg{Any,N} where N} where A<:DenseArray where N where T, DenseArray}, ReshapedArray{T<:Union{Complex{Float32}, Complex{Float64}},N,A,MI} where MI<:Tuple{Vararg{SignedMultiplicativeInverse{Int64},N} where N} where A<:Union{ReinterpretArray{T,N,S,A} where S where A<:Union{SubArray{T,N,A,I,true} where I<: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<: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}, AbstractCartesianIndex},N} where N} where A<:Union{ReinterpretArray{T,N,S,A} where S where A<:Union{SubArray{T,N,A,I,true} where I<:Tuple{AbstractUnitRange,Vararg{Any,N} where N} where A<:DenseArray where N where T, DenseArray} where N where T, ReshapedArray{T,N,A,MI} where MI<:Tuple{Vararg{SignedMultiplicativeInverse{Int64},N} where N} where A<:Union{ReinterpretArray{T,N,S,A} where S where A<:Union{SubArray{T,N,A,I,true} where I<: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<: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 /home/ettersi/.julia/packages/FFTW/p7sLQ/src/fft.jl:619
  plan_fft(::AbstractArray{#s16,N} where N where #s16<:Real, ::Any; kws...) at /home/ettersi/.julia/packages/AbstractFFTs/7WCaR/src/definitions.jl:199
  plan_fft(::AbstractArray{#s25,N} where N where #s25<:(Complex{#s26} where #s26<:Union{Integer, Rational}), ::Any; kws...) at /home/ettersi/.julia/packages/AbstractFFTs/7WCaR/src/definitions.jl:201
  ...
Stacktrace:
 [1] #plan_fft#1(::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::Function, ::Transpose{Complex{Float64},Array{Complex{Float64},2}}) at /home/ettersi/.julia/packages/AbstractFFTs/7WCaR/src/definitions.jl:52
 [2] plan_fft(::Transpose{Complex{Float64},Array{Complex{Float64},2}}) at /home/ettersi/.julia/packages/AbstractFFTs/7WCaR/src/definitions.jl:52
 [3] fft(::Transpose{Complex{Float64},Array{Complex{Float64},2}}) at /home/ettersi/.julia/packages/AbstractFFTs/7WCaR/src/definitions.jl:50
 [4] top-level scope at none:0

Note that the real case works:

julia> fft(transpose(rand(Float64,2,2)))
2×2 Array{Complex{Float64},2}:
   1.70938+0.0im   0.333911+0.0im
 -0.734234+0.0im  -0.246447+0.0im
sf219 commented 3 years ago

Hi,

I may be a little bit late. but I faced the same issue. Sorry for the lack of correction, this is my first post here. What worked for me was a little bit rudimentary, but given a LinearAlgebra.Transpose{Complex{Float64},Array{Complex{Float64},2}} element, say d, using d[:, :] removed the Transpose wrapper. Once it is removed, the fft method worked correctly.

Probably there are better solutions out there. I am not very well familiarized with the Julia internal processing.

mihalybaci commented 3 years ago

I ran into this same issue, but doing the x[:, :] slicing worked for me too, thanks!