@@ -56,104 +56,6 @@ BlockArrays.blocks(a::NonBlockedArray) = SingleBlockView(parent(a))
56
56
const NonBlockedVector{T,Array} = NonBlockedArray{T,1 ,Array}
57
57
NonBlockedVector (array:: AbstractVector ) = NonBlockedArray (array)
58
58
59
- # BlockIndices works around an issue that the indices of BlockSlice
60
- # are restricted to AbstractUnitRange{Int}.
61
- struct BlockIndices{B,T<: Integer ,I<: AbstractVector{T} } <: AbstractVector{T}
62
- blocks:: B
63
- indices:: I
64
- end
65
- for f in (:axes , :unsafe_indices , :axes1 , :first , :last , :size , :length , :unsafe_length )
66
- @eval Base.$ f (S:: BlockIndices ) = Base.$ f (S. indices)
67
- end
68
- Base. getindex (S:: BlockIndices , i:: Integer ) = getindex (S. indices, i)
69
- function Base. getindex (S:: BlockIndices , i:: BlockSlice{<:Block{1}} )
70
- # TODO : Check that `i.indices` is consistent with `S.indices`.
71
- # It seems like this isn't handling the case where `i` is a
72
- # subslice of a block correctly (i.e. it ignores `i.indices`).
73
- @assert length (S. indices[Block (i)]) == length (i. indices)
74
- return BlockSlice (S. blocks[Int (Block (i))], S. indices[Block (i)])
75
- end
76
-
77
- # This is used in slicing like:
78
- # a = BlockSparseArray{Float64}([2, 2, 2, 2], [2, 2, 2, 2])
79
- # I = BlockedVector([Block(4), Block(3), Block(2), Block(1)], [2, 2])
80
- # a[I, I]
81
- function Base. getindex (
82
- S:: BlockIndices{<:AbstractBlockVector{<:Block{1}}} , i:: BlockSlice{<:Block{1}}
83
- )
84
- # TODO : Check for conistency of indices.
85
- # Wrapping the indices in `NonBlockedVector` reinterprets the blocked indices
86
- # as a single block, since the result shouldn't be blocked.
87
- return NonBlockedVector (BlockIndices (S. blocks[Block (i)], S. indices[Block (i)]))
88
- end
89
- function Base. getindex (
90
- S:: BlockIndices{<:BlockedVector{<:Block{1},<:BlockRange{1}}} , i:: BlockSlice{<:Block{1}}
91
- )
92
- return i
93
- end
94
- # Views of `BlockIndices` are eager.
95
- # This fixes an issue in Julia 1.11 where reindexing defaults to using views.
96
- Base. view (S:: BlockIndices , i) = S[i]
97
-
98
- # Used in indexing such as:
99
- # ```julia
100
- # a = BlockSparseArray{Float64}([2, 2, 2, 2], [2, 2, 2, 2])
101
- # I = BlockedVector([Block(4), Block(3), Block(2), Block(1)], [2, 2])
102
- # b = @view a[I, I]
103
- # @view b[Block(1, 1)[1:2, 2:2]]
104
- # ```
105
- # This is similar to the definition:
106
- # @interface BlockSparseArrayInterface() to_indices(a, inds, I::Tuple{UnitRange{<:Integer},Vararg{Any}})
107
- function Base. getindex (
108
- a:: NonBlockedVector{<:Integer,<:BlockIndices} , I:: UnitRange{<:Integer}
109
- )
110
- ax = only (axes (parent (a). indices))
111
- brs = to_blockindices (ax, I)
112
- inds = blockedunitrange_getindices (ax, I)
113
- return NonBlockedVector (parent (a)[BlockSlice (brs, inds)])
114
- end
115
-
116
- function Base. getindex (S:: BlockIndices , i:: BlockSlice{<:BlockRange{1}} )
117
- # TODO : Check that `i.indices` is consistent with `S.indices`.
118
- # TODO : Turn this into a `blockedunitrange_getindices` definition.
119
- subblocks = S. blocks[Int .(i. block)]
120
- subindices = mortar (
121
- map (1 : length (i. block)) do I
122
- r = blocks (i. indices)[I]
123
- return S. indices[first (r)]: S. indices[last (r)]
124
- end ,
125
- )
126
- return BlockIndices (subblocks, subindices)
127
- end
128
-
129
- # Used when performing slices like:
130
- # @views a[[Block(2), Block(1)]][2:4, 2:4]
131
- function Base. getindex (S:: BlockIndices , i:: BlockSlice{<:BlockVector{<:BlockIndex{1}}} )
132
- subblocks = mortar (
133
- map (blocks (i. block)) do br
134
- return S. blocks[Int (Block (br))][only (br. indices)]
135
- end ,
136
- )
137
- subindices = mortar (
138
- map (blocks (i. block)) do br
139
- S. indices[br]
140
- end ,
141
- )
142
- return BlockIndices (subblocks, subindices)
143
- end
144
-
145
- # Similar to the definition of `BlockArrays.BlockSlices`:
146
- # ```julia
147
- # const BlockSlices = Union{Base.Slice,BlockSlice{<:BlockRange{1}}}
148
- # ```
149
- # but includes `BlockIndices`, where the blocks aren't contiguous.
150
- const BlockSliceCollection = Union{
151
- Base. Slice,BlockSlice{<: BlockRange{1} },BlockIndices{<: Vector{<:Block{1}} }
152
- }
153
- const SubBlockSliceCollection = BlockIndices{
154
- <: BlockVector{<:BlockIndex{1},<:Vector{<:BlockIndexRange{1}}}
155
- }
156
-
157
59
# TODO : This is type piracy. This is used in `reindex` when making
158
60
# views of blocks of sliced block arrays, for example:
159
61
# ```julia
@@ -326,10 +228,6 @@ function blockrange(axis::AbstractUnitRange, r::BlockSlice)
326
228
return blockrange (axis, r. block)
327
229
end
328
230
329
- function blockrange (a:: AbstractUnitRange , r:: BlockIndices )
330
- return blockrange (a, r. blocks)
331
- end
332
-
333
231
function blockrange (axis:: AbstractUnitRange , r:: Block{1} )
334
232
return r: r
335
233
end
@@ -397,10 +295,6 @@ function blockindices(
397
295
return Base. OneTo (length (axis[block]))
398
296
end
399
297
400
- function blockindices (a:: AbstractUnitRange , b:: Block , r:: BlockIndices )
401
- return blockindices (a, b, r. blocks)
402
- end
403
-
404
298
function blockindices (
405
299
a:: AbstractUnitRange ,
406
300
b:: Block ,
0 commit comments