Commit 2466954
Fix NamedArrayPartition Vector{Int} / UnitRange indexing (#583)
The invalidation-eliminating change in 05faa73 narrowed
`getindex(::NamedArrayPartition, ...)` from a catch-all `args...` form
to just `Int`. Anything else now falls through `AbstractArray`'s
generic indexing, which routes via `similar(x, T, dims)`.
That exposed a latent bug in the `similar` overloads: when
`dims != size(A)`, `similar(::ArrayPartition, T, dims)` intentionally
degrades to a plain `Vector` (a partition layout no longer fits the
requested shape). The `NamedArrayPartition` overloads then tried to wrap
that `Vector` via the inner constructor
`NamedArrayPartition{T, A<:ArrayPartition{T}, NT}(::A, ::NT)`, which
raised a MethodError. The catch-all `args...` getindex used to bypass
`similar` entirely, so the bug stayed hidden until 05faa73.
Make `similar(::NAP, dims)` and `similar(::NAP, T, dims)` mirror
`ArrayPartition`'s own degradation: wrap when the inner result is an
`ArrayPartition`, otherwise return the fallback array as-is. This
restores `x[1:2]` and `x[[1, 4]]` for partial slices, keeps `x[1:end]`
returning a `NamedArrayPartition` (the full-range slice still hits the
ArrayPartition path), and reintroduces no method that catches a wider
signature than necessary — `using RecursiveArrayTools` still produces
0 invalidation trees, verified with `SnoopCompile.invalidation_trees`.
Closes #583.
Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 45eb808 commit 2466954
2 files changed
Lines changed: 48 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | | - | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
38 | 43 | | |
39 | | - | |
40 | | - | |
41 | | - | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
42 | 47 | | |
43 | 48 | | |
44 | 49 | | |
| |||
48 | 53 | | |
49 | 54 | | |
50 | 55 | | |
51 | | - | |
52 | 56 | | |
53 | | - | |
54 | | - | |
55 | | - | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
56 | 60 | | |
57 | 61 | | |
58 | 62 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
0 commit comments