Skip to content

Commit

Permalink
Deal with new copy behaviour of np.array() in NumPy 2
Browse files Browse the repository at this point in the history
  • Loading branch information
jpauwels committed Aug 21, 2024
1 parent 1602f9f commit dc4b314
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 7 deletions.
3 changes: 2 additions & 1 deletion madmom/evaluation/tempo.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ def sort_tempo(tempo):
Tempi sorted according to their strength.
"""
tempo = np.array(tempo, copy=False, ndmin=1)
if not isinstance(tempo, np.ndarray):
tempo = np.array(tempo, ndmin=1)
if tempo.ndim != 2:
raise ValueError('`tempo` has no strength information, cannot sort '
'them.')
Expand Down
3 changes: 2 additions & 1 deletion madmom/features/beats.py
Original file line number Diff line number Diff line change
Expand Up @@ -1082,7 +1082,8 @@ def process_online(self, activations, reset=True, **kwargs):
"""
# cast as 1-dimensional array
# Note: in online mode, activations are just float values
activations = np.array(activations, copy=False, subok=True, ndmin=1)
if not isinstance(activations, np.ndarray):
activations = np.array(activations, ndmin=1)
# reset to initial state
if reset:
self.reset()
Expand Down
3 changes: 2 additions & 1 deletion madmom/features/onsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1125,7 +1125,8 @@ def process_online(self, activations, reset=True, **kwargs):
"""
# cast as 1-dimensional array
# Note: in online mode, activations are just float values
activations = np.array(activations, copy=False, subok=True, ndmin=1)
if not isinstance(activations, np.ndarray):
activations = np.array(activations, ndmin=1)
# buffer data
if self.buffer is None or reset:
# reset the processor
Expand Down
6 changes: 3 additions & 3 deletions madmom/features/tempo.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,8 @@ def process_online(self, activations, reset=True, **kwargs):
Corresponding delays [frames].
"""

activations = np.array(activations, copy=False, subok=True, ndmin=1, dtype=float)
if not isinstance(activations, np.ndarray):
activations = np.array(activations, ndmin=1, dtype=float)
# reset to initial state
if reset:
self.reset()
Expand All @@ -402,7 +402,7 @@ def process_online(self, activations, reset=True, **kwargs):
# iterate over all activations
# Note: in online mode, activations are just float values, thus cast
# them as 1-dimensional array
for act in np.array(activations, copy=False, subok=True, ndmin=1):
for act in activations:
# online feed backward comb filter (y[n] = x[n] + α * y[n - τ])
y_n = act + self.alpha * self._comb_buffer[idx]
# shift output buffer with new value
Expand Down
2 changes: 1 addition & 1 deletion madmom/processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,7 @@ def process(self, data, **kwargs):
ndmin = len(self.buffer_size)
# cast the data to have that many dimensions
if data.ndim < ndmin:
data = np.array(data, copy=False, subok=True, ndmin=ndmin)
data = np.array(data, ndmin=ndmin)
# length of the data
data_length = len(data)
# if length of data exceeds buffer length simply replace buffer data
Expand Down

0 comments on commit dc4b314

Please sign in to comment.