You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+30-9Lines changed: 30 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,8 +7,14 @@ into one `AbstractArray`. Given several arrays with the same `eltype`,
7
7
or an array of such arrays, it returns a lazy `Stacked{T,N}` view of these:
8
8
9
9
```julia
10
-
lazystack([zeros(2,2), ones(2,2)]) # isa Stacked{Float64, 3, <:Vector{<:Matrix}}
11
-
lazystack([1,2,3], 4:6) # isa Stacked{Int, 2, <:Tuple{<:Vector, <:UnitRange}}
10
+
julia>lazystack([1:2, 3:4, 5:6])
11
+
2×3lazystack(::Vector{UnitRange{Int64}}) with eltype Int64:
12
+
135
13
+
246
14
+
15
+
julia>lazystack([pi^ℯ], [ℯ^pi])
16
+
1×2lazystack(::Tuple{Vector{Float64}, Vector{Float64}}) with eltype Float64:
17
+
22.459223.1407
12
18
```
13
19
14
20
Before v0.1 this function used to be called `stack`, but that name is now exported by Base (from Julia 1.9).
@@ -21,29 +27,44 @@ This should make one big `CuArray`, since scalar indexing of individual slices w
21
27
22
28
### Ragged stack
23
29
24
-
There is also a version which does not demand that slices have equal `size` (or equal `ndims`),
25
-
which always returns a new `Array`. You can control the position of slices `using OffsetArrays`:
30
+
There is also a version which does not demand that slices have equal `size` (or equal `ndims`).
31
+
For now this is not lazy:
26
32
27
33
```julia
28
-
raggedstack([1:n for n in1:10]) # upper triangular Matrix{Int}
29
-
raggedstack(OffsetArray(fill(n,4), rand(-2:2)) for n in1:10; fill=NaN)
34
+
julia>raggedstack([10:10+n for n in1:3])
35
+
4×3 Matrix{Int64}:
36
+
101010
37
+
111111
38
+
01212
39
+
0013
40
+
41
+
julia>using OffsetArrays
42
+
43
+
julia>raggedstack(OffsetArray(fill(1.0n, 3), rand(-1:1)) for n in1:10; fill=NaN)
44
+
5×10OffsetArray(::Matrix{Float64}, 0:4, 1:10) with eltype Float64 with indices 0:4×1:10:
45
+
NaN2.0NaN4.0NaN6.07.0NaN9.0NaN
46
+
1.02.03.04.05.06.07.0NaN9.010.0
47
+
1.02.03.04.05.06.07.08.09.010.0
48
+
1.0NaN3.0NaN5.0NaNNaN8.0NaN10.0
49
+
NaNNaNNaNNaNNaNNaNNaN8.0NaNNaN
30
50
```
31
51
32
52
### Other packages
33
53
34
-
This one plays well with [OffsetArrays.jl](https://github.com/JuliaArrays/OffsetArrays.jl), and ChainRules-compatible AD such as [Zygote.jl](https://github.com/FluxML/Zygote.jl).
54
+
This one plays well with [OffsetArrays.jl](https://github.com/JuliaArrays/OffsetArrays.jl), and [ChainRules.jl](https://github.com/JuliaDiff/ChainRules.jl)-compatible AD such as [Zygote.jl](https://github.com/FluxML/Zygote.jl).
35
55
36
56
Besides which, there are several other ways to achieve similar things:
37
57
38
58
* For an array of arrays, you can also use [`JuliennedArrays.Align`](https://bramtayl.github.io/JuliennedArrays.jl/latest/#JuliennedArrays.Align). This requires (or enables) you to specify which dimensions of the output belong to the sub-arrays, instead of writing `PermutedDimsArray(stack(...), ...)`.
39
-
* There is also [`RecursiveArrayTools.VectorOfArray`](https://github.com/JuliaDiffEq/RecursiveArrayTools.jl#vectorofarray) which as its name hints only allows a one-dimensional container. Linear indexing retreives a slice, not an element, which is sometimes surprising.
59
+
* There is also [`RecursiveArrayTools.VectorOfArray`](https://github.com/JuliaDiffEq/RecursiveArrayTools.jl#vectorofarray) which as its name hints only allows a one-dimensional container. (And unlike the package name, nothing is recursive.) Linear indexing retreives a slice, not an element, which is sometimes surprising.
40
60
* For a tuple of arrays, [`LazyArrays.Hcat`](https://github.com/JuliaArrays/LazyArrays.jl#concatenation) is at present faster to index than `stack`, but doesn't allow arbitrary dimensions.
41
61
42
62
And a few more:
43
63
44
64
* When writing this I missed [`SplitApplyCombine.combinedimsview`](https://github.com/JuliaData/SplitApplyCombine.jl#combinedimsviewarray), which is very similar to `stack`, but doesn't handle tuples.
45
65
* Newer than this package is [StackViews.jl](https://github.com/JuliaArrays/StackViews.jl) handles both, with `StackView(A,B,dims=4) == StackView([A,B],4)` creating a 4th dimension; the container is always one-dimensional.
46
66
*[`Flux.stack`](https://fluxml.ai/Flux.jl/stable/utilities/#Flux.stack) similarly takes a dimension, but eagerly creates an `Array`.
67
+
* Finally, [CatViews.jl](https://github.com/ahwillia/CatViews.jl) offers a lazy `vcat`. But the package is old and I think not so fast.
47
68
48
69
The lazy inverse:
49
70
@@ -53,7 +74,7 @@ The lazy inverse:
53
74
54
75
* As does [`PackedVectorsOfVectors`](https://github.com/synchronoustechnologies/PackedVectorsOfVectors.jl), although only 1+1 dimensions. Also has an eager `pack` method which turns a vector of vectors into view of a single larger matrix.
55
76
56
-
*[`Base.eachslice`](https://docs.julialang.org/en/v1/base/arrays/#Base.eachslice) also views one large array as many slices. This is a generator, but [JuliaLang#32310](https://github.com/JuliaLang/julia/pull/32310)should upgrade it to a multi-dimensional container indexable container.
77
+
*[`Base.eachslice`](https://docs.julialang.org/en/v1/base/arrays/#Base.eachslice) also views one large array as many slices. This was a generator, but [JuliaLang#32310](https://github.com/JuliaLang/julia/pull/32310)upgrades it to a multi-dimensional indexable container, in Julia 1.9.
0 commit comments