loopyng 0.2.2__tar.gz → 0.2.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. {loopyng-0.2.2 → loopyng-0.2.4}/PKG-INFO +1 -1
  2. {loopyng-0.2.2 → loopyng-0.2.4}/loopyng/utils/librosa_utils.py +2 -2
  3. {loopyng-0.2.2 → loopyng-0.2.4}/pyproject.toml +4 -3
  4. loopyng-0.2.4/tests/test_librosa_utils_dtypes.py +143 -0
  5. {loopyng-0.2.2 → loopyng-0.2.4}/.gitignore +0 -0
  6. {loopyng-0.2.2 → loopyng-0.2.4}/LICENSE +0 -0
  7. {loopyng-0.2.2 → loopyng-0.2.4}/README.md +0 -0
  8. {loopyng-0.2.2 → loopyng-0.2.4}/loopyng/__init__.py +0 -0
  9. {loopyng-0.2.2 → loopyng-0.2.4}/loopyng/_optional.py +0 -0
  10. {loopyng-0.2.2 → loopyng-0.2.4}/loopyng/examples/__init__.py +0 -0
  11. {loopyng-0.2.2 → loopyng-0.2.4}/loopyng/examples/annotated_sounds.py +0 -0
  12. {loopyng-0.2.2 → loopyng-0.2.4}/loopyng/examples/tagged_intervals.py +0 -0
  13. {loopyng-0.2.2 → loopyng-0.2.4}/loopyng/gen/__init__.py +0 -0
  14. {loopyng-0.2.2 → loopyng-0.2.4}/loopyng/gen/diagnosis_sounds.py +0 -0
  15. {loopyng-0.2.2 → loopyng-0.2.4}/loopyng/gen/signal_generators.py +0 -0
  16. {loopyng-0.2.2 → loopyng-0.2.4}/loopyng/gen/simple.py +0 -0
  17. {loopyng-0.2.2 → loopyng-0.2.4}/loopyng/gen/sine_mix.py +0 -0
  18. {loopyng-0.2.2 → loopyng-0.2.4}/loopyng/gen/util.py +0 -0
  19. {loopyng-0.2.2 → loopyng-0.2.4}/loopyng/gen/voiced_time.py +0 -0
  20. {loopyng-0.2.2 → loopyng-0.2.4}/loopyng/lite_sample_sounds.py +0 -0
  21. {loopyng-0.2.2 → loopyng-0.2.4}/loopyng/scrap/__init__.py +0 -0
  22. {loopyng-0.2.2 → loopyng-0.2.4}/loopyng/sound/__init__.py +0 -0
  23. {loopyng-0.2.2 → loopyng-0.2.4}/loopyng/sound/audio.py +0 -0
  24. {loopyng-0.2.2 → loopyng-0.2.4}/loopyng/sound/audio_librosa.py +0 -0
  25. {loopyng-0.2.2 → loopyng-0.2.4}/loopyng/util.py +0 -0
  26. {loopyng-0.2.2 → loopyng-0.2.4}/loopyng/utils/__init__.py +0 -0
  27. {loopyng-0.2.2 → loopyng-0.2.4}/loopyng/utils/date_ticks.py +0 -0
  28. {loopyng-0.2.2 → loopyng-0.2.4}/loopyng/utils/infinite_waveform.py +0 -0
  29. {loopyng-0.2.2 → loopyng-0.2.4}/loopyng/utils/plotting.py +0 -0
  30. {loopyng-0.2.2 → loopyng-0.2.4}/tests/test_optional_deps.py +0 -0
  31. {loopyng-0.2.2 → loopyng-0.2.4}/tests/test_smoke.py +0 -0
  32. {loopyng-0.2.2 → loopyng-0.2.4}/tests/test_viz.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: loopyng
3
- Version: 0.2.2
3
+ Version: 0.2.4
4
4
  Summary: Generate synthetic signals for ML pipelines
5
5
  Project-URL: Homepage, https://github.com/thorwhalen/loopyng
6
6
  Project-URL: Repository, https://github.com/thorwhalen/loopyng
@@ -255,7 +255,7 @@ def __coord_chroma(n, bins_per_octave=12, **_kwargs):
255
255
 
256
256
 
257
257
  def tempo_frequencies(n_bins, hop_length=512, sr=22050):
258
- bin_frequencies = np.zeros(int(n_bins), dtype=np.float)
258
+ bin_frequencies = np.zeros(int(n_bins), dtype=float)
259
259
 
260
260
  bin_frequencies[0] = np.inf
261
261
  bin_frequencies[1:] = 60.0 * sr / (hop_length * np.arange(1.0, n_bins))
@@ -974,7 +974,7 @@ def normalize(S, norm=np.inf, axis=0, threshold=None, fill=None):
974
974
  raise Exception("Input must be finite")
975
975
 
976
976
  # All norms only depend on magnitude, let's do that first
977
- mag = np.abs(S).astype(np.float)
977
+ mag = np.abs(S).astype(float)
978
978
 
979
979
  # For max/min norms, filling with 1 works
980
980
  fill_norm = 1
@@ -6,7 +6,7 @@ build-backend = "hatchling.build"
6
6
 
7
7
  [project]
8
8
  name = "loopyng"
9
- version = "0.2.2"
9
+ version = "0.2.4"
10
10
  description = "Generate synthetic signals for ML pipelines"
11
11
  readme = "README.md"
12
12
  requires-python = ">=3.10"
@@ -185,7 +185,8 @@ install.linux = [
185
185
  "sudo apt-get install -y libsndfile1 libsndfile1-dev",
186
186
  ]
187
187
  install.macos = "brew install libsndfile"
188
- install.windows = "echo soundfile ships a bundled libsndfile in its Windows wheels; no system install needed"
188
+ # soundfile ships a bundled libsndfile in its Windows wheels: no system install needed,
189
+ # and wads verifies any declared install with the check above, so none is declared.
189
190
 
190
191
  [tool.wads.ops.gcc]
191
192
  description = "GCC - C toolchain, needed when a dependency has no wheel and builds from source"
@@ -198,7 +199,7 @@ install.linux = [
198
199
  "sudo apt-get install -y gcc",
199
200
  ]
200
201
  install.macos = "echo clang ships with the macOS runner Command Line Tools; no install needed"
201
- install.windows = "echo MSVC build tools ship with the Windows runner; no install needed"
202
+ # MSVC build tools ship with the Windows runner: no install needed (none declared).
202
203
 
203
204
  [tool.wads.ci]
204
205
  project_name = ""
@@ -0,0 +1,143 @@
1
+ """Guard the vendored librosa DSP against numpy's removed scalar-type aliases.
2
+
3
+ ``np.float`` was a deprecated alias for the builtin ``float``, and numpy 1.24
4
+ removed it. Two lines of the vendored librosa code still asked for it, and both
5
+ sat on live paths that no test ever walked:
6
+
7
+ * ``tempo_frequencies`` -- reached from ``specshow(..., y_axis='tempo')``
8
+ * ``normalize`` -- reached from ``mel`` (and so ``melspectrogram``) whenever
9
+ ``norm`` is anything but the default ``'slaney'``, and from
10
+ ``spectral_centroid`` unconditionally
11
+
12
+ Under any numpy new enough to have dropped the alias, calling those functions
13
+ raised ``AttributeError: module 'numpy' has no attribute 'float'``. The suite
14
+ stayed green because the only mel path it exercised was the default
15
+ ``norm='slaney'``, which happens to skip the broken line.
16
+
17
+ Each test below therefore asserts on an observable that the repaired line
18
+ actually decides -- a Nyquist bound, a filter bank that sums to one, a column
19
+ that only survives at full float precision -- rather than on a shape or a dtype
20
+ that would look identical with the line broken or narrowed. Shapes and
21
+ "it returned something" are what let the original breakage hide.
22
+ """
23
+
24
+ import numpy as np
25
+ import pytest
26
+
27
+ from loopyng.utils.librosa_utils import (
28
+ mel,
29
+ melspectrogram,
30
+ normalize,
31
+ spectral_centroid,
32
+ tempo_frequencies,
33
+ )
34
+
35
+ SR = 22050
36
+ N_FFT = 2048
37
+ HOP_LENGTH = 512
38
+ N_MELS = 128
39
+ NYQUIST = SR / 2
40
+ # ``_spectrogram`` centre-pads, so a one-second signal yields this many frames.
41
+ N_FRAMES = 1 + SR // HOP_LENGTH
42
+
43
+
44
+ @pytest.fixture
45
+ def noise():
46
+ """One second of reproducible white noise at ``SR``."""
47
+ return np.random.default_rng(0).standard_normal(SR).astype(np.float32)
48
+
49
+
50
+ def test_normalize_max_norms_each_column():
51
+ """``normalize`` divides every column by its own maximum magnitude."""
52
+ normalized = normalize(np.array([[1.0, 2.0], [3.0, 4.0]]))
53
+
54
+ assert np.allclose(normalized, [[1 / 3, 0.5], [1.0, 1.0]])
55
+
56
+
57
+ def test_normalize_takes_magnitudes_at_full_float_precision():
58
+ """The repaired ``np.abs(S).astype(float)`` must not narrow to float32.
59
+
60
+ No assertion on an ordinary input can see this: ``normalize`` builds its
61
+ result with ``np.empty_like(S)``, so the *output* dtype comes from the input
62
+ and says nothing about the magnitudes computed on the way. A column whose
63
+ magnitudes overflow float32 does see it -- narrowing makes the column
64
+ maximum ``inf``, and dividing by that zeroes the whole column.
65
+ """
66
+ beyond_float32 = np.array([[1e300, 1.0], [1e-300, 2.0]])
67
+
68
+ assert np.allclose(normalize(beyond_float32), [[1.0, 0.5], [0.0, 1.0]])
69
+
70
+
71
+ @pytest.mark.parametrize("dtype", [np.float32, np.float64])
72
+ def test_normalize_preserves_a_floating_input_dtype(dtype):
73
+ """``np.empty_like(S)`` means the input picks the output dtype, not the fix.
74
+
75
+ Worth pinning because it is easy to read the ``.astype(float)`` on the
76
+ magnitudes as a promise that the result is float64. It is not: the mel
77
+ filter bank, ``normalize``'s main caller here, is float32 and stays float32.
78
+ """
79
+ normalized = normalize(np.array([[1.0, 2.0], [3.0, 4.0]], dtype=dtype))
80
+
81
+ assert normalized.dtype == dtype
82
+ assert np.allclose(normalized, [[1 / 3, 0.5], [1.0, 1.0]])
83
+
84
+
85
+ def test_normalize_truncates_integer_input_as_upstream_librosa_does():
86
+ """Integer input comes back truncated -- matched on purpose, not overlooked.
87
+
88
+ ``np.empty_like(S)`` keeps an integer input's dtype, so the float division is
89
+ truncated on assignment into it. That is exactly what upstream
90
+ ``librosa.util.normalize`` does; this module is a vendored copy, so the
91
+ behaviour is matched rather than quietly corrected. Before the numpy-alias
92
+ fix every dtype raised ``AttributeError``, which is what kept the trap out of
93
+ sight -- pinning it here keeps it visible. Callers wanting ratios pass floats.
94
+ """
95
+ integers = np.array([[1, 2], [3, 4]])
96
+
97
+ assert np.array_equal(normalize(integers), [[0, 0], [1, 1]])
98
+ assert np.allclose(normalize(integers.astype(float)), [[1 / 3, 0.5], [1.0, 1.0]])
99
+
100
+
101
+ def test_tempo_frequencies_allocates_float_bins():
102
+ """Bin 0 holds ``inf``, which only a float array can.
103
+
104
+ Here the dtype assertion *is* the guard: ``np.zeros(n_bins, dtype=float)`` is
105
+ the repaired line, and the finite bins would survive a narrower dtype well
106
+ within ``allclose``'s tolerance.
107
+ """
108
+ n_bins = 4
109
+ bin_frequencies = tempo_frequencies(n_bins, hop_length=HOP_LENGTH, sr=SR)
110
+
111
+ assert bin_frequencies.dtype == np.float64
112
+ assert bin_frequencies[0] == np.inf
113
+ assert np.allclose(
114
+ bin_frequencies[1:], 60.0 * SR / (HOP_LENGTH * np.arange(1.0, n_bins))
115
+ )
116
+
117
+
118
+ def test_mel_filter_bank_with_non_slaney_norm(noise):
119
+ """``norm=1`` routes the filter bank through ``normalize``, so rows sum to 1.
120
+
121
+ The melspectrogram's shape cannot show this -- it is the same for every
122
+ ``norm``, including the default ``'slaney'`` that skips the repaired line
123
+ (and whose rows sum to roughly 0.09).
124
+ """
125
+ assert np.allclose(mel(SR, N_FFT, norm=1).sum(axis=1), 1.0)
126
+ assert melspectrogram(y=noise, sr=SR, n_fft=N_FFT, norm=1).shape == (
127
+ N_MELS,
128
+ N_FRAMES,
129
+ )
130
+
131
+
132
+ def test_spectral_centroid_stays_below_nyquist(noise):
133
+ """``spectral_centroid`` normalizes its spectrogram, so it needs the fix too.
134
+
135
+ The Nyquist bound is what makes this a test of the ``normalize`` call rather
136
+ than of the shape: drop the normalization and the "centroid" becomes a raw
137
+ weighted energy sum, four orders of magnitude above the highest frequency the
138
+ signal can even represent.
139
+ """
140
+ centroid = spectral_centroid(y=noise, sr=SR, n_fft=N_FFT, hop_length=HOP_LENGTH)
141
+
142
+ assert centroid.shape == (1, N_FRAMES)
143
+ assert np.all((centroid > 0) & (centroid < NYQUIST))
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes