Skip to content

Preserve ShapedAxis components during vcat #301

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ComponentArrays"
uuid = "b0b7db55-cfe3-40fc-9ded-d10e2dbeff66"
authors = ["Jonnie Diegelman <[email protected]>"]
version = "0.15.26"
version = "0.15.27"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Expand Down
2 changes: 1 addition & 1 deletion src/axis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ reindex(i, offset) = i .+ offset
reindex(ax::FlatAxis, _) = ax
reindex(ax::Axis, offset) = Axis(map(x->reindex(x, offset), indexmap(ax)))
reindex(ax::ViewAxis, offset) = ViewAxis(viewindex(ax) .+ offset, indexmap(ax))
function reindex(ax::ViewAxis{OldInds,IdxMap,Ax}, offset) where {OldInds,IdxMap,Ax<:Shaped1DAxis}
function reindex(ax::ViewAxis{OldInds,IdxMap,Ax}, offset) where {OldInds,IdxMap,Ax<:Union{Shaped1DAxis,ShapedAxis}}
NewInds = viewindex(ax) .+ offset
return ViewAxis(NewInds, Ax())
end
Expand Down
13 changes: 13 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,19 @@ end
@test all(Xstack4_dcolon[:b, :, :] .== Xstack4_noca_dcolon[2:3, :, :])
end

# Test that we maintain higher-order components during vcat.
x = ComponentVector(a=rand(Float64, 2, 3, 4), b=rand(Float64, 4, 3, 2))
y = ComponentVector(c=rand(Float64, 3, 4, 2), d=rand(Float64, 3, 2, 4))
xy = vcat(x, y)
@test size(xy.a) == size(x.a)
@test size(xy.b) == size(x.b)
@test size(xy.c) == size(y.c)
@test size(xy.d) == size(y.d)
@test all(xy.a .≈ x.a)
@test all(xy.b .≈ x.b)
@test all(xy.c .≈ y.c)
@test all(xy.d .≈ y.d)

# Test fix https://github.com/Deltares/Ribasim/issues/2028
a = range(0.0, 1.0, length=0) |> collect
b = range(0.0, 1.0; length=2) |> collect
Expand Down
Loading