Skip to content

Faster unit selection sorting.#4581

Open
samuelgarcia wants to merge 4 commits into
SpikeInterface:mainfrom
samuelgarcia:faster_unit_selection_sorting
Open

Faster unit selection sorting.#4581
samuelgarcia wants to merge 4 commits into
SpikeInterface:mainfrom
samuelgarcia:faster_unit_selection_sorting

Conversation

@samuelgarcia
Copy link
Copy Markdown
Member

@samuelgarcia samuelgarcia commented May 13, 2026

@grahamfindlay @alejoe91

Faster unit selection sorting.

This PR is also a base for discussion to avoid the proposal of get_unit_spiketrains() in #4502
I am not super in favor of adding new internal/external API for the sorting object.

Here this is a simple loop mimic the get_unit_spiketrains()

The speed is not so bad because only a few unit are selected.

phy_folder = Path('/home/samuel.garcia/Documents/data_sorting_graham/')

# no cache
t0 = time.perf_counter()
sorting = si.read_phy(phy_folder)
t1 = time.perf_counter()
print('read phy 342', t1 - t0)
sorting

# no cache
t0 = time.perf_counter()
subsorting = sorting.select_units(unit_ids=sorting.unit_ids[::10])
t1 = time.perf_counter()
print('select 34 units', t1 - t0)

# Trigger cache of spike vector in parent
# Trigger cache of spike vector subsorting
# Trigger lexsort in subsorting but no in parent
t0 = time.perf_counter()
spikes = subsorting.to_spike_vector()
subsorting.to_reordered_spike_vector()
t1 = time.perf_counter()
print('force cache', t1 - t0)

t0 = time.perf_counter()
for unit_id in subsorting.unit_ids:
    st = subsorting.get_unit_spike_train(unit_id=unit_id)
t1 = time.perf_counter()
print('get some spike train', t1 - t0)

give

read phy 342 11.468396085314453
select 30 units 0.030592769384384155
force cache 19.56562849227339
get spike train 0.0018834266811609268

This Pr depend on #4579

# check if order is preserved
pos = np.searchsorted(self._parent_sorting.unit_ids, self.unit_ids)
order_is_preserved = np.all(np.diff(pos)>0)
print('order_is_preserved', order_is_preserved)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant