Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

beat.beat_track gives error: ufunc '_cabs2' did not contain a loop #1675

Closed
PasqualeTotaro opened this issue Feb 21, 2023 · 9 comments
Closed

Comments

@PasqualeTotaro
Copy link

PasqualeTotaro commented Feb 21, 2023

Hi,

I trying to run the first tutorial like below

import librosa

# 1. Get the file path to an included audio example
y, sr = librosa.load(librosa.ex('nutcracker'))

# Set the hop length; at 22050 Hz, 512 samples ~= 23ms
hop_length = 512

# Separate harmonics and percussives into two waveforms
y_harmonic, y_percussive = librosa.effects.hpss(y)
# plt.plot(y_percussive)


# Beat track on the percussive signal
tempo, beat_frames = librosa.beat.beat_track(y=y_percussive,
                                             sr=sr)

print('Estimated tempo: {:.2f} beats per minute'.format(tempo))

but I get the following error on beat_tracker:

Exception has occurred: _UFuncNoLoopError
ufunc '_cabs2' did not contain a loop with signature matching types <class 'numpy.dtype[complex128]'> -> None
  File "/Users/pasquale/Documents/Projects/ODD/Software/Jam Prototype/metadata/main.py", line 23, in <module>
    tempo, beat_frames = librosa.beat.beat_track(y=y_percussive,
numpy.core._exceptions._UFuncNoLoopError: ufunc '_cabs2' did not contain a loop with signature matching types <class 'numpy.dtype[complex128]'> -> None
@bmcfee
Copy link
Member

bmcfee commented Feb 21, 2023

Please fill out the issue template correctly with details about your environment.

I was able to run (more or less) the example as described with the 0.10.0 release:

In [1]: import librosa

In [2]: y, sr = librosa.load(librosa.ex('nutcracker'))

In [3]: yh, yp = librosa.effects.hpss(y)

In [4]: yp
Out[4]: 
array([ 1.3060981e-06,  3.4135082e-06, -4.7504541e-06, ...,
        4.0520217e-06,  7.1086342e-06,  3.9290107e-06], dtype=float32)

In [5]: librosa.beat.beat_track(y=yp, sr=sr)
Out[5]: 
(
    107.666015625,
    array([  51,   74,  100,  124,  149,  173,  198,  221,  246,  270,  295,
        319,  344,  367,  393,  415,  439,  461,  485,  507,  531,  554,
        577,  600,  623,  646,  669,  692,  716,  739,  762,  785,  807,
        831,  855,  877,  900,  923,  946,  969,  993, 1015, 1038, 1061,
       1085, 1107, 1131, 1155, 1178, 1201, 1225, 1248, 1272, 1296, 1320,
       1344, 1368, 1392, 1414, 1437, 1460, 1483, 1505, 1527, 1550, 1573,
       1595, 1618, 1641, 1664, 1688, 1712, 1735, 1758, 1782, 1806, 1829,
       1852, 1876, 1900, 1924, 1947, 1971, 1994, 2018, 2041, 2064, 2087,
       2110, 2132, 2155, 2177, 2200, 2222, 2244, 2266, 2289, 2312, 2335,
       2357, 2380, 2404, 2427, 2451, 2474, 2498, 2521, 2544, 2568, 2592,
       2615, 2638, 2661, 2684, 2706, 2728, 2752, 2775, 2797, 2819, 2842,
       2864, 2887, 2910, 2933, 2955, 2978, 3001, 3024, 3050, 3075, 3100,
       3125, 3150, 3174, 3199, 3223, 3246, 3269, 3295, 3317, 3340, 3362,
       3385, 3409, 3432, 3456, 3480, 3508, 3533, 3560, 3585, 3612, 3637,
       3663, 3688, 3714, 3740, 3766, 3791, 3816, 3841, 3866, 3890, 3915,
       3940, 3965, 3989, 4014, 4038, 4063, 4087, 4111, 4135, 4159, 4183,
       4208, 4231, 4255, 4279, 4304, 4327, 4351, 4374, 4399, 4422, 4447,
       4471, 4495, 4519, 4543, 4567, 4590, 4614, 4638, 4662, 4686, 4709,
       4734, 4758, 4781, 4805, 4829, 4853, 4877, 4901, 4925, 4949, 4973,
       4997, 5021])
)

@PasqualeTotaro
Copy link
Author

I am on Mac OS Venture 13.2. Using python 3.10.2 and librosa 0.10.0.

Running everything via VS code.

@bmcfee
Copy link
Member

bmcfee commented Feb 21, 2023

Can you please include the output of librosa.show_versions() here?

@PasqualeTotaro
Copy link
Author

Of course

INSTALLED VERSIONS
------------------
python: 3.10.2 (v3.10.2:a58ebcc701, Jan 13 2022, 14:50:16) [Clang 13.0.0 (clang-1300.0.29.30)]

librosa: 0.10.0

audioread: 3.0.0
numpy: 1.22.2
scipy: 1.10.1
sklearn: 1.2.1
joblib: 1.2.0
decorator: 5.1.1
numba: 0.56.4
soundfile: 0.12.1
pooch: v1.6.0
soxr: 0.3.3
typing_extensions: installed, no version number available
lazy_loader: installed, no version number available
msgpack: 1.0.4

numpydoc: None
sphinx: None
sphinx_rtd_theme: None
matplotlib: 3.7.0
sphinx_multiversion: None
sphinx_gallery: None
mir_eval: None
ipython: None
sphinxcontrib.rsvgconverter: None
pytest: None
pytest_mpl: None
pytest_cov: None
samplerate: None
resampy: None
presets: None
packaging: 23.0

@bmcfee
Copy link
Member

bmcfee commented Feb 21, 2023

Thanks - that's very strange. The error you're reporting indicates that the abs2 helper is not defined for complex128, but this is explicitly so here:

librosa/librosa/util/utils.py

Lines 2472 to 2477 in 1f770e8

@numba.vectorize(
["float32(complex64)", "float64(complex128)"], nopython=True, cache=True, identity=0
) # type: ignore
def _cabs2(x: _ComplexLike_co) -> _FloatLike_co: # pragma: no cover
"""Helper function for efficiently computing abs2 on complex inputs"""
return x.real**2 + x.imag**2

I suspected a numba issue was the cause, but we're on the same version (0.56.4), so that can't be it.

Are you able to run the example code snippets in the librosa.util.abs2 docstring?

@PasqualeTotaro
Copy link
Author

I can't.

here is the output

librosa.util.abs2(3 + 4j)
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/librosa/util/utils.py", line 2514, in abs2
    y = _cabs2(x)
numpy.core._exceptions._UFuncNoLoopError: ufunc '_cabs2' did not contain a loop with signature matching types <class 'numpy.dtype[complex128]'> -> None

and

librosa.util.abs2((0.5j)**np.arange(8))
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/librosa/util/utils.py", line 2514, in abs2
    y = _cabs2(x)
numpy.core._exceptions._UFuncNoLoopError: ufunc '_cabs2' did not contain a loop with signature matching types <class 'numpy.dtype[complex128]'> -> None

@bmcfee
Copy link
Member

bmcfee commented Feb 22, 2023

Ok, thanks for checking. I'm rather stumped here, as I've been unable to replicate this behavior. The only substantive difference between our environments that I can see is numpy 1.22.2 (yours) vs 1.23.5 (mine). However, nothing in the release notes (or my understanding of how these things work) suggests a change that would produce this behavior, and we do include numpy==1.20.3 and numba==0.51.0 in our minimal dependency test environment (which works).

The only other thing that comes to mind is that it appears that you've installed librosa in a system-wide environment (as super-user?), and that does occasionally cause trouble with numba when it can't cache the compiled function objects on disk. Usually this looks more like an indefinite hang on import, but I wonder if the behavior you're seeing is related?

We could test this hypothesis by changing the NUMBA_CACHE_DIR environment variable to something that your user has write permissions to, as noted here https://librosa.org/doc/latest/troubleshooting.html#import-librosa-hangs-indefinitely at the bottom.

@PasqualeTotaro
Copy link
Author

Good news, I have upgraded numpy and numba. Now it works!

Thank you for the helping me out.

@bmcfee
Copy link
Member

bmcfee commented Feb 23, 2023

Huh, well i'm glad it's working! But it would be nice to know what the problem was. I'll close this issue for now, but perhaps we can reopen it if it recurs in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants