Skip to content

Commit 8492444

Browse files
Merge pull request #301 from dingraha/vcat_shaped_axis
Preserve `ShapedAxis` components during `vcat`
2 parents de251fa + 90c1720 commit 8492444

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ComponentArrays"
22
uuid = "b0b7db55-cfe3-40fc-9ded-d10e2dbeff66"
33
authors = ["Jonnie Diegelman <[email protected]>"]
4-
version = "0.15.26"
4+
version = "0.15.27"
55

66
[deps]
77
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"

src/axis.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ reindex(i, offset) = i .+ offset
163163
reindex(ax::FlatAxis, _) = ax
164164
reindex(ax::Axis, offset) = Axis(map(x->reindex(x, offset), indexmap(ax)))
165165
reindex(ax::ViewAxis, offset) = ViewAxis(viewindex(ax) .+ offset, indexmap(ax))
166-
function reindex(ax::ViewAxis{OldInds,IdxMap,Ax}, offset) where {OldInds,IdxMap,Ax<:Shaped1DAxis}
166+
function reindex(ax::ViewAxis{OldInds,IdxMap,Ax}, offset) where {OldInds,IdxMap,Ax<:Union{Shaped1DAxis,ShapedAxis}}
167167
NewInds = viewindex(ax) .+ offset
168168
return ViewAxis(NewInds, Ax())
169169
end

test/runtests.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -857,6 +857,19 @@ end
857857
@test all(Xstack4_dcolon[:b, :, :] .== Xstack4_noca_dcolon[2:3, :, :])
858858
end
859859

860+
# Test that we maintain higher-order components during vcat.
861+
x = ComponentVector(a=rand(Float64, 2, 3, 4), b=rand(Float64, 4, 3, 2))
862+
y = ComponentVector(c=rand(Float64, 3, 4, 2), d=rand(Float64, 3, 2, 4))
863+
xy = vcat(x, y)
864+
@test size(xy.a) == size(x.a)
865+
@test size(xy.b) == size(x.b)
866+
@test size(xy.c) == size(y.c)
867+
@test size(xy.d) == size(y.d)
868+
@test all(xy.a .≈ x.a)
869+
@test all(xy.b .≈ x.b)
870+
@test all(xy.c .≈ y.c)
871+
@test all(xy.d .≈ y.d)
872+
860873
# Test fix https://github.com/Deltares/Ribasim/issues/2028
861874
a = range(0.0, 1.0, length=0) |> collect
862875
b = range(0.0, 1.0; length=2) |> collect

0 commit comments

Comments
 (0)