Refactor fractionSum for simplicity and performance #1674
Closed
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.
Important: I wasn't able to get the current version of the master branch to pass the tests even without any changes (perhaps I was doing something wrong). So this PR was made on top of the fix-mypy-error branch. That means that accepting this PR will also merge the fix-mypy-error branch changes.
About the actual changes I made, they're all in music21/meter/tools.py -> fractionSum. fractionSum is refactored to be easier to read and more performant. The same results are returned in the same format, but there's between a 0% and 50% decrease in runtime depending on the case. I didn't measure memory usage but it should also be lower since fewer iterables are created.
If this sort of PR is wanted, I have about 10 small changes (even smaller than this one) ready to go that I could also contribute. If so, is it better to commit each one individually, or one altogether? I dove into python sets and other basic structures and wanted to apply that knowledge in a practical way, and that is common thread in the changes.