Repository navigation
Add stft and istft to mlx.core.fft - #3639
Conversation
|
|
||
| namespace { | ||
|
|
||
| // Pad the last axis; mx::pad has no reflect mode, so build it from take. |
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?
There was a problem hiding this comment.
Thanks for verifying, let's just keep the local version for now.
zcbenz
left a comment
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.
ab45a15 to
bae1de8
Compare
|
Approved and green since mid-June. Not sure if this is waiting on something or just got buried. |
bae1de8 to
a597978
Compare
zcbenz
left a comment
There was a problem hiding this comment.
@eyupcanakman Sorry for the long wait, I was waiting if someone else more familiar with fourier transform could take another look.
Would you mind replacing the pad_last_axis with pad op which supports reflect mode now? And then we can merge.
Remove the pad_last_axis helper and call pad directly now that reflect mode is supported. Inputs no longer than n_fft / 2 with pad_mode="reflect" now follow NumPy's repeated reflection behavior.
a597978 to
5eec6d9
Compare
|
Replaced pad_last_axis with pad, removed the helper, and rebased on main (signals no longer than n_fft / 2 with reflect padding now follow NumPy's repeated reflection). Could you please approve the CI run when you get a chance? |
|
Thanks for your patience! |
Proposed changes
Adds
stftandistfttomlx.core.fft, closes #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