# Allowed types for \`fft()\` and \`ifft()\` when using sparse arrays

**URL:** <https://discourse.julialang.org/t/allowed-types-for-fft-and-ifft-when-using-sparse-arrays/64481>\
**Category:** Numerics\
**Tags:** fftw, sparse\
**Created:** [July 12, 2021, 1:56am UTC](https://discourse.julialang.org/t/allowed-types-for-fft-and-ifft-when-using-sparse-arrays/64481 "2021-07-12T01:56:03Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![maxkapur](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maxkapur/32/21208_2.png) [@maxkapur](https://discourse.julialang.org/u/maxkapur)\
**Post date:** [July 12, 2021, 1:56am UTC](https://discourse.julialang.org/t/allowed-types-for-fft-and-ifft-when-using-sparse-arrays/64481/1 "2021-07-12T01:56:03Z")

</div>

In the following code, I have commented out all the lines that produce a `MethodError`:

```julia
using FFTW, SparseArrays

fft(rand(Float64, 50, 50))
fft(rand(ComplexF64, 50, 50))
fft(rand(Float32, 50, 50))
fft(rand(ComplexF32, 50, 50))
fft(rand(Float16, 50, 50))
# fft(rand(ComplexF16, 50, 50))

fft(sprand(Float64, 50, 50, 0.2))
# fft(sprand(ComplexF64, 50, 50, 0.2))
fft(sprand(Float32, 50, 50, 0.2))
# fft(sprand(ComplexF32, 50, 50, 0.2))
fft(sprand(Float16, 50, 50, 0.2))
# fft(sprand(ComplexF16, 50, 50, 0.2))

ifft(rand(Float64, 50, 50))
ifft(rand(ComplexF64, 50, 50))
ifft(rand(Float32, 50, 50))
ifft(rand(ComplexF32, 50, 50))
ifft(rand(Float16, 50, 50))
# ifft(rand(ComplexF16, 50, 50))
    
ifft(sprand(Float64, 50, 50, 0.2))
# ifft(sprand(ComplexF64, 50, 50, 0.2))
ifft(sprand(Float32, 50, 50, 0.2))
# ifft(sprand(ComplexF32, 50, 50, 0.2))
ifft(sprand(Float16, 50, 50, 0.2))
# ifft(sprand(ComplexF16, 50, 50, 0.2))

```

It seems odd to me that `fft()` and `ifft()` would be defined for `Float16` but not `ComplexF16`, and also that there is no support for sparse arrays of any kind of complex float. Is this an issue with FFTW.jl or the underlying FFTW library itself?

The lack of support for sparse complex arrays makes it difficult to do (for example) FFT image compression in a meaningful way, because the output of `res = fft(sprand(Float32, 50, 50, 0.5))` is a `Matrix{ComplexF32}`. Discarding low coefficients only saves memory if we then convert `res` to a sprase format that can be `ifft`ed directly.
