`fft(v)` fails for subtypes of `AbstractArray{<:Complex}`

Hello,

I think this is a bug:

struct wrap{T,N} <: AbstractArray{T,N}
    v::Array{T,N}
end
Base.size(w::wrap)=size(w.v)
Base.getindex(w::wrap,i)=getindex(w.v,i)
Base.setindex!(w::wrap,i,v)=setindex!(w.v,i,v)

wwr=wrap(rand(Float64,10))
wwc=wrap(rand(ComplexF64,10));

using FFTW
fft(wwr) #works 
fft(wwc) #error

MethodError: no method matching plan_fft(::wrap{Complex{Float64},1}, ::UnitRange{Int64})

Am I missing something or should I file an issue with AbstractFFTs (my guess) or FFTW?

Thanks!

AbstractArray is too generic for fft. You need to make your struct <:StridedArray{T,N}. In you case, since it only accepts Array{T,N} you can make the struct <:DenseArray{T,N}, which is a subtype of StridedArray.

For a DenseArray you need to write one more method for the struct:
Base.unsafe_convert(::Ptr{T}, a::wrap{T,N}) where {T,N} = Base.unsafe_convert(Prt{T}, a.v)

1 Like

Thank you for the reply, for this example, doing what you described works!

Unfortunately, my use case looks like wrap{T,N} <: Abstractwrap{T,N} <: AbstractArray{T,N}.

Is there a way to make this work cleanly, since it obviously works for the real version (or is was not not supposed to work either? It works because of a call to complexfloat that drops the wrapper type info).