vectorized note and svara converters properly #1572
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Reference Issue
Fixes #1553
What does this implement/fix? Explain your changes.
This PR replaces the optional recursion in
midi_to_note
(and in_svara_*
) by a proper numpy vectorization. This simplifies both the implementation of these functions, and allows them to operate more cleanly on arbitrary array shapes.It also introduces a function
librosa.util.decorators.vectorize
, which operates similarly tonp.vectorize
but preserves scalar inputs. (Numpy vectorize, as noted in #1553, maps everything to arrays, including scalars.)Example usage:
With a multi-dimensional array (list of lists), we now produce a proper ndarray output:
with a scalar input, we produce a scalar output as exepcted:
This is a very slightly API-breaking change, in that we now produce ndarrays instead of lists. I'm okay with doing this without a full deprecation cycle, but we should definitely highlight it in the release notes.
Any other comments?
A few things I'd like to improve in this PR: