-
Notifications
You must be signed in to change notification settings - Fork 124
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
FFT module revamp + updating dune-lang #680
Conversation
Things would be much easier to review if ocamlformat update and dune lang bump were in two separate commits and not mixed with owl logic. |
Yes actually that's what I was thinking about when seeing the enormous diff. I'll revert the changes made by the new version of OCaml format. And push a new commit so it'll be easier for you to check the changes. |
- Added several new functionnalities to the FFT module by changing the dependency from FFTPACK to POCKETFTT. - new optionnal parameters for the API (nthreads, norm, ...) - new functions for cosine and sine transforms (dct, dst, ...) - Switched from dune 2.0 to dune 3.16 (this was required as I ran throught issues with linking while using 2.0)
I force-pushed to the branch only the modifications I added to the Owl logic, and discarded the ones that were due to the ocamlformat version update. The diff should be way smaller now for code review. |
src/owl/fftpack/owl_fft_generic.mli
Outdated
|
||
val dct | ||
: ?axis:int | ||
-> ?ttype: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.
What does this stand for? You could avoid the asserts like assert (ttype > 0 || ttype < 5)
by introducing a new more descriptive type for these that converts to the specific int and enforces the constraints. However, I am not sure if this impacts performances (I think it can be erased by the compiler)
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.
Hi, thanks for your review. The ttype option is for the Cosine and Sine transforms type (see scipy.fft.dct and scipy.fft.dst for references as I inspired the implementation from their).
Regarding the assert, I was trying to stick with the current state of Owl. Lots of conditions checking are done with asserts through the code (which I agree with you is not optimal). Sure thing, introducing a custom type here might be beneficial.
Thanks !
- Added the ttrig_transform type to specify the DCT and DST types - Added the tnorm type to specify the normalization option for the FFTs.
@gabyfle Thanks a lot for this nice contribution! Do you think you could also add some extra examples and tests for the revised FFT module? |
Hi, thanks for the review. I just saw that CI failed, I'll try to investigate as it compiles well on my Ubuntu installation. Of course, I'll add some tests though I'm unfamiliar with Alcotest, I'll try my best and feel free to correct me if I'm misusing it. EDIT: looks like the main issue is the |
- One "complex" usage: computing a PSD spectrogram from input data - One "simple" usage: computing the maximum frequency peak in time series data using rfft.
- Fixed an issue where the DCT/DST parameters weren't passed in the right order - Fixed an issue where the norm factor of the DCT wasn't computed correctly (incorrect delta) - Generated a unit_fft file that tests various parameters of FFT. Values are generated using scipy.fft module for the FFT, DCT and DST functions - Changed pocketfft::detail:: namespace usage to just pocketfft:: in the C++ code for more readability
@jzstark I added a This allowed me to spot two little issues in the implementation:
These issues are fixed and all the added tests are passing. I'm unsure whether or not I'm using EDIT: I'm already using these modifications inside my sound library code. You can see DCT in action here: https://github.com/gabyfle/SoundML/blob/feature/mfcc/src/feature/spectral/spectral.ml#L249-L285 |
I'll get rid of the submodule and directly put a copy of the |
Hi @jzstark, The CI should be fixed. I added manually the |
Thank you so much for the fix @gabyfle ! Really appreciate the workload doing this. It already works on the ubuntu + OCaml 5.1 environment, which is actually quite nice. But it would still be great if we can find out how to fix the issues on mac and OCaml 4.x versions. Unfortunately I don't have the environments at hands to give it a quick local debugging now. |
@jzstark Ubuntu compile for versions 4.x should be fixed now. The only issue I'll have now is that I don't have a MacOS computer to run the builds on my machine for the moment. I'll let you know once it's done ! |
- Kept the declaration inside the extern C but moved away the declaration, as an attempt to fix MacOS builds.
This works well and passes all the tests with ocaml 4.14.1 on my mac. I don't understand the failure for 4.10, see below.
The failure in https://github.com/owlbarn/owl/actions/runs/11894830732/workflow is on homebrew side: macos workers come with an old version of base packages preinstalled and now conflict with the new pkgconfig package (which changed name to pkgconf). It has nothing to do with this PR, I'll send a fix attempt separately. The failure of https://github.com/owlbarn/owl/actions/runs/11894830682?pr=680 is due to some issue with github pages actions, independent of this PR |
@mseri Thanks a lot for looking into this issue. Yes I think the error on 4.10 is more likely an Action problem with the OCaml version numbers now that the installation works on other platforms. I will first update the github action setup with your new PR. @gabyfle Thanks for the quick fixes and very solid PR! |
Thanks a lot for looking after this issue, I was tearing my hair out over this problem, not understanding what did I do wrong ! Glad to see it's not on my side !
No problem, thanks to you to keep updated Owl and maintening the project so far ! |
- Added norm and nthreads parameters.
@gabyfle Now the checks work fine (except for the 4.10 version we have already decide to dump). So everything looks fine other than the SciPy performance gap problem you mentioned. Please let me know if you think the current results are better and this PR is ready to go. (Perhaps also incorporate this performance gap check into the unit test?) |
@jzstark Thanks for your reply. Actually, there are no performances gap (that's why I deleted the comment). I was checking results computed with I personnally tested it on few testing audio I have for the library I'm building, and it works like a charm. |
Perfect! Thanks for this great PR again! |
Introduction
Hello everyone. In order to be able to add more features to the Audio processing library I'm currently building on top of Owl (see: https://github.com/gabyfle/SoundML), I needed to be able to compute Discrete Cosine & Sine transforms (in order to compute MFCC and other related things). The Owl's FFT module was so far pretty empty even if very usefull, only exposing real and complex discrete fourier transforms, but with only few prameters available.
After checking out what was done in the well known Scipy Python library and comparing with what was done inside Owl, I found out that Owl was using FFTPACK for the computation. In order to stay a maximum compatible with the existing Owl's API, I used (like in the Scipy library) pocketfft which comes as a C++ header-only library.
In fact these additions should not break any code (it's 100% same API), and it might even enhance it because we gained some of the features of pocketfft:
dct
,idct
,dst
,idst
inside theOwl.Fft
module.ocamlformat
fileexamples
folderI hope that these new features / enhancements will please you ! Please, feel free to let me know if you find out anything wrong/unexpected.
gabyfle.
Main changes:
(lang dune 2.0)
to(lang dune 3.16)
version=0.20.0
toversion=0.26.2