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
fourier: new package for fourier analysis and related functions #412
Conversation
From an API perspective, I think that given there are work arrays kept, a type holding those that can be reused would be the most sensible approach:
I'm not wildly happy about the method names |
fourier/rfft.go
Outdated
ai2 = dc2*ai2 + ds2*ar2 | ||
ar2 = ar2h | ||
for ik := 1; ik <= idl1; ik++ { | ||
ch2m.set(ik, l, ch2m.at(ik, l)+ar2*c2m.at(ik, j)) |
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.
These two lines suggest that a twoArray.add(i, j int, v float64)
method would be a worthwhile optimisation.
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.
These are done.
fourier/rfft.go
Outdated
} | ||
for j := 2; j <= ipph; j++ { | ||
for ik := 1; ik <= idl1; ik++ { | ||
ch2m.set(ik, 1, ch2m.at(ik, 1)+c2m.at(ik, j)) |
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 here.
fourier/rfft.go
Outdated
ai2 = dc2*ai2 + ds2*ar2 | ||
ar2 = ar2h | ||
for ik := 1; ik <= idl1; ik++ { | ||
c2m.set(ik, l, c2m.at(ik, l)+ar2*ch2m.at(ik, j)) |
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 here.
fourier/rfft.go
Outdated
|
||
for j := 2; j <= ipph; j++ { | ||
for ik := 1; ik <= idl1; ik++ { | ||
ch2m.set(ik, 1, ch2m.at(ik, 1)+ch2m.at(ik, j)) |
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 here.
|
dd0e55e
to
2c4ea68
Compare
I'll get to this when I can, I'm on travel at the moment. |
No worries. |
2a1a53f
to
31ce9e8
Compare
Apologies for the unhelpful ordering - I revised the author name, and github insists on presenting PR changes in chronological order in a way that made that revision show differences that were not otherwise there. |
I understand the desire for having the types to reuse the work arrays. From what I understand, this is how FFTW works as well. Do you think it's desirable to also have some high level functions for ease of use? I haven't looked at all of the intended functions, but I wonder if we could get away with Just a thought. I'll take a more detailed look soon hopefully. |
They are an easy addition, so I think we should leave that for when someone asks for it. |
I have put together the implementation and API for DCT, DST and QW-FFT (tests will come later), but I won't include them in this PR. However, after seeing how the API looks I'm going to push a little harder towards English for the method names. I have two proposals (in preference order):
This gives us nicer API for the new routines mentioned above, e.g. for QW-FFT, |
fourier/rfft.go
Outdated
rffti1(n, work[n:2*n], ifac[:15]) | ||
} | ||
|
||
func rffti1(n int, wa []float64, ifac []int) { |
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.
Checked this one and looks good.
fourier/rfft.go
Outdated
rfftf1(n, r[:n], work[:n], work[n:2*n], ifac[:15]) | ||
} | ||
|
||
func rfftf1(n int, c, ch, wa []float64, ifac []int) { |
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.
This looks good too
// freq=0.375 cycles/period, magnitude=3, phase=3.142 | ||
} | ||
|
||
func Example_fFT2() { |
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.
Lower-case f in fFT2
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.
That's to give it package scope. See the example names section https://blog.golang.org/examples
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.
Oh, there's always something to learn. Thanks.
Thanks. There are a few of things to do; On the subject of the internal/fftpack package: I know we've done this kind of thing in mathext, but I'm really not convinced it's a good idea. The package boundary is to define separation of concerns and modularity. I don't see that division here except as a consequence of history. Though maybe it does help in debugging with other implementations. Comments? |
The implementation of FFT and IFFT here are a direct translation of the RFFTI/RFFTF/RFFTB and CFFTI/CFFTF/CFFTB functions from FFTPACK. The Fortranisms will be reduced, but not eliminated (column major will remain). API will follow.
I've done as much history condensation as I think is achievable while retaining the capacity to identify bugs later. |
Semicolon sounds great. I think it's a separation of concerns. The code base isn't really "native go", just translated fortran, while the main package is novel code. The FFTPack code has additional "license" documentation that goes with it that the other code does not have. I think it's also good to separate for other implementations, in particular it would be nice to clean up a lot of the FFTPack code (i.e. using |
OK. I'll try to rebase it into a new package and at the same time add the semicolons. I'll ping when it's done since that push won't alert you. |
Actually, the history revision is non-trivial to the extent that I think I will just add another commit moving the fftpack code out to the internal package. There is too much breakage opportunity doing it the way I initially wanted. |
PTAL |
Thanks for the review. |
Please take a look.
So far I have only added the backing code. I want to add CFFT[IFB] and then I will dismantle some of the
array.go
support (remove 1-based indexing and the linear support types). It makes sense to add the API in this PR, so suggestions welcome here.