Speed up large-index mapping by avoiding repeated unique and using fast integer dedupicator#33
Merged
cmutel merged 5 commits intobrightway-lca:mainfrom Feb 27, 2026
Merged
Conversation
cmutel
reviewed
Feb 26, 2026
cmutel
reviewed
Feb 26, 2026
Member
|
It's crazy that using pandas is faster than numpy for |
Member
|
@jsvgoncalves This PR proposes including |
Contributor
Author
|
There still seems to be a test failing (tests/monte_carlo.py::test_distributions_without_uncertainties), but it does not appear to be caused by the proposed changes. |
jsvgoncalves
approved these changes
Feb 27, 2026
Member
|
The failing test is probabilistic - it should fail a small percentage of the time, or at least that the way it currently works. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR fixes a performance bottleneck in
matrix_utilswhen building large mapped matrices (especially technosphere).In my large case (~4.46M index entries), almost all runtime was spent inside index deduplication for
ArrayMapper, withnp.uniquetaking hundreds of seconds on unsorted integer arrays.What changed
np.sort(pd.unique(array))instead of plainnp.unique(array). Keepnp.uniqueas fallback/for smaller arrays.ArrayMapperdeduplicate once.Result
On the same large technosphere case:
build_tech_mm: ~500s -> ~0.65sNo other changes are intended. This should not break anything, but I have not tested that thoroughly.