|
| 1 | +""" |
| 2 | + RecursiveArrayToolsShorthandConstructors |
| 3 | +
|
| 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. |
| 7 | +
|
| 8 | +```julia |
| 9 | +using RecursiveArrayToolsShorthandConstructors |
| 10 | +``` |
| 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) |
| 16 | +""" |
| 17 | +module RecursiveArrayToolsShorthandConstructors |
| 18 | + |
| 19 | +using RecursiveArrayTools: VA, VectorOfArray, AP, ArrayPartition |
| 20 | + |
| 21 | +# VA[...] shorthand |
| 22 | +Base.getindex(::Type{VA}, xs...) = VectorOfArray(collect(xs)) |
| 23 | + |
| 24 | +# AP[...] shorthand |
| 25 | +Base.getindex(::Type{AP}, xs...) = ArrayPartition(xs...) |
| 26 | + |
| 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 |
0 commit comments