Skip to content

Commit 66af122

Browse files
Add RecursiveArrayToolsArrayPartitionAnyAll subpackage
Benchmarking shows the partition-by-partition any/all IS ~1.5-1.8x faster than the AbstractArray default for full scans, because ArrayPartition's generic element iteration has per-element partition lookup overhead. Kept as a separate lib/ subpackage (not a submodule) because submodules are loaded at package load time and would still cause invalidations. Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com> Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent d39cd6e commit 66af122

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name = "RecursiveArrayToolsArrayPartitionAnyAll"
2+
uuid = "172d604e-c495-4f00-97bf-d70957099afa"
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+
RecursiveArrayToolsArrayPartitionAnyAll
3+
4+
Optimized `any`/`all` for `ArrayPartition` that iterates partition-by-partition
5+
instead of using the generic `AbstractArray` element iteration. This gives
6+
~1.5-1.8x speedup on full scans because it avoids per-element partition lookup
7+
overhead. Separated into its own subpackage because `any(f::Function, ::ArrayPartition)`
8+
invalidates ~780 specializations of `any(f::Function, ::AbstractArray)`.
9+
10+
```julia
11+
using RecursiveArrayToolsArrayPartitionAnyAll
12+
```
13+
"""
14+
module RecursiveArrayToolsArrayPartitionAnyAll
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

0 commit comments

Comments
 (0)