reduce_grouped's backed path rescans the group codes for every group
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 withrows[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
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de scverse/mantispy
-
bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 88/100
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 88/100
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 84/100
-
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 84/100
Todas as issues de scverse/mantispy
Issues semelhantes
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 88/100
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 82/100
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
-
enhancement
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 74/100