reduce_grouped's backed path rescans the group codes for every group

Aberta Para iniciantes
#113 0 comentários 0 reações 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
2/5
Tempo estimado
1-3 horas
Facilidade para iniciantes
88/100
Tipo de issue
Refatoração
Clareza
Claramente especificada
Status de atividade
Ativa
Stack de tecnologia
python
Domínio
data, performance

Direção de pesquisa

Comece em src/mantispy/_core/_reduce.py, na branch backed por volta da linha 178, e depois leia group_rows perto da linha 49. Execute tests/test_backed.py::test_aggregate_and_feature_select_match e adicione cobertura usando uma quantidade de grupos acima do ponto de crossover; considera-se concluído quando a redução backed mantém os resultados esperados e evita uma varredura completa de codes para cada grupo.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

Problem

src/mantispy/_core/_reduce.py:178, inside the backed branch's loop over groups:

for index in range(len(keys)):
    rows = np.flatnonzero((codes == index) & selected)

Two full-length passes over codes and selected per group, so O(n_groups x n_obs) in total. group_rows
(_reduce.py:49, in __all__, already used by tl/_design.py) does the same work once from one stable
ordering.

The cost depends entirely on the group count, and the crossover is around a few hundred groups:

rows groups per-group scan sorted once
1,000,000 141 (plates) 0.07 s 0.13 s
200,000 9,600 (wells) 0.76 s 0.03 s
1,000,000 50,000 (wells) 18.1 s 0.18 s

Grouping by plate is a wash, and the current form is marginally ahead. Grouping by well is the path
tl.aggregate takes on a cell-level object — tests/test_backed.py::test_aggregate_and_feature_select_match
calls exactly that — and there the scan adds 18 seconds of index arithmetic to a reduction that is already
paying one h5py read per group.

Proposed fix

  • Take the row indices from group_rows(codes, len(keys)) once before the loop, then restrict each
    group's rows with rows[selected[rows]]. Both give ascending indices within a group, so the reads and
    the statistic are unchanged.
  • Use it unconditionally rather than switching on the group count: the 0.06 s it gives up at plate counts
    is not worth a branch.
  • A test at a group count above the crossover, since the existing backed tests use two plates.

Found while reviewing #67. The in-memory branch below does not have this problem — it passes codes to the
kernel whole.

Linguagem predominante
Python
Estrelas
8
Forks
0
Merge médio
10h 48min
PRs com merge (30d)
37

Guia de contribuição

Abrir o guia de contribuição

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de scverse/mantispy

Todas as issues de scverse/mantispy

Issues semelhantes

Mais issues de Python

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.