Skip to content

Commit

Permalink
Merge pull request CPJKU#494 from CPJKU/v0.17_preparation
Browse files Browse the repository at this point in the history
v0.17 preparation
  • Loading branch information
Sebastian Böck authored Jan 6, 2022
2 parents a947e6c + dbc6d15 commit d958ed3
Show file tree
Hide file tree
Showing 58 changed files with 459 additions and 378 deletions.
2 changes: 1 addition & 1 deletion .codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ coverage:
status:
patch: false

comment: off
comment: off
6 changes: 6 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[flake8]
ignore = E203,W503,Q000
max-line-length = 80
per-file-ignores =
*/__init__.py: F401
tests/***.py: F405
27 changes: 27 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
hooks: # for a list of hooks see https://github.com/pre-commit/pre-commit-hooks
- id: check-added-large-files
args: ['--maxkb=100']
- id: check-case-conflict
- id: check-executables-have-shebangs
- id: check-json
- id: check-shebang-scripts-are-executable
- id: check-merge-conflict
- id: check-symlinks
- id: check-yaml
- id: destroyed-symlinks
- id: detect-private-key
- id: end-of-file-fixer
- id: file-contents-sorter
- id: mixed-line-ending
- id: no-commit-to-branch
- id: pretty-format-json
- id: requirements-txt-fixer
- id: sort-simple-yaml
- id: trailing-whitespace
- repo: https://gitlab.com/pycqa/flake8
rev: 3.9.2
hooks:
- id: flake8
2 changes: 1 addition & 1 deletion bin/KeyRecognition
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def main():
Filip Korzeniowski and Gerhard Widmer,
"Genre-Agnostic Key Classification with Convolutional Neural Networks",
In Proceedings of the 19th International Society for Music Information
In Proceedings of the 19th International Society for Music Information
Retrieval Conference (ISMIR), Paris, France, 2018.
This program can be run in 'single' file mode to process a single audio
Expand Down
2 changes: 1 addition & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# fake requirements for readthedocs
cython
numpydoc
mido
numpydoc
20 changes: 20 additions & 0 deletions environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: madmom
channels:
- conda-forge
- nodefaults
dependencies:
- python
- cython>=0.25
- numpy
- scipy
- opencv
- portaudio
- pip
- pip:
- mido>=1.2.6
- pyfftw
- pyaudio
- pytest
- black
- pre-commit
- prospector
6 changes: 3 additions & 3 deletions madmom/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@
doctest.__all__.append("NORMALIZE_FFT")
doctest.COMPARISON_FLAGS = doctest.COMPARISON_FLAGS | _NORMALIZE_FFT

_doctest_OutputChecker = doctest.OutputChecker
_DoctestOutputChecker = doctest.OutputChecker


class _OutputChecker(_doctest_OutputChecker):
class _OutputChecker(_DoctestOutputChecker):
"""
Output checker which enhances `doctest.OutputChecker` to compare doctests
and computed output with additional flags.
Expand Down Expand Up @@ -91,7 +91,7 @@ def check_output(self, want, got, optionflags):
got = re.sub(r'-3.14159', ' 3.14159', got)
want = re.sub(r'-3.14159', ' 3.14159', want)

super_check_output = _doctest_OutputChecker.check_output
super_check_output = _DoctestOutputChecker.check_output
return super_check_output(self, want, got, optionflags)


Expand Down
14 changes: 7 additions & 7 deletions madmom/audio/comb_filters.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def feed_forward_comb_filter(signal, tau, alpha):
# y[n] = x[n] + α * x[n - τ]
if tau <= 0:
raise ValueError('`tau` must be greater than 0')
y = signal.astype(np.float)
y = signal.astype(float)
# add the delayed signal
y[tau:] += alpha * signal[:-tau]
# return
Expand Down Expand Up @@ -90,10 +90,10 @@ def feed_backward_comb_filter(signal, tau, alpha):
"""
if signal.ndim == 1:
return _feed_backward_comb_filter_1d(signal.astype(np.float),
return _feed_backward_comb_filter_1d(signal.astype(float),
tau, alpha)
elif signal.ndim == 2:
return _feed_backward_comb_filter_2d(signal.astype(np.float),
return _feed_backward_comb_filter_2d(signal.astype(float),
tau, alpha)
else:
raise ValueError('signal must be 1d or 2d')
Expand Down Expand Up @@ -198,11 +198,11 @@ def comb_filter(signal, filter_function, tau, alpha):
"""
# convert tau to a integer numpy array
tau = np.array(tau, dtype=np.int, ndmin=1)
tau = np.array(tau, dtype=int, ndmin=1)
if tau.ndim != 1:
raise ValueError('`tau` must be a 1D numpy array')
# convert alpha to a numpy array
alpha = np.array(alpha, dtype=np.float, ndmin=1)
alpha = np.array(alpha, dtype=float, ndmin=1)
# expand a single alpha value to same length as tau
if len(alpha) == 1:
alpha = np.repeat(alpha, len(tau))
Expand Down Expand Up @@ -275,8 +275,8 @@ class CombFilterbankProcessor(Processor):

def __init__(self, filter_function, tau, alpha):
# convert tau and alpha to a numpy arrays
self.tau = np.array(tau, dtype=np.int, ndmin=1)
self.alpha = np.array(alpha, dtype=np.float, ndmin=1)
self.tau = np.array(tau, dtype=int, ndmin=1)
self.alpha = np.array(alpha, dtype=float, ndmin=1)
# set the filter function
if filter_function in ['forward', feed_forward_comb_filter]:
self.filter_function = feed_forward_comb_filter
Expand Down
10 changes: 5 additions & 5 deletions madmom/audio/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ def hz2midi(f, fref=A4):
to round it to the nearest integer.
"""
return (12. * np.log2(np.asarray(f, dtype=np.float) / fref)) + 69.
return (12. * np.log2(np.asarray(f, dtype=float) / fref)) + 69.


def midi2hz(m, fref=A4):
Expand All @@ -289,7 +289,7 @@ def midi2hz(m, fref=A4):
Corresponding frequencies [Hz].
"""
return 2. ** ((np.asarray(m, dtype=np.float) - 69.) / 12.) * fref
return 2. ** ((np.asarray(m, dtype=float) - 69.) / 12.) * fref


# provide an alias to semitone_frequencies
Expand Down Expand Up @@ -405,7 +405,7 @@ def bins2frequencies(bins, bin_frequencies):
"""
# map the frequencies to spectrogram bins
return np.asarray(bin_frequencies, dtype=np.float)[np.asarray(bins)]
return np.asarray(bin_frequencies, dtype=float)[np.asarray(bins)]


# filter classes
Expand Down Expand Up @@ -637,7 +637,7 @@ def __new__(cls, start, stop, norm=False):
# length of the filter
length = stop - start
# create filter
data = np.ones(length, dtype=np.float)
data = np.ones(length, dtype=float)
# cast to RectangularFilter and return it
return Filter.__new__(cls, data, start, norm)

Expand Down Expand Up @@ -732,7 +732,7 @@ def __new__(cls, data, bin_frequencies):
if len(bin_frequencies) != obj.shape[0]:
raise ValueError('`bin_frequencies` must have the same length as '
'the first dimension of `data`.')
obj.bin_frequencies = np.asarray(bin_frequencies, dtype=np.float)
obj.bin_frequencies = np.asarray(bin_frequencies, dtype=float)
# return the object
return obj

Expand Down
4 changes: 2 additions & 2 deletions madmom/audio/signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,8 @@ def energy(signal):
if np.iscomplex(signal).any():
signal = np.abs(signal)
# Note: type conversion needed because of integer overflows
if signal.dtype != np.float:
signal = signal.astype(np.float)
if signal.dtype != float:
signal = signal.astype(float)
# return energy
return np.dot(signal.flatten(), signal.flatten())

Expand Down
2 changes: 1 addition & 1 deletion madmom/audio/stft.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ class ShortTimeFourierTransform(_PropertyMixin, np.ndarray):
Doing the same with a Signal of float data-type will result in a STFT of
same value range (rounding errors will occur of course):
>>> sig = Signal('tests/data/audio/sample.wav', dtype=np.float)
>>> sig = Signal('tests/data/audio/sample.wav', dtype=float)
>>> sig # doctest: +NORMALIZE_WHITESPACE +ELLIPSIS
Signal([-0.07611, -0.0766 , ..., 0.01999, 0.0195 ])
>>> frames = FramedSignal(sig, frame_size=2048, hop_size=441)
Expand Down
46 changes: 23 additions & 23 deletions madmom/evaluation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,19 @@ def find_closest_matches(detections, annotations):
"""
# make sure the arrays have the correct types
detections = np.asarray(detections, dtype=np.float)
annotations = np.asarray(annotations, dtype=np.float)
detections = np.asarray(detections, dtype=float)
annotations = np.asarray(annotations, dtype=float)
# TODO: right now, it only works with 1D arrays
if detections.ndim > 1 or annotations.ndim > 1:
raise NotImplementedError('please implement multi-dim support')
# if no detections or annotations are given
if len(detections) == 0 or len(annotations) == 0:
# return a empty array
return np.zeros(0, dtype=np.int)
return np.zeros(0, dtype=int)
# if only a single annotation is given
if len(annotations) == 1:
# return an array as long as the detections with indices 0
return np.zeros(len(detections), dtype=np.int)
return np.zeros(len(detections), dtype=int)
# solution found at: http://stackoverflow.com/questions/8914491/
indices = annotations.searchsorted(detections)
indices = np.clip(indices, 1, len(annotations) - 1)
Expand Down Expand Up @@ -84,17 +84,17 @@ def calc_errors(detections, annotations, matches=None):
"""
# make sure the arrays have the correct types
detections = np.asarray(detections, dtype=np.float)
annotations = np.asarray(annotations, dtype=np.float)
detections = np.asarray(detections, dtype=float)
annotations = np.asarray(annotations, dtype=float)
if matches is not None:
matches = np.asarray(matches, dtype=np.int)
matches = np.asarray(matches, dtype=int)
# TODO: right now, it only works with 1D arrays
if detections.ndim > 1 or annotations.ndim > 1:
raise NotImplementedError('please implement multi-dim support')
# if no detections or annotations are given
if len(detections) == 0 or len(annotations) == 0:
# return a empty array
return np.zeros(0, dtype=np.float)
return np.zeros(0, dtype=float)
# determine the closest annotations
if matches is None:
matches = find_closest_matches(detections, annotations)
Expand Down Expand Up @@ -129,10 +129,10 @@ def calc_absolute_errors(detections, annotations, matches=None):
"""
# make sure the arrays have the correct types
detections = np.asarray(detections, dtype=np.float)
annotations = np.asarray(annotations, dtype=np.float)
detections = np.asarray(detections, dtype=float)
annotations = np.asarray(annotations, dtype=float)
if matches is not None:
matches = np.asarray(matches, dtype=np.int)
matches = np.asarray(matches, dtype=int)
# TODO: right now, it only works with 1D arrays
if detections.ndim > 1 or annotations.ndim > 1:
raise NotImplementedError('please implement multi-dim support')
Expand Down Expand Up @@ -165,17 +165,17 @@ def calc_relative_errors(detections, annotations, matches=None):
"""
# make sure the arrays have the correct types
detections = np.asarray(detections, dtype=np.float)
annotations = np.asarray(annotations, dtype=np.float)
detections = np.asarray(detections, dtype=float)
annotations = np.asarray(annotations, dtype=float)
if matches is not None:
matches = np.asarray(matches, dtype=np.int)
matches = np.asarray(matches, dtype=int)
# TODO: right now, it only works with 1D arrays
if detections.ndim > 1 or annotations.ndim > 1:
raise NotImplementedError('please implement multi-dim support')
# if no detections or annotations are given
if len(detections) == 0 or len(annotations) == 0:
# return a empty array
return np.zeros(0, dtype=np.float)
return np.zeros(0, dtype=float)
# determine the closest annotations
if matches is None:
matches = find_closest_matches(detections, annotations)
Expand Down Expand Up @@ -425,10 +425,10 @@ def __init__(self, tp=None, fp=None, tn=None, fn=None, **kwargs):
# instantiate a SimpleEvaluation object
super(Evaluation, self).__init__(**kwargs)
# convert everything to numpy arrays and save them
self.tp = np.asarray(list(tp), dtype=np.float)
self.fp = np.asarray(list(fp), dtype=np.float)
self.tn = np.asarray(list(tn), dtype=np.float)
self.fn = np.asarray(list(fn), dtype=np.float)
self.tp = np.asarray(list(tp), dtype=float)
self.fp = np.asarray(list(fp), dtype=float)
self.tn = np.asarray(list(tn), dtype=float)
self.fn = np.asarray(list(fn), dtype=float)

@property
def num_tp(self):
Expand Down Expand Up @@ -487,10 +487,10 @@ def __init__(self, tp=None, fp=None, tn=None, fn=None, **kwargs):
if fn is None:
fn = np.zeros((0, 2))
super(MultiClassEvaluation, self).__init__(**kwargs)
self.tp = np.asarray(tp, dtype=np.float)
self.fp = np.asarray(fp, dtype=np.float)
self.tn = np.asarray(tn, dtype=np.float)
self.fn = np.asarray(fn, dtype=np.float)
self.tp = np.asarray(tp, dtype=float)
self.fp = np.asarray(fp, dtype=float)
self.tn = np.asarray(tn, dtype=float)
self.fn = np.asarray(fn, dtype=float)

def tostring(self, verbose=False, **kwargs):
"""
Expand Down
Loading

0 comments on commit d958ed3

Please sign in to comment.