This document summarizes what we changed in nnAudio, which problems were fixed, how to run the project locally, and what results we expect to see.
The work described here focuses on the professor's explicit requests: compatibility with current Torch and dependencies, issue #132, issue #136, and a citation reminder for users.
The current local verification environment is:
- Python:
3.11.10 - Torch:
2.10.0+cpu - NumPy:
2.4.3 - SciPy:
1.17.1 - librosa:
0.11.0 - nnAudio package version:
0.3.4
Notes:
- The codebase has been updated to run correctly in this modern dependency environment.
- We did not bump the package version to
2.0; functionally, this is the start of maintaining a newer generation of nnAudio, not a formal package release named2.0.
This file received the largest set of changes and addresses two main issues.
Original problem:
torch.jit.script(STFT(...))failedtorch.jit.script(iSTFT(...))also failed
Main causes:
- Dynamic module attribute assignment inside
forward() - Dynamic padding module construction inside
forward() Nonehandling iniSTFTthat was not TorchScript-friendly
What we changed:
- Replaced dynamic attribute writes with local variables
- Replaced dynamically constructed padding modules with functional padding
- Tightened argument handling for TorchScript-facing paths
Result:
STFTcan now be compiled withtorch.jit.script(...)iSTFTcan now be compiled withtorch.jit.script(...)
Original problem:
freq_scale='linear'orfreq_scale='log'produced clearly poor inverse reconstructions- The code did not fail, which was misleading for users
What we changed:
- Added explicit inverse-support checks
- Defined reliable inverse support only for the standard uniform-bin case with
freq_scale='no' - Non-uniform frequency scales (
linear,log,log2) now raise a clear runtime error on inverse - Initialization warnings were added to mark these configurations as analysis-only
Result:
freq_scale='no': inverse still worksfreq_scale='linear' / 'log' / 'log2': inverse no longer silently returns bad audio; it now fails explicitly
This file was updated to support the TorchScript fix for issue #132.
What we changed:
- Added explicit type annotations to
torch_window_sumsquare(...)andoverlap_add(...) - Adjusted
fold(..., stride=...)argument handling to better match current Torch / TorchScript behavior
Result:
- The helper functions used by
iSTFTcan now be handled correctly by TorchScript
This file received new regression tests.
New coverage includes:
- TorchScript compilation for
STFT - TorchScript compilation for
iSTFT - Rejection behavior for inverse on non-uniform frequency scales
Result:
- These behaviors are now covered by tests instead of being only manually verified once
This file was updated for modern SciPy compatibility.
Original problem:
scipy.signal.blackmanharriswas no longer available at the old location under the current SciPy version
What we changed:
- Switched to
scipy.signal.windows.blackmanharris
Result:
- CFP-related tests now pass again
This file was updated to fix VQT/CQT compatibility behavior.
Original problem:
VQT(gamma=0)should theoretically reduce to CQT, but it showed a meaningful mismatch againstCQT1992v2
What we changed:
- When
gamma == 0,VQTnow explicitly routes throughCQT1992v2
Result:
VQT(gamma=0)is aligned with CQT behavior- The related tests now pass
This file implements the citation reminder requested by the professor.
Added:
__citation__cite()show_citation()CitationReminderWarning- Import-time citation reminder
NNAUDIO_DISABLE_CITATION_REMINDER=1to suppress the reminder
Result:
import nnAudionow reminds users to cite the paper- Users can also access the citation programmatically
This is a new test file for citation-related behavior.
Coverage includes:
- Citation text exists and contains the DOI
- The import-time warning appears
- The suppress environment variable works
To avoid misleading users about issue #136, we also updated:
README.mdSphinx/source/intro.rstSphinx/source/index.rst
The purpose here was not to expand scope, but to document the new supported/unsupported boundary clearly.
At this point, the following problems have been addressed:
- Core compatibility issues with current Torch and current dependencies
- issue
#132:STFT/iSTFTcould not be compiled with TorchScript - issue
#136: non-uniform frequency-scale inverse silently returned poor results - CFP initialization failed under modern SciPy
VQT(gamma=0)did not align with CQT behavior- The package had no built-in citation reminder
cd /junyi/nnAudio
source .venv/bin/activatepytest Installation/tests -qpytest Installation/tests/test_stft.py -qpython - <<'PY'
import nnAudio
print(nnAudio.__version__)
print(nnAudio.__citation__)
PYNNAUDIO_DISABLE_CITATION_REMINDER=1 python - <<'PY'
import nnAudio
print(nnAudio.__version__)
PYCommand:
pytest Installation/tests -qExpected result:
- You should currently see
57 passed - A number of warnings are acceptable
- There should be no failed tests
STFT and iSTFT should now compile with torch.jit.script(...) and should no longer raise the original issue #132 errors.
For:
freq_scale='no'
Expected result:
- inverse works
- reconstruction error remains very small
For:
freq_scale='linear'freq_scale='log'freq_scale='log2'
Expected result:
- inverse raises a clear exception
- this is expected behavior, not a bug
Reason:
- under the current implementation, these inverse paths are not numerically reliable
- explicit failure is safer than silently returning poor output
Command:
python - <<'PY'
import nnAudio
PYExpected result:
- a
CitationReminderWarningis shown - it reminds the user to cite the nnAudio paper
The test suite now passes completely, but a few warnings are still present:
- CFP still emits a
divide by zerowarning torch.stft(return_complex=False)has a future deprecation warningtorch.jit.scriptitself is deprecated in newer Torch versions
These are not blockers for the professor's current task, but they are reasonable cleanup targets for a later maintenance pass.
Against the professor's explicit task list:
- Current Torch / dependency compatibility: validated locally in a modern environment
- issue
#132: completed - issue
#136: completed via a safe supported/unsupported boundary - Citation reminder: completed via import-time reminder
At this stage, the core task requested by the professor can be considered complete.