10
10
11
11
const Symbols = Tuple{Symbol,Vararg{Symbol}}
12
12
13
- @doc """
13
+ """
14
14
Type-stable axis-specific indexing and identification with a
15
15
parametric type.
16
16
@@ -47,7 +47,7 @@ A[Axis{:row}(2)] # grabs the second row
47
47
A[Axis{2}(2:5)] # grabs the second through 5th columns
48
48
```
49
49
50
- """ ->
50
+ """
51
51
immutable Axis{name,T}
52
52
val:: T
53
53
end
@@ -70,7 +70,7 @@ Base.length(A::Axis) = length(A.val)
70
70
Base. convert {name,T} (:: Type{Axis{name,T}} , ax:: Axis{name,T} ) = ax
71
71
Base. convert {name,T} (:: Type{Axis{name,T}} , ax:: Axis{name} ) = Axis {name} (convert (T, ax. val))
72
72
73
- @doc """
73
+ """
74
74
An AxisArray is an AbstractArray that wraps another AbstractArray and
75
75
adds axis names and values to each array dimension. AxisArrays can be indexed
76
76
by using the named axes as an alternative to positional indexing by
@@ -130,16 +130,10 @@ Two main types of axes supported by default include:
130
130
131
131
User-defined axis types can be added along with custom indexing
132
132
behaviors. 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).
139
134
140
135
For more advanced indexing, you can define custom methods for
141
- `AxisArrays.axisindexes`.
142
-
136
+ [`AxisArrays.axisindexes`](@ref).
143
137
144
138
### Examples
145
139
@@ -154,7 +148,7 @@ A[Axis{:time}(ClosedInterval(.2,.4))] # restrict the AxisArray along the time ax
154
148
A[ClosedInterval(0.,.3), [:a, :c]] # select an interval and two columns
155
149
```
156
150
157
- """ ->
151
+ """
158
152
immutable AxisArray{T,N,D,Ax} <: AbstractArray{T,N}
159
153
data:: D # D <:AbstractArray, enforced in constructor to avoid dispatch bugs (https://github.com/JuliaLang/julia/issues/6383)
160
154
axes:: Ax # Ax<:NTuple{N, Axis}, but with specialized Axis{...} types
@@ -229,13 +223,13 @@ HasAxes{A<:AbstractArray}(::Type{A}) = HasAxes{false}()
229
223
HasAxes (A:: AbstractArray ) = HasAxes (typeof (A))
230
224
231
225
# Axis definitions
232
- @doc """
226
+ """
233
227
axisdim(::AxisArray, ::Axis) -> Int
234
228
axisdim(::AxisArray, ::Type{Axis}) -> Int
235
229
236
230
Given an AxisArray and an Axis, return the integer dimension of
237
231
the Axis within the array.
238
- """ ->
232
+ """
239
233
axisdim (A:: AxisArray , ax:: Axis ) = axisdim (A, typeof (ax))
240
234
@generated function axisdim {T<:Axis} (A:: AxisArray , ax:: Type{T} )
241
235
dim = axisdim (A, T)
@@ -460,14 +454,14 @@ function Base.summary(A::AxisArray)
460
454
end
461
455
462
456
# Custom methods specific to AxisArrays
463
- @doc """
457
+ """
464
458
axisnames(A::AxisArray) -> (Symbol...)
465
459
axisnames(::Type{AxisArray{...}}) -> (Symbol...)
466
460
axisnames(ax::Axis...) -> (Symbol...)
467
461
axisnames(::Type{Axis{...}}...) -> (Symbol...)
468
462
469
463
Returns the axis names of an AxisArray or list of Axises as a tuple of Symbols.
470
- """ ->
464
+ """
471
465
axisnames {T,N,D,Ax} (:: AxisArray{T,N,D,Ax} ) = _axisnames (Ax)
472
466
axisnames {T,N,D,Ax} (:: Type{AxisArray{T,N,D,Ax}} ) = _axisnames (Ax)
473
467
axisnames {Ax<:Tuple{Vararg{Axis}}} (:: Type{Ax} ) = _axisnames (Ax)
@@ -481,17 +475,17 @@ axisname{name,T}(::Type{Axis{name,T}}) = name
481
475
axisname {name } (:: Type{Axis{name }} ) = name
482
476
axisname (ax:: Axis ) = axisname (typeof (ax))
483
477
484
- @doc """
478
+ """
485
479
axisvalues(A::AxisArray) -> (AbstractVector...)
486
480
axisvalues(ax::Axis...) -> (AbstractVector...)
487
481
488
482
Returns the axis values of an AxisArray or list of Axises as a tuple of vectors.
489
- """ ->
483
+ """
490
484
axisvalues (A:: AxisArray ) = axisvalues (A. axes... )
491
485
axisvalues () = ()
492
486
axisvalues (ax:: Axis , axs:: Axis... ) = tuple (ax. val, axisvalues (axs... )... )
493
487
494
- @doc """
488
+ """
495
489
axes(A::AxisArray) -> (Axis...)
496
490
axes(A::AxisArray, ax::Axis) -> Axis
497
491
axes(A::AxisArray, dim::Int) -> Axis
@@ -503,7 +497,7 @@ than `axes(A)[1]`.
503
497
504
498
For an AbstractArray without `Axis` information, `axes` returns the
505
499
default axes, i.e., those that would be produced by `AxisArray(A)`.
506
- """ ->
500
+ """
507
501
axes (A:: AxisArray ) = A. axes
508
502
axes (A:: AxisArray , dim:: Int ) = A. axes[dim]
509
503
axes (A:: AxisArray , ax:: Axis ) = axes (A, typeof (ax))
@@ -520,6 +514,23 @@ immutable Dimensional <: AxisTrait end
520
514
immutable Categorical <: AxisTrait end
521
515
immutable Unsupported <: AxisTrait end
522
516
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
+ """
523
534
axistrait (:: Any ) = Unsupported
524
535
axistrait (ax:: Axis ) = axistrait (ax. val)
525
536
axistrait {T<:Union{Number, Dates.AbstractTime}} (:: AbstractVector{T} ) = Dimensional
0 commit comments