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

**URL:** <https://discourse.julialang.org/t/fft-v-fails-for-subtypes-of-abstractarray-complex/19404>\
**Category:** General Usage\
**Tags:** fftw\
**Created:** [January 8, 2019, 11:46pm UTC](https://discourse.julialang.org/t/fft-v-fails-for-subtypes-of-abstractarray-complex/19404 "2019-01-08T23:46:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![raminammour](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raminammour/32/13572_2.png) [@raminammour](https://discourse.julialang.org/u/raminammour)\
**Post date:** [January 8, 2019, 11:46pm UTC](https://discourse.julialang.org/t/fft-v-fails-for-subtypes-of-abstractarray-complex/19404/1 "2019-01-08T23:46:49Z")

</div>

Hello,

I think this is a bug:

```julia
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!

---

<div class="post-metadata">

**Author:** ![favba](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/favba/32/2735_2.png) [@favba](https://discourse.julialang.org/u/favba)\
**Post date:** [January 9, 2019, 1:31am UTC](https://discourse.julialang.org/t/fft-v-fails-for-subtypes-of-abstractarray-complex/19404/2 "2019-01-09T01:31:12Z")

</div>

`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)`

---

<div class="post-metadata">

**Author:** ![raminammour](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raminammour/32/13572_2.png) [@raminammour](https://discourse.julialang.org/u/raminammour)\
**Post date:** [January 9, 2019, 5:30pm UTC](https://discourse.julialang.org/t/fft-v-fails-for-subtypes-of-abstractarray-complex/19404/3 "2019-01-09T17:30:36Z")

</div>

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).
