From 963fe3398c641d67cafcebaed2e440275836b91f Mon Sep 17 00:00:00 2001 From: ChrisRackauckas-Claude Date: Mon, 31 Aug 2026 18:08:03 -0400 Subject: [PATCH] Preserve SLArray labels when restructuring Teach the public ArrayInterface.restructure API to rebuild immutable SLArray states with their original shape and labels. This keeps out-of-place stiff solver stages labelled after a flat linear solve. Co-Authored-By: Chris Rackauckas Co-Authored-By: OpenAI Codex Agent-Harness: Codex CLI 0.151.0 Agent-Model: gpt-5.6-sol Agent-Session: local session ID 01a0598f-11b9-72d1-91d9-b2fbb186557d --- src/slarray.jl | 4 ++++ test/slarrays.jl | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/slarray.jl b/src/slarray.jl index 5aad73f..b3acee2 100644 --- a/src/slarray.jl +++ b/src/slarray.jl @@ -189,6 +189,10 @@ function StaticArrays.similar_type( end end +function ArrayInterface.restructure(x::SLArray, y) + return StaticArrays.similar_type(typeof(x), eltype(y), Size(x))(Tuple(y)) +end + function Base.similar( ::Type{SLArray{S, T, N, L, Syms}}, ::Type{NewElType}, ::Size{NewSize} diff --git a/test/slarrays.jl b/test/slarrays.jl index 3c420aa..e1e6188 100644 --- a/test/slarrays.jl +++ b/test/slarrays.jl @@ -1,5 +1,6 @@ using LabelledArrays, StaticArrays using Test, InteractiveUtils +import ArrayInterface @testset "Basic interface" begin ABC = @SLVector (:a, :b, :c) @@ -37,6 +38,9 @@ using Test, InteractiveUtils @test @inferred(copy(b)) === ABC_int(Tuple(b)) + @test @inferred(ArrayInterface.restructure(b, SVector(1.0, 2.0, 3.0))) === + ABC_fl(1.0, 2.0, 3.0) + @test @inferred(broadcast(Float64, b)) === ABC_fl(Tuple(b)) @test @inferred(broadcast(+, b, b)) === ABC_int(Tuple(b.__x .+ b.__x)) @test @inferred(broadcast(+, b, 1.0)) === ABC_fl(Tuple(b.__x .+ 1.0))