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
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "LabelledArrays"
uuid = "2ee39098-c373-598a-b85f-a56591580800"
authors = ["Chris Rackauckas <[email protected]>"]
version = "1.0.2"
version = "1.1.0"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand Down
11 changes: 10 additions & 1 deletion src/slarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ end
#####################################
## SLArray to named tuple
function Base.convert(::Type{NamedTuple}, x::SLArray{S,T,N,L,Syms}) where {S,T,N,L,Syms}
tup = NTuple{length(Syms),T}(x)
tup = NTuple{length(Syms),T}(x.__x)
NamedTuple{Syms,typeof(tup)}(tup)
end
Base.keys(x::SLArray{S,T,N,L,Syms}) where {S,T,N,L,Syms} = Syms
Expand All @@ -48,6 +48,10 @@ Base.pairs(x::SLArray{S,T,N,L,Syms}) where {S,T,N,L,Syms} =
# (label => getproperty(x, label) for label in Syms) # not type stable?
(Syms[i] => x[i] for i in 1:length(Syms))

function Base.iterate(x::SLArray,args...)
iterate(convert(NamedTuple,x),args...)
end

#####################################
# StaticArray Interface
#####################################
Expand Down Expand Up @@ -95,6 +99,11 @@ Base.@propagate_inbounds function Base.getindex(x::SLArray,s::AbstractArray{Symb
[getindex(x,si) for si in s]
end

function Base.vcat(x1::SLArray{S1,T,1,L1,Syms1},x2::SLArray{S2,T,1,L2,Syms2}) where {S1,S2,T,L1,L2,Syms1,Syms2}
__x = vcat(x1.__x,x2.__x)
SLArray{StaticArrays.size_tuple(Size(__x)),(Syms1...,Syms2...)}(__x)
end


"""
@SLArray Size Names
Expand Down
7 changes: 7 additions & 0 deletions test/slarrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,10 @@ end
@test_nowarn display(z)
@test z.a == [2, 4]
end

@testset "Concatenate and Iterate" begin
x = SLVector(a=1, b=2)
y = SLVector(c=1, d=2)
@test (x...,y...) == (1,2,1,2)
@test typeof(vcat(x,y)) <: SLArray
end