Skip to content

Commit 74ce20c

Browse files
committed
tidy
1 parent 2cbddd3 commit 74ce20c

File tree

2 files changed

+30
-19
lines changed

2 files changed

+30
-19
lines changed

.travis.yml

Lines changed: 0 additions & 10 deletions
This file was deleted.

README.md

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,14 @@ into one `AbstractArray`. Given several arrays with the same `eltype`,
77
or an array of such arrays, it returns a lazy `Stacked{T,N}` view of these:
88

99
```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×3 lazystack(::Vector{UnitRange{Int64}}) with eltype Int64:
12+
1 3 5
13+
2 4 6
14+
15+
julia> lazystack([pi^ℯ], [ℯ^pi])
16+
1×2 lazystack(::Tuple{Vector{Float64}, Vector{Float64}}) with eltype Float64:
17+
22.4592 23.1407
1218
```
1319

1420
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
2127

2228
### Ragged stack
2329

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:
2632

2733
```julia
28-
raggedstack([1:n for n in 1:10]) # upper triangular Matrix{Int}
29-
raggedstack(OffsetArray(fill(n,4), rand(-2:2)) for n in 1:10; fill=NaN)
34+
julia> raggedstack([10:10+n for n in 1:3])
35+
4×3 Matrix{Int64}:
36+
10 10 10
37+
11 11 11
38+
0 12 12
39+
0 0 13
40+
41+
julia> using OffsetArrays
42+
43+
julia> raggedstack(OffsetArray(fill(1.0n, 3), rand(-1:1)) for n in 1:10; fill=NaN)
44+
5×10 OffsetArray(::Matrix{Float64}, 0:4, 1:10) with eltype Float64 with indices 0:4×1:10:
45+
NaN 2.0 NaN 4.0 NaN 6.0 7.0 NaN 9.0 NaN
46+
1.0 2.0 3.0 4.0 5.0 6.0 7.0 NaN 9.0 10.0
47+
1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0
48+
1.0 NaN 3.0 NaN 5.0 NaN NaN 8.0 NaN 10.0
49+
NaN NaN NaN NaN NaN NaN NaN 8.0 NaN NaN
3050
```
3151

3252
### Other packages
3353

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).
3555

3656
Besides which, there are several other ways to achieve similar things:
3757

3858
* 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.
4060
* 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.
4161

4262
And a few more:
4363

4464
* 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.
4565
* 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.
4666
* [`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.
4768

4869
The lazy inverse:
4970

@@ -53,7 +74,7 @@ The lazy inverse:
5374

5475
* 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.
5576

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.
5778

5879
Eager:
5980

0 commit comments

Comments
 (0)