Skip to content

Commit

Permalink
ENH add parallelization to remaining sharp methods (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
joaopfonseca committed Feb 20, 2024
1 parent 4ad6f6f commit d9e931f
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions sharp/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,9 @@ def individual(self, sample, X=None, y=None, **kwargs):
else:
sample_size = X_.shape[0]

influences = []
for col_idx in range(len(self.feature_names_)):
cell_influence = self.measure_(
verbosity = kwargs["verbose"] if "verbose" in kwargs.keys() else self.verbose
influences = parallel_loop(
lambda col_idx: self.measure_(
row=sample,
col_idx=col_idx,
set_cols_idx=set_cols_idx,
Expand All @@ -141,8 +141,12 @@ def individual(self, sample, X=None, y=None, **kwargs):
sample_size=sample_size,
replace=self.replace,
rng=self._rng,
)
influences.append(cell_influence)
),
range(len(self.feature_names_)),
n_jobs=self.n_jobs,
progress_bar=verbosity,
)

return influences

def feature(self, feature, X=None, y=None, **kwargs):
Expand Down Expand Up @@ -191,7 +195,7 @@ def all(self, X=None, y=None, **kwargs):
X_, y_ = check_inputs(X, y)

influences = parallel_loop(
lambda sample_idx: self.individual(sample_idx, X_, **kwargs),
lambda sample_idx: self.individual(sample_idx, X_, verbose=False, **kwargs),
range(X_.shape[0]),
n_jobs=self.n_jobs,
progress_bar=self.verbose,
Expand Down

0 comments on commit d9e931f

Please sign in to comment.