Skip to content

Commit dd092dd

Browse files
authored
Merge pull request #39 from Curucail/numba-to-numpy-vectorization
Remove unneccessary Numba usage -> use numpy vectorization
2 parents 583b47d + 9955887 commit dd092dd

13 files changed

Lines changed: 38 additions & 53 deletions

File tree

.github/workflows/test_conda.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@ jobs:
1717

1818
steps:
1919
- uses: actions/checkout@v2
20-
- name: Set up Python 3.12
20+
- name: Set up Python 3.14
2121
uses: actions/setup-python@v2
2222
with:
23-
python-version: 3.12
23+
python-version: 3.14
2424
- name: Add conda to system path
2525
run: |
2626
# $CONDA is an environment variable pointing to the root of the miniconda directory
2727
echo $CONDA/bin >> $GITHUB_PATH
2828
- name: Install dependencies
2929
run: |
30-
conda install -c conda-forge libsndfile python=3.11
30+
conda install -c conda-forge libsndfile python=3.14
3131
python -m pip install .['test']
3232
- name: Lint with flake8
3333
run: |

.github/workflows/test_pip.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ jobs:
2323
- '3.10'
2424
- 3.11
2525
- 3.12
26+
- 3.13
27+
- 3.14
2628

2729
steps:
2830
- uses: actions/checkout@v2

environment.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ channels:
55
- conda-forge
66

77
dependencies:
8-
- python>=3.8.0, <3.13.0
8+
- python>=3.10.0, <3.15.0
99
- ipython
1010
- jupyter
1111

1212
- pip:
13-
- synctoolbox==1.2.*
13+
- synctoolbox==1.4.*

pyproject.toml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ build-backend = "flit_core.buildapi"
44

55
[project]
66
name = "synctoolbox"
7-
version = "1.4.1"
7+
version = "1.4.2"
88
description = "Python Package for Efficient, Robust, and Accurate Music Synchronization (Sync Toolbox)"
99
readme = "README.md"
10-
requires-python = ">=3.10, <3.13.0"
10+
requires-python = ">=3.10, <3.15.0"
1111
license = {text = "MIT"}
1212
authors = [
1313
{name = "Meinard Müller", email = "meinard.mueller@audiolabs-erlangen.de"},
@@ -24,16 +24,16 @@ classifiers = [
2424
"Programming Language :: Python :: 3",
2525
]
2626
dependencies = [
27-
"librosa >= 0.10.0, < 1.0.0",
28-
"matplotlib >= 3.1.0, < 4.0.0",
29-
"music21 >= 9.1.0, < 10.0.0",
30-
"numba >= 0.58.1, < 0.60.0",
31-
"numpy >= 1.17.0, < 2.0.0",
32-
"pandas >= 2.1.0, < 3.0.0",
33-
"pretty_midi >= 0.2.0, < 1.0.0",
34-
"soundfile >= 0.9.0, < 1.0.0",
35-
"scipy >= 1.7.0, < 2.0.0",
36-
"libfmp >= 1.2.0, < 2.0.0"
27+
"librosa >= 0.11.0, < 1.0.0",
28+
"matplotlib >= 3.10.0, < 4.0.0",
29+
"music21 >= 9.9.0, < 10.0.0",
30+
"numba >= 0.63.0, < 0.66.0",
31+
"numpy >= 2.0.0, < 2.5.0",
32+
"pandas >= 2.3.0, < 3.0.0",
33+
"pretty_midi >= 0.2.11, < 1.0.0",
34+
"soundfile >= 0.13.0, < 1.0.0",
35+
"scipy >= 1.15.0, < 2.0.0",
36+
"libfmp >= 1.3.0, < 2.0.0"
3737
]
3838

3939
[project.optional-dependencies]
@@ -43,7 +43,7 @@ develop = [
4343
"jupyter",
4444
"nbstripout"
4545
]
46-
test = ["pytest == 6.2.*"]
46+
test = ["pytest >= 8.3.0, < 9.0.0"]
4747
doc = [
4848
"sphinx == 4.0.*",
4949
"sphinx_rtd_theme == 0.5.*"

sync_audio_audio_simple.ipynb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
},
9191
"outputs": [],
9292
"source": [
93-
"audio_2, _ = librosa.load('data_music/Schubert_D911-01_SC06.wav', Fs)\n",
93+
"audio_2, _ = librosa.load('data_music/Schubert_D911-01_SC06.wav', sr=Fs)\n",
9494
"\n",
9595
"plot_signal(audio_2, Fs=Fs, ylabel='Amplitude', title='Version 2', figsize=figsize)\n",
9696
"ipd.display(ipd.Audio(audio_2, rate=Fs))"
@@ -228,7 +228,7 @@
228228
],
229229
"metadata": {
230230
"kernelspec": {
231-
"display_name": "Python 3 (ipykernel)",
231+
"display_name": ".venv",
232232
"language": "python",
233233
"name": "python3"
234234
},
@@ -242,7 +242,7 @@
242242
"name": "python",
243243
"nbconvert_exporter": "python",
244244
"pygments_lexer": "ipython3",
245-
"version": "3.11.5"
245+
"version": "3.14.3"
246246
}
247247
},
248248
"nbformat": 4,

synctoolbox/dtw/anchor.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from numba import jit
21
import numpy as np
32
from typing import Tuple
43

@@ -137,11 +136,9 @@ def derive_neighboring_anchors(warping_path: np.ndarray,
137136
return neighboring_anchors, neighboring_anchor_indices
138137

139138

140-
@jit(nopython=True)
141139
def __compute_area(a: tuple,
142140
b: tuple):
143141
"""Computes the area between two points, given as tuples"""
144142
return (b[0] - a[0] + 1) * (b[1] - a[1] + 1)
145143

146144

147-

synctoolbox/dtw/cost.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
from numba import jit
21
import numpy as np
32
from sklearn.metrics.pairwise import euclidean_distances
43

54

6-
#@jit(nopython=True)
75
def cosine_distance(f1, f2, cos_meas_max=2.0, cos_meas_min=1.0):
86
"""For all pairs of vectors f1' and f2' in f1 and f2, computes 1 - (f1.f2),
97
where '.' is the dot product, and rescales the results to lie in the
@@ -13,8 +11,6 @@ def cosine_distance(f1, f2, cos_meas_max=2.0, cos_meas_min=1.0):
1311
return (1 - f1.T @ f2) * (cos_meas_max - cos_meas_min) + cos_meas_min
1412

1513

16-
17-
#@jit(nopython=True)
1814
def euclidean_distance(f1, f2, l2_meas_max=1.0, l2_meas_min=0.0):
1915
"""Computes euclidean distances between the vectors in f1 and f2, and
2016
rescales the results to lie in the range [cos_meas_min, cos_meas_max]."""
@@ -76,4 +72,3 @@ def compute_high_res_cost_matrix(f_chroma1: np.ndarray,
7672
euc_dis = euclidean_distance(f_onset1, f_onset2, l2_meas_min=l2_meas_min, l2_meas_max=l2_meas_max)
7773

7874
return weights[0] * cos_dis + weights[1] * euc_dis
79-

synctoolbox/dtw/mrmsdtw.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from numba import jit
21
import numpy as np
32
import time
43
from typing import List, Tuple, Optional
@@ -495,7 +494,6 @@ def __diagonal_warping_path(f1: np.ndarray,
495494
return np.array([np.linspace(0, min_size-1, min_size), np.round(np.linspace(0, max_size - 1, min_size))])
496495

497496

498-
@jit(nopython=True)
499497
def __compute_area(f1, f2):
500498
"""Computes the area of the cost matrix given two feature sequences
501499

synctoolbox/dtw/utils.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,11 +228,12 @@ def find_anchor_indices_in_warping_path(warping_path: np.ndarray,
228228
indices : np.ndarray [shape=(2, M)]
229229
Anchor indices in the ``warping_path``
230230
"""
231-
indices = np.zeros(anchors.shape[1])
231+
indices = np.zeros(anchors.shape[1], dtype=int)
232232

233233
for k in range(anchors.shape[1]):
234234
a = anchors[:, k]
235-
indices[k] = np.where((a[0] == warping_path[0, :]) & (a[1] == warping_path[1, :]))[0]
235+
anchor_indices = np.flatnonzero((a[0] == warping_path[0, :]) & (a[1] == warping_path[1, :]))
236+
indices[k] = anchor_indices[0]
236237

237238
return indices
238239

synctoolbox/feature/dlnco.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ def pitch_onset_features_to_DLNCO(f_peaks: dict,
7171
for midi_pitch in range(midi_min, midi_max + 1):
7272
if midi_pitch not in f_peaks:
7373
continue
74-
time_peaks = f_peaks[midi_pitch][0, :] / 1000 # Now given in seconds
75-
val_peaks = np.log(f_peaks[midi_pitch][1, :] * log_compression_gamma + 1)
74+
time_peaks = np.asarray(f_peaks[midi_pitch][0, :] / 1000).reshape(-1) # Now given in seconds
75+
val_peaks = np.asarray(np.log(f_peaks[midi_pitch][1, :] * log_compression_gamma + 1)).reshape(-1)
7676
ind_chroma = np.mod(midi_pitch, 12)
7777
for k in range(time_peaks.size):
7878
indTime = __matlab_round(time_peaks[k] * feature_rate) # Usage of "round" accounts
@@ -166,6 +166,7 @@ def __visualize_LN_features(f_N: np.ndarray,
166166

167167
def __matlab_round(x: float = None) -> int:
168168
"""Workaround to cope the rounding differences between MATLAB and python"""
169+
x = float(np.asarray(x).squeeze())
169170
if x - np.floor(x) < 0.5:
170171
return int(np.floor(x))
171172
else:

0 commit comments

Comments
 (0)