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