Skip to content

Commit 202af0c

Browse files
committed
ControlSystems compat part 3: Axes. Closes #84
1 parent a1cb849 commit 202af0c

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/axis.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,16 @@ julia> ca.c.b
119119
struct Axis{IdxMap} <: AbstractAxis{IdxMap} end
120120
@inline Axis(IdxMap::NamedTuple) = Axis{IdxMap}()
121121
Axis(;kwargs...) = Axis((;kwargs...))
122+
function Axis(symbols::Union{AbstractVector{Symbol}, NTuple{N,Symbol}}) where N
123+
return Axis(NamedTuple(symbols .=> eachindex(symbols)))
124+
end
125+
Axis(symbols::Symbol...) = Axis(symbols)
122126

123127
Axis(ax::AbstractAxis) = ax
124128
Axis(ax::PartitionedAxis) = ax.ax
125129
Axis(ax::ViewAxis) = ax.ax
126130

131+
# Get rid of this
127132
Axis(::Number) = NullAxis()
128133
Axis(::NamedTuple{()}) = FlatAxis()
129134
Axis(x) = FlatAxis()

test/runtests.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ end
6868
@test_throws DimensionMismatch ComponentMatrix(rand(11,11,11), ax, ax)
6969
@test_throws ErrorException ComponentArray(v=[(a=1, b=2), (a=3, c=4)])
7070

71+
# Axis construction from symbols
72+
@test Axis([:a, :b, :c]) == Axis(a=1, b=2, c=3)
73+
@test Axis((:a, :b, :c)) == Axis(a=1, b=2, c=3)
74+
@test Axis(:a, :b, :c) == Axis(a=1, b=2, c=3)
75+
7176
# Issue #24
7277
@test ComponentVector(a=1, b=2f0) == ComponentVector{Float32}(a = 1.0, b = 2.0)
7378
@test ComponentVector(a=1, b=2+im) == ComponentVector{Complex{Int64}}(a = 1 + 0im, b = 2 + 1im)

0 commit comments

Comments
 (0)