1010
1111const Symbols = Tuple{Symbol,Vararg{Symbol}}
1212
13- @doc """
13+ """
1414Type-stable axis-specific indexing and identification with a
1515parametric type.
1616
@@ -47,7 +47,7 @@ A[Axis{:row}(2)] # grabs the second row
4747A[Axis{2}(2:5)] # grabs the second through 5th columns
4848```
4949
50- """ ->
50+ """
5151immutable Axis{name,T}
5252 val:: T
5353end
@@ -70,7 +70,7 @@ Base.length(A::Axis) = length(A.val)
7070Base. convert {name,T} (:: Type{Axis{name,T}} , ax:: Axis{name,T} ) = ax
7171Base. convert {name,T} (:: Type{Axis{name,T}} , ax:: Axis{name} ) = Axis {name} (convert (T, ax. val))
7272
73- @doc """
73+ """
7474An AxisArray is an AbstractArray that wraps another AbstractArray and
7575adds axis names and values to each array dimension. AxisArrays can be indexed
7676by using the named axes as an alternative to positional indexing by
@@ -130,16 +130,10 @@ Two main types of axes supported by default include:
130130
131131User-defined axis types can be added along with custom indexing
132132behaviors. To add add a custom type as a Categorical or Dimensional
133- axis, add a trait using `AxisArrays.axistrait`. Here is the example of
134- adding a custom Dimensional axis:
135-
136- ```julia
137- AxisArrays.axistrait(v::MyCustomAxis) = AxisArrays.Dimensional
138- ```
133+ axis, add a trait using [`AxisArrays.axistrait`](@ref).
139134
140135For more advanced indexing, you can define custom methods for
141- `AxisArrays.axisindexes`.
142-
136+ [`AxisArrays.axisindexes`](@ref).
143137
144138### Examples
145139
@@ -154,7 +148,7 @@ A[Axis{:time}(ClosedInterval(.2,.4))] # restrict the AxisArray along the time ax
154148A[ClosedInterval(0.,.3), [:a, :c]] # select an interval and two columns
155149```
156150
157- """ ->
151+ """
158152immutable AxisArray{T,N,D,Ax} <: AbstractArray{T,N}
159153 data:: D # D <:AbstractArray, enforced in constructor to avoid dispatch bugs (https://github.com/JuliaLang/julia/issues/6383)
160154 axes:: Ax # Ax<:NTuple{N, Axis}, but with specialized Axis{...} types
@@ -229,13 +223,13 @@ HasAxes{A<:AbstractArray}(::Type{A}) = HasAxes{false}()
229223HasAxes (A:: AbstractArray ) = HasAxes (typeof (A))
230224
231225# Axis definitions
232- @doc """
226+ """
233227 axisdim(::AxisArray, ::Axis) -> Int
234228 axisdim(::AxisArray, ::Type{Axis}) -> Int
235229
236230Given an AxisArray and an Axis, return the integer dimension of
237231the Axis within the array.
238- """ ->
232+ """
239233axisdim (A:: AxisArray , ax:: Axis ) = axisdim (A, typeof (ax))
240234@generated function axisdim {T<:Axis} (A:: AxisArray , ax:: Type{T} )
241235 dim = axisdim (A, T)
@@ -460,14 +454,14 @@ function Base.summary(A::AxisArray)
460454end
461455
462456# Custom methods specific to AxisArrays
463- @doc """
457+ """
464458 axisnames(A::AxisArray) -> (Symbol...)
465459 axisnames(::Type{AxisArray{...}}) -> (Symbol...)
466460 axisnames(ax::Axis...) -> (Symbol...)
467461 axisnames(::Type{Axis{...}}...) -> (Symbol...)
468462
469463Returns the axis names of an AxisArray or list of Axises as a tuple of Symbols.
470- """ ->
464+ """
471465axisnames {T,N,D,Ax} (:: AxisArray{T,N,D,Ax} ) = _axisnames (Ax)
472466axisnames {T,N,D,Ax} (:: Type{AxisArray{T,N,D,Ax}} ) = _axisnames (Ax)
473467axisnames {Ax<:Tuple{Vararg{Axis}}} (:: Type{Ax} ) = _axisnames (Ax)
@@ -481,17 +475,17 @@ axisname{name,T}(::Type{Axis{name,T}}) = name
481475axisname {name } (:: Type{Axis{name }} ) = name
482476axisname (ax:: Axis ) = axisname (typeof (ax))
483477
484- @doc """
478+ """
485479 axisvalues(A::AxisArray) -> (AbstractVector...)
486480 axisvalues(ax::Axis...) -> (AbstractVector...)
487481
488482Returns the axis values of an AxisArray or list of Axises as a tuple of vectors.
489- """ ->
483+ """
490484axisvalues (A:: AxisArray ) = axisvalues (A. axes... )
491485axisvalues () = ()
492486axisvalues (ax:: Axis , axs:: Axis... ) = tuple (ax. val, axisvalues (axs... )... )
493487
494- @doc """
488+ """
495489 axes(A::AxisArray) -> (Axis...)
496490 axes(A::AxisArray, ax::Axis) -> Axis
497491 axes(A::AxisArray, dim::Int) -> Axis
@@ -503,7 +497,7 @@ than `axes(A)[1]`.
503497
504498For an AbstractArray without `Axis` information, `axes` returns the
505499default axes, i.e., those that would be produced by `AxisArray(A)`.
506- """ ->
500+ """
507501axes (A:: AxisArray ) = A. axes
508502axes (A:: AxisArray , dim:: Int ) = A. axes[dim]
509503axes (A:: AxisArray , ax:: Axis ) = axes (A, typeof (ax))
@@ -520,6 +514,23 @@ immutable Dimensional <: AxisTrait end
520514immutable Categorical <: AxisTrait end
521515immutable Unsupported <: AxisTrait end
522516
517+ """
518+ axistrait(ax::Axis) -> Type{<:AxisTrait}
519+
520+ Returns the indexing type of an `Axis`, any subtype of `AxisTrait`.
521+ The default is `Unsupported`, meaning there is no special indexing behaviour for this axis
522+ and indexes into this axis are passed directly to the underlying array.
523+
524+ Two main types of axes supported by default are `Categorical` and `Dimensional`; see
525+ [Indexing](@ref) for more information on these types.
526+
527+ User-defined axis types can be added along with custom indexing behaviors by defining new
528+ methods of this function. Here is the example of adding a custom Dimensional axis:
529+
530+ ```julia
531+ AxisArrays.axistrait(v::MyCustomAxis) = AxisArrays.Dimensional
532+ ```
533+ """
523534axistrait (:: Any ) = Unsupported
524535axistrait (ax:: Axis ) = axistrait (ax. val)
525536axistrait {T<:Union{Number, Dates.AbstractTime}} (:: AbstractVector{T} ) = Dimensional
0 commit comments