@@ -37,6 +37,10 @@ This internal function determines the new set of axes that are constructed upon
37
37
indexing with I.
38
38
"""
39
39
reaxis (A:: AxisArray , I:: Idx... ) = _reaxis (make_axes_match (axes (A), I), I)
40
+ function reaxis (A:: AxisArray , I:: AbstractArray{Bool} )
41
+ vecI = vec (I)
42
+ _reaxis (make_axes_match (axes (A), (vecI,)), (vecI,))
43
+ end
40
44
# Ensure the number of axes matches the number of indexing dimensions
41
45
@inline make_axes_match (axs, idxs) = _make_axes_match ((), axs, Base. index_ndims (idxs... ))
42
46
# Move the axes into newaxes, until we run out of both simultaneously
@@ -95,6 +99,12 @@ using Base.AbstractCartesianIndex
95
99
# Setindex is so much simpler. Just assign it to the data:
96
100
@propagate_inbounds Base. setindex! (A:: AxisArray , v, idxs:: Idx... ) = (A. data[idxs... ] = v)
97
101
102
+ # Logical indexing
103
+ @propagate_inbounds function Base. getindex (A:: AxisArray , idx:: AbstractArray{Bool} )
104
+ AxisArray (A. data[idx], reaxis (A, idx))
105
+ end
106
+ @propagate_inbounds Base. setindex! (A:: AxisArray , v, idx:: AbstractArray{Bool} ) = (A. data[idx] = v)
107
+
98
108
# ## Fancier indexing capabilities provided only by AxisArrays ###
99
109
@propagate_inbounds Base. getindex (A:: AxisArray , idxs... ) = A[to_index (A,idxs... )... ]
100
110
@propagate_inbounds Base. setindex! (A:: AxisArray , v, idxs... ) = (A[to_index (A,idxs... )... ] = v)
0 commit comments