Skip to content

Commit b034c72

Browse files
authored
Merge pull request #47 from JuliaArrays/teh/hasaxes
Add HasAxes trait
2 parents 4f70614 + 9b24a39 commit b034c72

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/core.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,12 @@ AxisArray(A::AbstractArray) = AxisArray(A, ()) # Disambiguation
203203
AxisArray(A::AbstractArray, names::Symbol...) = AxisArray(A, map((name,ind)->Axis{name}(ind), names, indices(A)))
204204
AxisArray(A::AbstractArray, vects::AbstractVector...) = AxisArray(A, ntuple(i->Axis{_defaultdimname(i)}(vects[i]), length(vects)))
205205

206+
# Traits
207+
immutable HasAxes{B} end
208+
HasAxes{A<:AxisArray}(::Type{A}) = HasAxes{true}()
209+
HasAxes{A<:AbstractArray}(::Type{A}) = HasAxes{false}()
210+
HasAxes(A::AbstractArray) = HasAxes(typeof(A))
211+
206212
# Axis definitions
207213
@doc """
208214
axisdim(::AxisArray, ::Axis) -> Int

test/core.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ A = AxisArray([0]', :x, :y)
118118
@test axisnames(@inferred(squeeze(A, Axis{:y}))) == (:x,)
119119
@test axisnames(@inferred(squeeze(squeeze(A, Axis{:x}), Axis{:y}))) == ()
120120

121+
@test AxisArrays.HasAxes(A) == AxisArrays.HasAxes{true}()
122+
@test AxisArrays.HasAxes([1]) == AxisArrays.HasAxes{false}()
123+
121124
# Test axisdim
122125
@test_throws ArgumentError AxisArray(reshape(1:24, 2,3,4),
123126
Axis{1}(.1:.1:.2),

0 commit comments

Comments
 (0)