Commit 93cad7f
committed
data: Make local indexing O(result size), not O(domain)
Two hot-path costs in serial/local data[idx], surfaced by benchmarking:
* index_decomposition (used by every basic slice) built a full np.arange
over the axis and ran np.isin against each whole subdomain -- O(domain)
per slice. Subdomains are contiguous ranges, so bucket the selected
indices by bounds in O(result size); an np.isin fallback covers any
non-contiguous subdomain. A 1024-wide slice of a 2**20 axis drops from
~2.1 ms to ~20 us.
* convert_index ran index_glb_to_loc per element via np.vectorize for an
array index. For a single (non-distributed) subdomain the map is just a
negative-index wrap, so vectorize it; the distributed path (handled by
the redistribution engine) is unchanged. A 65536-point assignment drops
from ~62 ms to ~1.6 ms.
Both are behaviour-preserving (doctests, TestDecomposition, and the mode-4
slicing/advanced-indexing tests pass).1 parent 9cb66bc commit 93cad7f
2 files changed
Lines changed: 30 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
592 | 592 | | |
593 | 593 | | |
594 | 594 | | |
595 | | - | |
596 | | - | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
597 | 618 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
100 | 100 | | |
101 | 101 | | |
102 | 102 | | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
103 | 110 | | |
104 | 111 | | |
105 | 112 | | |
| |||
0 commit comments