@@ -20,7 +20,7 @@ Base.show(io::IO, v::Value) =
2020 print (io, string (" Value(" , v. val, " , tol=" , v. tol, " )" ))
2121
2222# Defer IndexStyle to the wrapped array
23- @compat Base. IndexStyle {T,N,D,Ax} (:: Type{AxisArray{T,N,D,Ax}} ) = IndexStyle (D)
23+ Base. IndexStyle {T,N,D,Ax} (:: Type{AxisArray{T,N,D,Ax}} ) = IndexStyle (D)
2424
2525# Simple scalar indexing where we just set or return scalars
2626@propagate_inbounds Base. getindex (A:: AxisArray , idxs:: Int... ) = A. data[idxs... ]
@@ -55,7 +55,7 @@ reaxis(A::AxisArray, I::Idx...) = _reaxis(make_axes_match(axes(A), I), I)
5555# Now we can reaxis without worrying about mismatched axes/indices
5656@inline _reaxis (axs:: Tuple{} , idxs:: Tuple{} ) = ()
5757# Scalars are dropped
58- const ScalarIndex = @compat Union{Real, AbstractArray{<: Any , 0 }}
58+ const ScalarIndex = Union{Real, AbstractArray{<: Any , 0 }}
5959@inline _reaxis (axs:: Tuple , idxs:: Tuple{ScalarIndex, Vararg{Any}} ) = _reaxis (tail (axs), tail (idxs))
6060# Colon passes straight through
6161@inline _reaxis (axs:: Tuple , idxs:: Tuple{Colon, Vararg{Any}} ) = (axs[1 ], _reaxis (tail (axs), tail (idxs))... )
@@ -66,15 +66,15 @@ const ScalarIndex = @compat Union{Real, AbstractArray{<:Any, 0}}
6666# Vectors simply create new axes with the same name; just subsetted by their value
6767@inline _new_axes {name} (ax:: Axis{name} , idx:: AbstractVector ) = (Axis {name} (ax. val[idx]),)
6868# Arrays create multiple axes with _N appended to the axis name containing their indices
69- @generated function _new_axes {name, N} (ax:: Axis{name} , idx: :@compat ( AbstractArray{<: Any ,N}) )
69+ @generated function _new_axes {name, N} (ax:: Axis{name} , idx:: AbstractArray{<:Any,N} )
7070 newaxes = Expr (:tuple )
7171 for i= 1 : N
7272 push! (newaxes. args, :($ (Axis{Symbol (name, " _" , i)})(indices (idx, $ i))))
7373 end
7474 newaxes
7575end
7676# And indexing with an AxisArray joins the name and overrides the values
77- @generated function _new_axes {name, N} (ax:: Axis{name} , idx: :@compat ( AxisArray{<: Any , N}) )
77+ @generated function _new_axes {name, N} (ax:: Axis{name} , idx:: AxisArray{<:Any, N} )
7878 newaxes = Expr (:tuple )
7979 idxnames = axisnames (idx)
8080 for i= 1 : N
8888end
8989
9090# To resolve ambiguities, we need several definitions
91- if VERSION >= v " 0.6.0-dev.672"
92- using Base. AbstractCartesianIndex
93- @propagate_inbounds Base. view (A:: AxisArray , idxs:: Idx... ) = AxisArray (view (A. data, idxs... ), reaxis (A, idxs... ))
94- else
95- @propagate_inbounds function Base. view {T,N} (A:: AxisArray{T,N} , idxs:: Vararg{Idx,N} )
96- AxisArray (view (A. data, idxs... ), reaxis (A, idxs... ))
97- end
98- @propagate_inbounds function Base. view (A:: AxisArray , idx:: Idx )
99- AxisArray (view (A. data, idx), reaxis (A, idx))
100- end
101- @propagate_inbounds function Base. view {N} (A:: AxisArray , idxs:: Vararg{Idx,N} )
102- # this should eventually be deleted, see julia #14770
103- AxisArray (view (A. data, idxs... ), reaxis (A, idxs... ))
104- end
105- end
91+ using Base. AbstractCartesianIndex
92+ @propagate_inbounds Base. view (A:: AxisArray , idxs:: Idx... ) = AxisArray (view (A. data, idxs... ), reaxis (A, idxs... ))
10693
10794# Setindex is so much simpler. Just assign it to the data:
10895@propagate_inbounds Base. setindex! (A:: AxisArray , v, idxs:: Idx... ) = (A. data[idxs... ] = v)
11198@propagate_inbounds Base. getindex (A:: AxisArray , idxs... ) = A[to_index (A,idxs... )... ]
11299@propagate_inbounds Base. setindex! (A:: AxisArray , v, idxs... ) = (A[to_index (A,idxs... )... ] = v)
113100# Deal with lots of ambiguities here
114- if VERSION >= v " 0.6.0-dev.672"
115- @propagate_inbounds Base. view (A:: AxisArray , idxs:: ViewIndex... ) = view (A, to_index (A,idxs... )... )
116- @propagate_inbounds Base. view (A:: AxisArray , idxs:: Union{ViewIndex,AbstractCartesianIndex} ...) = view (A, to_index (A,Base. IteratorsMD. flatten (idxs)... )... )
117- @propagate_inbounds Base. view (A:: AxisArray , idxs... ) = view (A, to_index (A,idxs... )... )
118- else
119- for T in (:ViewIndex , :Any )
120- @eval begin
121- @propagate_inbounds function Base. view {T,N} (A:: AxisArray{T,N} , idxs:: Vararg{$T,N} )
122- view (A, to_index (A,idxs... )... )
123- end
124- @propagate_inbounds function Base. view (A:: AxisArray , idx:: $T )
125- view (A, to_index (A,idx)... )
126- end
127- @propagate_inbounds function Base. view {N} (A:: AxisArray , idsx:: Vararg{$T,N} )
128- # this should eventually be deleted, see julia #14770
129- view (A, to_index (A,idxs... )... )
130- end
131- end
132- end
133- end
101+ @propagate_inbounds Base. view (A:: AxisArray , idxs:: ViewIndex... ) = view (A, to_index (A,idxs... )... )
102+ @propagate_inbounds Base. view (A:: AxisArray , idxs:: Union{ViewIndex,AbstractCartesianIndex} ...) = view (A, to_index (A,Base. IteratorsMD. flatten (idxs)... )... )
103+ @propagate_inbounds Base. view (A:: AxisArray , idxs... ) = view (A, to_index (A,idxs... )... )
134104
135105# First is indexing by named axis. We simply sort the axes and re-dispatch.
136106# When indexing by named axis the shapes of omitted dimensions are preserved
0 commit comments