Skip to content

Commit 0b36ee6

Browse files
author
Chris Foster
committed
Access the values of an axis by name
1 parent 365496c commit 0b36ee6

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/core.jl

+9
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,15 @@ function axisdim(::Type{AxisArray{T,N,D,Ax}}, ::Type{<:Axis{name,S} where S}) wh
285285
idx
286286
end
287287

288+
# Allow access to the values of axes by name
289+
function Base.getproperty(A::AxisArray, name::Symbol)
290+
if name == :data || name == :axes
291+
getfield(A, name) # Real fields
292+
else
293+
getfield(A, :axes)[axisdim(A, Axis{name})].val
294+
end
295+
end
296+
288297
# Base definitions that aren't provided by AbstractArray
289298
@inline Base.size(A::AxisArray) = size(A.data)
290299
@inline Base.size(A::AxisArray, Ax::Axis) = size(A.data, axisdim(A, Ax))

0 commit comments

Comments
 (0)