Skip to content

Commit

Permalink
Merge pull request #1043 from CoffeaTeam/analysis-tools-lru
Browse files Browse the repository at this point in the history
perf: use an lru_cache for weight, partial_weight, require
  • Loading branch information
lgray committed Feb 17, 2024
2 parents 7484105 + 1226674 commit 3aeaad4
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/coffea/analysis_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import warnings
from collections import namedtuple
from functools import lru_cache

import awkward
import dask.array
Expand Down Expand Up @@ -346,6 +347,7 @@ def __add_variation(
elif isinstance(weight, dask_awkward.Array):
self.__add_variation_delayed(name, weight, weightUp, weightDown, shift)

@lru_cache
def weight(self, modifier=None):
"""Current event weight vector
Expand Down Expand Up @@ -391,6 +393,12 @@ def partial_weight(self, include=[], exclude=[], modifier=None):
The weight vector, corresponding to only the effect of the
corrections specified.
"""
return self._partial_weight(
include=tuple(include), exclude=tuple(exclude), modifier=modifier
)

@lru_cache
def _partial_weight(self, include, exclude, modifier=None):
if not self._storeIndividual:
raise ValueError(
"To be able to request weight exclusion, use storeIndividual=True when creating Weights object."
Expand Down Expand Up @@ -1204,6 +1212,7 @@ def add_multiple(self, selections, fill_value=False):
for name, selection in selections.items():
self.add(name, selection, fill_value)

@lru_cache
def require(self, **names):
"""Return a mask vector corresponding to specific requirements
Expand Down

0 comments on commit 3aeaad4

Please sign in to comment.