Skip to content

Commit 22b9094

Browse files
committed
avoid copy when not necessary
1 parent df3d2df commit 22b9094

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

src/spikeinterface/curation/auto_merge.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,19 @@ def compute_merge_unit_groups(
195195
raise ValueError(f"preset must be one of {list(_compute_merge_presets.keys())}")
196196
steps = _compute_merge_presets[preset]
197197

198-
if force_copy:
198+
# check at least one extension is needed
199+
at_least_one_extension_to_compute = False
200+
for step in steps:
201+
assert step in _default_step_params, f"{step} is not a valid step"
202+
if step in _required_extensions:
203+
for ext in _required_extensions[step]:
204+
if sorting_analyzer.has_extension(ext):
205+
continue
206+
if not compute_needed_extensions:
207+
raise ValueError(f"{step} requires {ext} extension")
208+
at_least_one_extension_to_compute = True
209+
210+
if force_copy and at_least_one_extension_to_compute:
199211
# To avoid erasing the extensions of the user
200212
sorting_analyzer = sorting_analyzer.copy()
201213

@@ -205,14 +217,10 @@ def compute_merge_unit_groups(
205217

206218
for step in steps:
207219

208-
assert step in _default_step_params, f"{step} is not a valid step"
209-
210220
if step in _required_extensions:
211221
for ext in _required_extensions[step]:
212222
if sorting_analyzer.has_extension(ext):
213223
continue
214-
if not compute_needed_extensions:
215-
raise ValueError(f"{step} requires {ext} extension")
216224

217225
# special case for templates
218226
if ext == "templates" and not sorting_analyzer.has_extension("random_spikes"):

0 commit comments

Comments
 (0)