Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Unitful data? #225

Open
JeffFessler opened this issue Dec 27, 2021 · 3 comments
Open

Support Unitful data? #225

JeffFessler opened this issue Dec 27, 2021 · 3 comments

Comments

@JeffFessler
Copy link

JeffFessler commented Dec 27, 2021

Currently fft fails for Unitful data. It is pretty easy to write a work-around that does not even add any dependency on the Unitful package, by using oneunit in Base:

using Unitful: mm
using FFTW: fft
import FFTW: fft

x = ones(8)*mm
#fft(x) # fails ERROR: LoadError: MethodError: no method matching plan_fft...

function fft(x::AbstractArray{<:Number})
    u = oneunit(eltype(x))
    return fft(x / u) * u
end

fft(x) # works as desired

Edit: perhaps the support should be added at the plan_fft level or such.
Would there be openness for a PR to add such support to FFTW?

@stevengj
Copy link
Member

That method allocates two extra arrays, which isn't ideal. It also creates an infinite dispatch loop for any Number type that isn't supported…

@mcabbott
Copy link

It should be fairly easy to do this by reinterpreting arrays, at least for simple dense arrays of constant units. Something like PainterQubits/Unitful.jl#437 except easier since fft only acts one one array. Unitful would probably need to depend on AbstractFFTs.

@JeffFessler
Copy link
Author

Thanks for the reinterpret tip! In the likely event that no else takes this up sooner, I'll take stab it this summer after classes end...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants