Add stft and istft to mlx.core.fft#3639
Open
eyupcanakman wants to merge 1 commit into
Open
Conversation
zcbenz
reviewed
Jun 10, 2026
|
|
||
| namespace { | ||
|
|
||
| // Pad the last axis; mx::pad has no reflect mode, so build it from take. |
Contributor
Author
There was a problem hiding this comment.
Yeah, its reflect mode matches what this helper does and also handles pad >= n, so I can drop the helper and call pad directly once it lands. Want me to rebase on it after it merges, or keep the local version for now?
Collaborator
There was a problem hiding this comment.
Thanks for verifying, let's just keep the local version for now.
zcbenz
approved these changes
Jun 14, 2026
zcbenz
left a comment
Collaborator
There was a problem hiding this comment.
I must admit I'm not familiar with short-time fft at all, but the implementation looks good, and the tests are well-written, so this PR looks good to me.
| StreamOrDevice s = {}); | ||
|
|
||
| /** Compute the inverse Short-Time Fourier Transform. */ | ||
| MLX_API array istft( |
Collaborator
There was a problem hiding this comment.
Can you move the function declarations and implementations to the end of the files, so the functions are listed in the same order?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Proposed changes
Adds
stftandistfttomlx.core.fft, closing #1004. Both are written in C++ so they are available from every language binding.stftframes the last axis withas_strided, applies the window, and runsrfft(orfftfor two-sided output).istftinverts that with an overlap-add normalized by the squared-window envelope. The signature followstorch.stft, exceptnormtakes the same"backward"/"ortho"/"forward"string the rest ofmlx.fftuses. Batched input works and the output has shape(..., n_freq, n_frames).Tested against
torch.stftandtorch.istftover reflect, constant, and edge padding, one-sided and two-sided transforms, theorthonorm, batched input, andn_fftthat is not a multiple ofhop_length. The C++ tests cover the shapes, an overlap-add round-trip, and the error paths.Checklist
pre-commit run --all-filesto format my code / installed pre-commit prior to committing changes