@@ -20,7 +20,7 @@ Base.show(io::IO, v::Value) =
20
20
print (io, string (" Value(" , v. val, " , tol=" , v. tol, " )" ))
21
21
22
22
# 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)
24
24
25
25
# Simple scalar indexing where we just set or return scalars
26
26
@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)
55
55
# Now we can reaxis without worrying about mismatched axes/indices
56
56
@inline _reaxis (axs:: Tuple{} , idxs:: Tuple{} ) = ()
57
57
# Scalars are dropped
58
- const ScalarIndex = @compat Union{Real, AbstractArray{<: Any , 0 }}
58
+ const ScalarIndex = Union{Real, AbstractArray{<: Any , 0 }}
59
59
@inline _reaxis (axs:: Tuple , idxs:: Tuple{ScalarIndex, Vararg{Any}} ) = _reaxis (tail (axs), tail (idxs))
60
60
# Colon passes straight through
61
61
@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}}
66
66
# Vectors simply create new axes with the same name; just subsetted by their value
67
67
@inline _new_axes {name} (ax:: Axis{name} , idx:: AbstractVector ) = (Axis {name} (ax. val[idx]),)
68
68
# 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} )
70
70
newaxes = Expr (:tuple )
71
71
for i= 1 : N
72
72
push! (newaxes. args, :($ (Axis{Symbol (name, " _" , i)})(indices (idx, $ i))))
73
73
end
74
74
newaxes
75
75
end
76
76
# 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} )
78
78
newaxes = Expr (:tuple )
79
79
idxnames = axisnames (idx)
80
80
for i= 1 : N
88
88
end
89
89
90
90
# 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... ))
106
93
107
94
# Setindex is so much simpler. Just assign it to the data:
108
95
@propagate_inbounds Base. setindex! (A:: AxisArray , v, idxs:: Idx... ) = (A. data[idxs... ] = v)
111
98
@propagate_inbounds Base. getindex (A:: AxisArray , idxs... ) = A[to_index (A,idxs... )... ]
112
99
@propagate_inbounds Base. setindex! (A:: AxisArray , v, idxs... ) = (A[to_index (A,idxs... )... ] = v)
113
100
# 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... )... )
134
104
135
105
# First is indexing by named axis. We simply sort the axes and re-dispatch.
136
106
# When indexing by named axis the shapes of omitted dimensions are preserved
0 commit comments