JuliaDSP / FourierTransforms.jl

Fourier transforms written in Julia
MIT License
20 stars 2 forks source link

type-flexible fft? #8

Open milankl opened 5 years ago

milankl commented 5 years ago

Thanks for the effort towards a pure-Julia fft package. I'm very interested in type-flexible fft, which I thought would be supported with such an fft implementation. However, Float16 is promoted to Float32

julia> x = rand(Float16,4);
julia> FourierTransforms.fft(x)
4-element Array{Complex{Float32},1}:
  2.2734375f0 + 0.0f0im       
 -0.6142578f0 + 0.38378906f0im
 -0.5371094f0 + 0.0f0im       
 -0.6142578f0 - 0.38378906f0im

and arbitrary number formats are not supported

julia> using SoftPosit
julia> x = Posit16.(rand(4))
4-element Array{Posit16,1}:
     Posit16(0x3e4e)
     Posit16(0x0eb6)
     Posit16(0x10d8)    
     Posit16(0x308f)    
julia> FourierTransforms.fft(x)
ERROR: type Posit16 not supported
Stacktrace: ...

Can I contribute somehow to make this package fully type-flexible?

milankl commented 5 years ago

Hmmm maybe I shouldn't have commented out the stacktrace

 [2] _fftfloat(::Type{Posit16}) at /home/username/.julia/packages/AbstractFFTs/PUqOK/src/definitions.jl:22

so it's about these two lines (20 & 22), which explain the above.

_fftfloat(::Type{Float16}) = Float32
_fftfloat(::Type{T}) where {T} = error("type $T not supported")

could we now change them thanks to FourierTransforms.jl?