Skip to content

Commit

Permalink
Add HasAxes trait
Browse files Browse the repository at this point in the history
The intended use of this trait is to facilitate extensions of the AxisArrays interface to other AbstractArrays.
  • Loading branch information
timholy committed Oct 5, 2016
1 parent 60d2a11 commit 8a181fe
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,11 @@ AxisArray(A::AbstractArray) = AxisArray(A, ()) # Disambiguation
AxisArray(A::AbstractArray, names::Symbol...) = AxisArray(A, map((name,ind)->Axis{name}(ind), names, indices(A)))
AxisArray(A::AbstractArray, vects::AbstractVector...) = AxisArray(A, ntuple(i->Axis{_defaultdimname(i)}(vects[i]), length(vects)))

# Traits
immutable HasAxes{B} end
HasAxes(A::AxisArray) = HasAxes{true}()
HasAxes(A::AbstractArray) = HasAxes{false}()

# Axis definitions
@doc """
axisdim(::AxisArray, ::Axis) -> Int
Expand Down
3 changes: 3 additions & 0 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ A = AxisArray([0]', :x, :y)
@test axisnames(@inferred(squeeze(A, Axis{:y}))) == (:x,)
@test axisnames(@inferred(squeeze(squeeze(A, Axis{:x}), Axis{:y}))) == ()

@test AxisArrays.HasAxes(A) == AxisArrays.HasAxes{true}()
@test AxisArrays.HasAxes([1]) == AxisArrays.HasAxes{false}()

# Test axisdim
@test_throws ArgumentError AxisArray(reshape(1:24, 2,3,4),
Axis{1}(.1:.1:.2),
Expand Down

0 comments on commit 8a181fe

Please sign in to comment.