@@ -48,6 +48,10 @@ This internal function determines the new set of axes that are constructed upon
48
48
indexing with I.
49
49
"""
50
50
reaxis (A:: AxisArray , I:: Idx... ) = _reaxis (make_axes_match (axes (A), I), I)
51
+ function reaxis (A:: AxisArray , I:: AbstractArray{Bool} )
52
+ vecI = vec (I)
53
+ _reaxis (make_axes_match (axes (A), (vecI,)), (vecI,))
54
+ end
51
55
# Ensure the number of axes matches the number of indexing dimensions
52
56
@inline make_axes_match (axs, idxs) = _make_axes_match ((), axs, Base. index_ndims (idxs... ))
53
57
# Move the axes into newaxes, until we run out of both simultaneously
@@ -106,6 +110,12 @@ using Base.AbstractCartesianIndex
106
110
# Setindex is so much simpler. Just assign it to the data:
107
111
@propagate_inbounds Base. setindex! (A:: AxisArray , v, idxs:: Idx... ) = (A. data[idxs... ] = v)
108
112
113
+ # Logical indexing
114
+ @propagate_inbounds function Base. getindex (A:: AxisArray , idx:: AbstractArray{Bool} )
115
+ AxisArray (A. data[idx], reaxis (A, idx))
116
+ end
117
+ @propagate_inbounds Base. setindex! (A:: AxisArray , v, idx:: AbstractArray{Bool} ) = (A. data[idx] = v)
118
+
109
119
# ## Fancier indexing capabilities provided only by AxisArrays ###
110
120
@propagate_inbounds Base. getindex (A:: AxisArray , idxs... ) = A[to_index (A,idxs... )... ]
111
121
@propagate_inbounds Base. setindex! (A:: AxisArray , v, idxs... ) = (A[to_index (A,idxs... )... ] = v)
0 commit comments