Skip to content

Commit c4af55b

Browse files
committed
improved the integration of cython backend, and added test for it
1 parent 488fba2 commit c4af55b

6 files changed

Lines changed: 462 additions & 130 deletions

File tree

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,23 @@ Run only smoke tests:
5858

5959
python -m pytest -k smoke
6060

61+
62+
Cython backend
63+
--------------
64+
65+
sms-tools includes a compiled Cython extension for selected core routines.
66+
When available, it is used automatically for better performance.
67+
If it cannot be imported, sms-tools falls back to pure-Python implementations
68+
with the same public behavior (typically slower).
69+
70+
You can verify which backend is active at runtime:
71+
72+
python - <<'PY'
73+
from smstools.models import utilFunctions as UF
74+
print("Using Cython backend:", UF.UF_C is not None)
75+
print("Backend module:", getattr(UF.UF_C, "__file__", None))
76+
PY
77+
6178
Test case summary:
6279

6380
* `tests/test_api_contracts.py`: API/signature and output-shape contract checks for core model entry points.

sms_tools.egg-info/PKG-INFO

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,15 @@ Run only smoke tests:
8282

8383
python -m pytest -k smoke
8484

85+
Test case summary:
86+
87+
* `tests/test_api_contracts.py`: API/signature and output-shape contract checks for core model entry points.
88+
* `tests/test_errors.py`: error-handling contracts (invalid parameters and invalid I/O paths).
89+
* `tests/test_models_smoke.py`: fast smoke coverage for all analysis/synthesis model modules.
90+
* `tests/test_transformations_smoke.py`: fast smoke coverage for all transformation modules.
91+
* `tests/test_models_ground_truth.py`: algorithmic/ground-truth model tests on synthetic signals (frequency accuracy, additivity, and quality invariants).
92+
* `tests/test_transformations_ground_truth.py`: algorithmic/ground-truth transformation tests (scaling/morphing identity behavior and expected interpolation/attenuation trends).
93+
8594

8695
Jupyter Notebooks
8796
-------

sms_tools.egg-info/SOURCES.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ smstools/transformations/stftTransformations.py
3131
smstools/transformations/stochasticTransformations.py
3232
tests/conftest.py
3333
tests/test_api_contracts.py
34+
tests/test_cython_vs_python.py
3435
tests/test_errors.py
36+
tests/test_models_ground_truth.py
3537
tests/test_models_smoke.py
38+
tests/test_multirate.py
39+
tests/test_transformations_ground_truth.py
3640
tests/test_transformations_smoke.py

smstools/models/utilFunctions.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -437,10 +437,12 @@ def sineSubtraction(x, N, H, sfreq, smag, sphase, fs):
437437
for l in range(L):
438438
xw = x[pin : pin + N] * w # window the input sound
439439
X = fft(fftshift(xw)) # compute FFT
440-
Yh = UF_C.genSpecSines(
441-
N * sfreq[l, :] / fs, smag[l, :], sphase[l, :], N
442-
) # generate spec sines, cython version
443-
# Yh = genSpecSines_p(N*sfreq[l,:]/fs, smag[l,:], sphase[l,:], N, fs) # generate spec sines, python version
440+
if UF_C is not None:
441+
Yh = UF_C.genSpecSines(
442+
N * sfreq[l, :] / fs, smag[l, :], sphase[l, :], N
443+
) # generate spec sines, cython version
444+
else:
445+
Yh = genSpecSines_p(sfreq[l, :], smag[l, :], sphase[l, :], N, fs) # python fallback
444446
Xr = X - Yh # subtract sines from original spectrum
445447
xrw = np.real(fftshift(ifft(Xr))) # inverse FFT
446448
xr[pin : pin + N] += xrw * sw # overlap-add
@@ -475,10 +477,12 @@ def stochasticResidualAnal(x, N, H, sfreq, smag, sphase, fs, stocf):
475477
for l in range(L):
476478
xw = x[pin : pin + N] * w # window the input sound
477479
X = fft(fftshift(xw)) # compute FFT
478-
Yh = UF_C.genSpecSines(
479-
N * sfreq[l, :] / fs, smag[l, :], sphase[l, :], N
480-
) # generate spec sines, cython version
481-
# Yh = genSpecSines_p(N*sfreq[l,:]/fs, smag[l,:], sphase[l,:], N, fs) # generate spec sines, python version
480+
if UF_C is not None:
481+
Yh = UF_C.genSpecSines(
482+
N * sfreq[l, :] / fs, smag[l, :], sphase[l, :], N
483+
) # generate spec sines, cython version
484+
else:
485+
Yh = genSpecSines_p(sfreq[l, :], smag[l, :], sphase[l, :], N, fs) # python fallback
482486
Xr = X - Yh # subtract sines from original spectrum
483487
mXr = 20 * np.log10(abs(Xr[:hN])) # magnitude spectrum of residual
484488
mXrenv = resample(

0 commit comments

Comments
 (0)