Skip to content
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
4 changes: 4 additions & 0 deletions src/slarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
4 changes: 4 additions & 0 deletions test/slarrays.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using LabelledArrays, StaticArrays
using Test, InteractiveUtils
import ArrayInterface

@testset "Basic interface" begin
ABC = @SLVector (:a, :b, :c)
Expand Down Expand Up @@ -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))
Expand Down
Loading