Remove `segment_index` from the spike vector(s)

未关闭
#4,816 2 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 2 天内回复

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
32/100
Issue 类型
重构
描述清晰度
基本清楚
活跃度
活跃
技术栈
numpy, python
领域
data, performance

调研方向

Start with to_spike_vector(return_slices=True) in waveform_tools.py and review the linked usages in analyzer_extension_core.py and numpyextractors.py. Trace the repeated np.searchsorted calls across waveform_tools.py, basesorting.py, zarrextractors.py, sorting_tools.py, and remove_excess_spikes.py. Done means the segment index is removed, slices are used instead, and a compatibility path remains for saved sortings that contain the field.

由索引模型根据 Issue 内容生成。

描述

core discussion

I am reviewing #4809 (optimize SpikeRetriever and RAM usage for extensions) and I want to bring back the topic of simplifying the spike vector (time ordered and unit ordered) data model. A lot of the memory cost on @alejoe91's benchmark is the spike vector itself and of that 1/3 is the segment index and the segment index is unnecessary. This is an edge case (most recordings are not multi-segment) and the field is only a convenience, syntactic sugar. These are the main places where we use it:

  1. To find the boundaries of a segment (the sorting already caches them as segment_slices, see to_spike_vector(return_slices=True)):
    https://github.com/SpikeInterface/spikeinterface/blob/93c612f51cca09ecafe2c23a283132cf0ad57869/src/spikeinterface/core/waveform_tools.py#L357
    The same np.searchsorted is repeated three more times in waveform_tools.py and in basesorting.py, zarrextractors.py, sorting_tools.py and remove_excess_spikes.py.

  2. To mask the spikes of one unit in one segment (this could be a slice of the segment plus a mask on unit_index):
    https://github.com/SpikeInterface/spikeinterface/blob/93c612f51cca09ecafe2c23a283132cf0ad57869/src/spikeinterface/core/analyzer_extension_core.py#L131-L133

  3. As a sort key when building a sorting from peaks (the slices could be computed once at construction instead):
    https://github.com/SpikeInterface/spikeinterface/blob/93c612f51cca09ecafe2c23a283132cf0ad57869/src/spikeinterface/core/numpyextractors.py#L498

As a side effect this would remove the branching for the mono-segment case, like the special cases that #4809 adds to SpikeRetriever, PeakRetriever and _get_spike_vector_segment_slices.

The cost is a big refactor: using the slices wherever we rely on np.searchsorted (which I also think would be more efficient) and a compatibility path for the sortings that were saved with the field.

What do you think? Is there something I am missing?

主要语言
Python
星标
883
派生
291
平均合并
3 天 17 小时
30 天内合并 PR
40

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

SpikeInterface/spikeinterface 的其他 Issue

查看 SpikeInterface/spikeinterface 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。