Skip to content

Commit

Permalink
removed contiguity requirement for audio. fixes #1133 (#1140)
Browse files Browse the repository at this point in the history
  • Loading branch information
bmcfee committed Jun 1, 2020
1 parent 3f59a4f commit 18a6dc8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
9 changes: 2 additions & 7 deletions librosa/util/utils.py
Expand Up @@ -236,8 +236,8 @@ def valid_audio(y, mono=True):
- `y.dtype` is not floating-point
- `mono == True` and `y.ndim` is not 1
- `mono == False` and `y.ndim` is not 1 or 2
- `mono == False` and `y.ndim == 2` but `y.shape[0] == 1`
- `np.isfinite(y).all()` is False
- `y.flags["F_CONTIGUOUS"]` is False
Notes
-----
Expand All @@ -258,8 +258,6 @@ def valid_audio(y, mono=True):
See also
--------
stack
numpy.asfortranarray
numpy.float32
'''

Expand All @@ -276,17 +274,14 @@ def valid_audio(y, mono=True):
elif y.ndim > 2 or y.ndim == 0:
raise ParameterError('Audio data must have shape (samples,) or (channels, samples). '
'Received shape={}'.format(y.shape))

elif y.ndim == 2 and y.shape[0] < 2:
raise ParameterError('Mono data must have shape (samples,). '
'Received shape={}'.format(y.shape))

if not np.isfinite(y).all():
raise ParameterError('Audio buffer is not finite everywhere')

if not y.flags["F_CONTIGUOUS"]:
raise ParameterError('Audio buffer is not Fortran-contiguous. '
'Use numpy.asfortranarray to ensure Fortran contiguity.')

return True


Expand Down
6 changes: 2 additions & 4 deletions tests/test_failures.py
Expand Up @@ -91,14 +91,12 @@ def test_valid_audio_ndim(y, mono):
librosa.util.valid_audio(y, mono=mono)


@pytest.mark.xfail(raises=librosa.ParameterError)
def test_valid_audio_strided():
"""valid_audio: strided"""
y = np.zeros(1000)[::2]
librosa.util.valid_audio(y)


@pytest.mark.xfail(raises=librosa.ParameterError)
def test_valid_audio_clang():
"""valid_audio: C-contiguous"""
y = np.zeros(1000).reshape(2, 500)
Expand All @@ -112,11 +110,11 @@ def test_frame_hop():
librosa.util.frame(y, frame_length=10, hop_length=0)


@pytest.mark.xfail(raises=librosa.ParameterError)
def test_frame_discontiguous():
"""frame: discontiguous input"""
y = np.zeros((128, 2)).T
librosa.util.frame(y[0], frame_length=64, hop_length=64)
with pytest.warns(UserWarning):
librosa.util.frame(y[0], frame_length=64, hop_length=64)


def test_frame_contiguous():
Expand Down

0 comments on commit 18a6dc8

Please sign in to comment.