Skip to content

Conversation

ParamThakkar123
Copy link
Contributor

@ParamThakkar123 ParamThakkar123 commented Apr 13, 2025

Proposed changes

Please include a description of the problem or feature this PR is addressing. If there is a corresponding issue, include the issue #.

This PR introduces the implementations of Short Time and Inverse Short Time Fourier Transforms in mlx as addressed in issue #1004

Fixes #1004

Checklist

Put an x in the boxes that apply.

  • I have read the CONTRIBUTING document
  • I have run pre-commit run --all-files to format my code / installed pre-commit prior to committing changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have updated the necessary documentation (if needed)

@ParamThakkar123
Copy link
Contributor Author

ParamThakkar123 commented Apr 13, 2025

I referred to librosa's documentation on stft to write my implementation:
https://librosa.org/doc/main/generated/librosa.stft.html

and Pytorch's documentation:
https://pytorch.org/docs/stable/generated/torch.stft.html

Copy link
Member

@angeloskath angeloskath left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks well done from a first pass.

The main question to answer is whether this should be in the main mlx vs on a per library/use case implementation. I also think this shouldn't be in the top level of the package. We should come up with a better location if we are to merge this (I don't have a very good suggestion atm).

Regarding the PR content, I would definitely add docstrings and tests for the two functions.

@ParamThakkar123
Copy link
Contributor Author

@angeloskath would adding to the code to the utils.py be a better option ?

@awni
Copy link
Member

awni commented Apr 17, 2025

One option is to go the route of cloning scipy in MXL kind of like Jax (e.g. put this in a new package mlx.scipy.signal). It's a big package so I'm not really sure that's a good idea.

Another option is to put this in mlx.core.fft, but that would require a C++ implementation instead of a Python one (which may actually be handy to be honest because then we get it in all the APIs with simple bindings).

@ParamThakkar123
Copy link
Contributor Author

One option is to go the route of cloning scipy in MXL kind of like Jax (e.g. put this in a new package mlx.scipy.signal). It's a big package so I'm not really sure that's a good idea.

Another option is to put this in mlx.core.fft, but that would require a C++ implementation instead of a Python one (which may actually be handy to be honest because then we get it in all the APIs with simple bindings).

Okay, I would implement a C++ version of this and add it to mlx.core.fft

@ParamThakkar123
Copy link
Contributor Author

@awni should I create a separate namespace for this ??

@ParamThakkar123
Copy link
Contributor Author

in fft.cpp

@ParamThakkar123
Copy link
Contributor Author

@awni @angeloskath I have added a C++ implementation of stft in mlx.core.fft i.e. fft.cpp file. Can you please review it ??

@awni
Copy link
Member

awni commented Apr 17, 2025

The next step is to remove the Python one and make a binding in python/src/fft.cp

@ParamThakkar123
Copy link
Contributor Author

@awni I have added bindings and also removed the python implementation

@awni
Copy link
Member

awni commented Apr 18, 2025

This PR is missing tests.

@ParamThakkar123 ParamThakkar123 requested a review from awni April 18, 2025 17:52
@ParamThakkar123
Copy link
Contributor Author

@awni can you please review this PR ?

@ParamThakkar123
Copy link
Contributor Author

I have added all the fixes and tests

@ParamThakkar123
Copy link
Contributor Author

@awni I fixed the headers. Compiled and tested it and it works fine on my end.

@ParamThakkar123 ParamThakkar123 requested a review from awni April 24, 2025 14:09
@ParamThakkar123
Copy link
Contributor Author

@awni @angeloskath

@ParamThakkar123
Copy link
Contributor Author

@awni can you please review this PR ?

@ParamThakkar123
Copy link
Contributor Author

@awni @angeloskath ???

@ParamThakkar123 ParamThakkar123 requested a review from yrom May 7, 2025 09:54
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

Successfully merging this pull request may close these issues.

[Feature] Support Short-Time Fourier Transforms

4 participants