From 91218558cb58a7d6849ad144a001d352abfbbf86 Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Sat, 1 Mar 2025 06:42:14 -0800 Subject: [PATCH 1/2] Fix CombinedAxis fallback reshape on AbstractArray Fixes https://discourse.julialang.org/t/no-method-error-reshape-when-solving-ode-with-componentarrays-jl/126342 --- src/componentarray.jl | 4 ++++ test/runtests.jl | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/componentarray.jl b/src/componentarray.jl index 4698ae5..c76be2a 100644 --- a/src/componentarray.jl +++ b/src/componentarray.jl @@ -255,6 +255,10 @@ function maybe_reshape(data, axs::AbstractAxis...) return reshape(data, shapes) end +function Base.reshape(parent::AbstractArray, dims::ComponentArrays.CombinedAxis...) + reshape(parent, getfield.(dims, :array_axis)) +end + # Recurse through nested ViewAxis types to find the last index last_index(x) = last(x) last_index(x::ViewAxis) = last_index(viewindex(x)) diff --git a/test/runtests.jl b/test/runtests.jl index f281f61..96653e8 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -306,7 +306,10 @@ end @test cmat3[:c, :b] == reshape(cmat3check[6:11, 2:5], 3, 2, 4) @test cmat3[:c, :c] == reshape(cmat3check[6:11, 6:11], 3, 2, 3, 2) - @test_broken reshape(a, axes(ca)...) isa Vector{Float64} + # https://discourse.julialang.org/t/no-method-error-reshape-when-solving-ode-with-componentarrays-jl/126342 + x = ComponentVector(x=1.0, y=0.0, z=0.0) + @test reshape(x, axes(x)...) isa ComponentVector + @test reshape(a, axes(ca)...) isa Vector{Float64} # Issue #265: Multi-symbol indexing with matrix components @test ca2.c[[:a, :b]].b isa AbstractMatrix From 961984fa16f79213614e749c91c11e565a995965 Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Sat, 1 Mar 2025 06:42:37 -0800 Subject: [PATCH 2/2] patch --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index cf5fed4..4607b5b 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "ComponentArrays" uuid = "b0b7db55-cfe3-40fc-9ded-d10e2dbeff66" authors = ["Jonnie Diegelman <47193959+jonniedie@users.noreply.github.com>"] -version = "0.15.24" +version = "0.15.25" [deps] Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"