Skip to content

Commit 1439262

Browse files
authored
Merge pull request #34 from mbauman/teh/slicing
Simplify slicing with a particular axis. Closes #33
2 parents 76a3a3d + c9ad669 commit 1439262

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed

src/core.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ Base.unsafe_getindex(A::Axis, i...) = Base.unsafe_getindex(A, i...)
6262
Base.eltype{_,T}(::Type{Axis{_,T}}) = eltype(T)
6363
Base.size(A::Axis) = size(A.val)
6464
Base.length(A::Axis) = length(A.val)
65+
@compat (A::Axis{name}){name}(i) = Axis{name}(i)
6566

6667
@doc """
6768
An AxisArray is an AbstractArray that wraps another AbstractArray and

test/indexing.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ B = AxisArray(reshape(1:15, 5,3), .1:.1:0.5, [:a, :b, :c])
5555
@test B[Axis{:row}(Interval(0.15, 0.3))] == B[2:3,:]
5656

5757
A = AxisArray(reshape(1:256, 4,4,4,4), Axis{:d1}(.1:.1:.4), Axis{:d2}(1//10:1//10:4//10), Axis{:d3}(["1","2","3","4"]), Axis{:d4}([:a, :b, :c, :d]))
58+
ax1 = axes(A)[1]
59+
@test A[Axis{:d1}(2)] == A[ax1(2)]
5860
@test A.data[1:2,:,:,:] == A[Axis{:d1}(Interval(.1,.2))] == A[Interval(.1,.2),:,:,:] == A[Interval(.1,.2),:,:,:,1] == A[Interval(.1,.2)]
5961
@test A.data[:,1:2,:,:] == A[Axis{:d2}(Interval(1//10,2//10))] == A[:,Interval(1//10,2//10),:,:] == A[:,Interval(1//10,2//10),:,:,1] == A[:,Interval(1//10,2//10)]
6062
@test A.data[:,:,1:2,:] == A[Axis{:d3}(["1","2"])] == A[:,:,["1","2"],:] == A[:,:,["1","2"],:,1] == A[:,:,["1","2"]]

0 commit comments

Comments
 (0)