-
Notifications
You must be signed in to change notification settings - Fork 9
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
Adding dims to DFT/IDFT operator #13
Conversation
Oh, I see the problem. Will fix and update... |
Hi @1oly , probably you already know but you can test your changes locally by typing: ] test AbstractOperators Additionally what I typically do is to comment out most of the tests in |
Thanks, all tips are welcome :) Currently only two of the tests I added are failing and I'm not quite sure why. It is for IDFT when
So going into
I think it might be due to a simple error in domain transformation but cannot find the error. Any ideas? |
OK, its the scaling factor in |
Well the scaling changes depending on the dimension you're applying the dft/idft to. I guess you could add a scaling parameter to the IDFT object and then modify these lines accordingly. Of course you should also add some tests of DFT and IDFT with different dimensions settings possibly below the ones that are already there. |
Starting to look better now. Tests are now passing. Some words on my approach: I've looked closely at RDFT/IRDFT and AbstractFFTs.jl. I adopted the
and added
It might be overkill to add ´E´ to both DFT and IDFT when DFT is not using it, but since they are both subtypes of To account for the normalization in IDFT, I added the line: Let me know what you think, I'll be happy to update again. |
Codecov Report
@@ Coverage Diff @@
## master #13 +/- ##
==========================================
+ Coverage 83.81% 83.92% +0.11%
==========================================
Files 49 49
Lines 1643 1655 +12
==========================================
+ Hits 1377 1389 +12
Misses 266 266
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #13 +/- ##
=======================================
Coverage 83.81% 83.81%
=======================================
Files 49 49
Lines 1643 1643
=======================================
Hits 1377 1377
Misses 266 266
Continue to review full report at Codecov.
|
maybe you could put |
test/test_linear_operators.jl
Outdated
|
||
@test all(norm.(y1 .- y2) .<= 1e-12) | ||
|
||
op = AbstractOperators.IDFT(Float64,(n,n)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perhaps here something like (n,m)
where m != n
would make the test more robust.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, will add some more robust tests.
src/linearoperators/DFT.jl
Outdated
T1<:AbstractFFTs.Plan, | ||
T2<:AbstractFFTs.Plan} <: FourierTransform{N,C,D,T1,T2} | ||
T2<:AbstractFFTs.Plan} <: FourierTransform{N,C,D,E,T1,T2} | ||
dim_in::NTuple{N,Int} | ||
A::T1 | ||
At::T2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to clarify what I said in the other comment. I think something like this could be more approriate:
struct DFT{N,
C<:RealOrComplex,
D<:RealOrComplex,
E<:Int,
T1<:AbstractFFTs.Plan,
T2<:AbstractFFTs.Plan} <: FourierTransform{N,C,D,T1,T2}
T2<:AbstractFFTs.Plan} <: FourierTransform{N,C,D,E,T1,T2}
dim_in::NTuple{N,E}
A::T1
At::T2
dims::E
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, much better!
T1<:AbstractFFTs.Plan, | ||
T2<:AbstractFFTs.Plan} <: FourierTransform{N,C,D,T1,T2} | ||
T2<:AbstractFFTs.Plan} <: FourierTransform{N,C,D,E,T1,T2} | ||
dim_in::NTuple{N,Int} | ||
A::T1 | ||
At::T2 | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Of course have the same structure here
src/linearoperators/DFT.jl
Outdated
A = plan_fft(x,dims) | ||
At = plan_bfft(y2,dims) | ||
dim_in = size(x) | ||
DFT{N,Complex{D},D,dims,typeof(A),typeof(At)}(dim_in,A,At) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and hence
d = prod(size(x,e) for e in dims)
DFT{N,Complex{D},D,typeof(d),dims,typeof(A),typeof(At)}(dim_in,A,At,d)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also are you sure of d = prod(size(x,e) for e in dims)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense to do the normalization here. But just to make sure, the same normalization also applies to mul!
:
https://github.com/kul-forbes/AbstractOperators.jl/blob/e16bbe48e82c334e9435b6692e621f72a73373cd/src/linearoperators/DFT.jl#L155-L160
Are we certain that x
from the constructor and b
from mul!
are the same dimensions? I guess the input b::AbstractArray{C,N}
suggests so...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quite certain about d = prod(size(x,e) for e in dims)
but will try to add a more convincing comment later :)
I may have overly complicated things 😂 It turns out that
Should I just try to clean up and commit that then (with the new tests and doc string of coarse)? |
Ah that's great!
I guess the fastest thing to do here is to checkout to master the single file? git checkout origin/master src/linearoperators/DFT.jl |
OK, should be final now. A little detour but got to study the code in detail which is always nice. Thanks for reviewing! |
This is adding an optional argument
dims
toDFT
/IDFT
. Discussed in #12Follows the definition from AbstractFFTs: https://github.com/JuliaMath/AbstractFFTs.jl/blob/2f11b0e86c7b1c1660f7513849986e85f58a28b7/src/definitions.jl#L198
by adding
dims=1:ndims(x)
ordims=1:N
to functions and constructors:DFT(x::AbstractArray{D,N},dims=1:ndims(x)) where {N,D<:Real}
orDFT(dim_in::NTuple{N,Int},dims=1:N) where {N} = DFT(zeros(dim_in),dims)
I hope I caught all cases and methods but please review and let me know if I'm missing anything.