Skip to content

Commit b317741

Browse files
Split any/all optimizations into separate subpackage
RecursiveArrayToolsShorthandConstructors now only has the VA[...] and AP[...] constructor syntax. The any/all partition-level optimizations are in their own RecursiveArrayToolsArrayPartitionOptimizations subpackage since they are unrelated to shorthand constructors. Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com> Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent a629d9f commit b317741

File tree

3 files changed

+39
-21
lines changed

3 files changed

+39
-21
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name = "RecursiveArrayToolsArrayPartitionOptimizations"
2+
uuid = "ef3824f8-e6de-4318-b303-9eebc901ed99"
3+
version = "1.0.0"
4+
5+
[deps]
6+
RecursiveArrayTools = "731186ca-8d62-57ce-b412-fbd966d074cd"
7+
8+
[compat]
9+
RecursiveArrayTools = "3.48"
10+
julia = "1.10"
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"""
2+
RecursiveArrayToolsArrayPartitionOptimizations
3+
4+
Optimized `any`/`all` for `ArrayPartition` that short-circuit at the
5+
partition level instead of element-by-element. Separated into its own
6+
subpackage because the `any(f::Function, ::ArrayPartition)` method
7+
invalidates ~780 downstream compiled specializations of
8+
`any(f::Function, ::AbstractArray)`.
9+
10+
```julia
11+
using RecursiveArrayToolsArrayPartitionOptimizations
12+
```
13+
"""
14+
module RecursiveArrayToolsArrayPartitionOptimizations
15+
16+
using RecursiveArrayTools: ArrayPartition
17+
18+
Base.any(f, A::ArrayPartition) = any((any(f, x) for x in A.x))
19+
Base.any(f::Function, A::ArrayPartition) = any((any(f, x) for x in A.x))
20+
Base.any(A::ArrayPartition) = any(identity, A)
21+
Base.all(f, A::ArrayPartition) = all((all(f, x) for x in A.x))
22+
Base.all(f::Function, A::ArrayPartition) = all((all(f, x) for x in A.x))
23+
Base.all(A::ArrayPartition) = all(identity, A)
24+
25+
end
Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,19 @@
11
"""
22
RecursiveArrayToolsShorthandConstructors
33
4-
Opt-in subpackage providing shorthand syntax and optimized methods that cause
5-
method table invalidations. These are separated from RecursiveArrayTools to
6-
avoid invalidating compiled code for users who don't need them.
4+
Shorthand `VA[a, b, c]` and `AP[a, b, c]` constructor syntax. Separated
5+
into its own subpackage because `getindex(::Type{VA}, xs...)` invalidates
6+
`getindex(::Type{T}, vals...)` from Base.
77
88
```julia
99
using RecursiveArrayToolsShorthandConstructors
1010
```
11-
12-
This enables:
13-
- `VA[a, b, c]` shorthand for `VectorOfArray([a, b, c])`
14-
- `AP[a, b, c]` shorthand for `ArrayPartition(a, b, c)`
15-
- Optimized `any`/`all` for `ArrayPartition` (partition-level short-circuiting)
1611
"""
1712
module RecursiveArrayToolsShorthandConstructors
1813

1914
using RecursiveArrayTools: VA, VectorOfArray, AP, ArrayPartition
2015

21-
# VA[...] shorthand
2216
Base.getindex(::Type{VA}, xs...) = VectorOfArray(collect(xs))
23-
24-
# AP[...] shorthand
2517
Base.getindex(::Type{AP}, xs...) = ArrayPartition(xs...)
2618

27-
# Optimized any/all for ArrayPartition — applies f partition-by-partition
28-
# for faster short-circuiting instead of element-by-element.
29-
Base.any(f, A::ArrayPartition) = any((any(f, x) for x in A.x))
30-
Base.any(f::Function, A::ArrayPartition) = any((any(f, x) for x in A.x))
31-
Base.any(A::ArrayPartition) = any(identity, A)
32-
Base.all(f, A::ArrayPartition) = all((all(f, x) for x in A.x))
33-
Base.all(f::Function, A::ArrayPartition) = all((all(f, x) for x in A.x))
34-
Base.all(A::ArrayPartition) = all(identity, A)
35-
36-
end # module
19+
end

0 commit comments

Comments
 (0)