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

Move type-pirating methods to FillArrays? #1426

Open
jishnub opened this issue May 26, 2023 · 10 comments
Open

Move type-pirating methods to FillArrays? #1426

jishnub opened this issue May 26, 2023 · 10 comments

Comments

@jishnub
Copy link

jishnub commented May 26, 2023

E.g.

FFTW.fft(x::Fill, dims...) = FFTW.fft(collect(x), dims...)

This looks like it should belong to an extension in FillArrays.jl

@devmotion
Copy link
Collaborator

devmotion commented May 26, 2023

Seems one could exploit though that

$$ \begin{split} DFT(A)[k] &= \sum^{length(A)}_{n=1} \exp{\bigg(\frac{- 2\pi i (k - 1) (n - 1)}{length(A)}\bigg)} A[n] \\ &= \begin{dcases} N A[1] & \text{if } k = 1,\\ \frac{1 - \exp{(-2 \pi i (k- 1))}}{1 - \exp{\Big(\frac{-2 \pi i (k - 1)}{length(A)}\Big)}} A[1] & \text{if } k > 1, \end{dcases} \\ &= \begin{dcases} N A[1] & \text{if } k = 1,\\ 0 & \text{if } k > 1, \end{dcases} \end{split} $$

if all entries of $A$ are equal.

Edit: Simplified even more (see below).

@jishnub
Copy link
Author

jishnub commented May 26, 2023

Yes, indeed, but won't the second case be zero for integer 1 < k <= length(A)? A constant array should only have the 0-frequency component populated.

@devmotion
Copy link
Collaborator

Yep, I just noticed that I could have simplified it even more 😅

@ToucheSir
Copy link
Member

You somehow discovered a very old version of that file. The current Zygote codebase doesn't use FFTW at all: https://github.com/FluxML/Zygote.jl/blob/master/src/lib/array.jl

@devmotion
Copy link
Collaborator

It's still there, just using AbstractFFT instead of FFTW (which I assume one would also want to use in an extension rather than FFTW):

Zygote.jl/src/lib/array.jl

Lines 672 to 677 in e2d7839

AbstractFFTs.fft(x::Fill, dims...) = AbstractFFTs.fft(collect(x), dims...)
AbstractFFTs.bfft(x::Fill, dims...) = AbstractFFTs.bfft(collect(x), dims...)
AbstractFFTs.ifft(x::Fill, dims...) = AbstractFFTs.ifft(collect(x), dims...)
AbstractFFTs.rfft(x::Fill, dims...) = AbstractFFTs.rfft(collect(x), dims...)
AbstractFFTs.irfft(x::Fill, d, dims...) = AbstractFFTs.irfft(collect(x), d, dims...)
AbstractFFTs.brfft(x::Fill, d, dims...) = AbstractFFTs.brfft(collect(x), d, dims...)

@devmotion devmotion reopened this May 26, 2023
@ToucheSir
Copy link
Member

ToucheSir commented May 26, 2023

Right, but for that we already have #835 no? AbstractFFTs shouldn't really be a dep of Zygote in the first place.

@devmotion
Copy link
Collaborator

IMO it's related to #835 but not a duplicate (I guess one could view it differently though): #835 is about reverse mode rules whereas this issue is just about blatant type piracy without involving any rules. It just happens that the same package (AbstractFFTs) is involved in both.

@ToucheSir
Copy link
Member

Yes, my point is that removing the rules for AbstractFFTs from Zygote should also involve removing any piracy (because there should be no code referring to AbstractFFTs left in Zygote afterwards).

@dlfivefifty
Copy link
Contributor

Yes make it an extension . But shouldn’t it return a OneHotVector ?

@devmotion
Copy link
Collaborator

That was our point above 🙂

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

4 participants