|
186 | 186 | reverse_index(index) = reverse(index) |
187 | 187 | reverse_index(index::CartesianIndex) = CartesianIndex(reverse(Tuple(index))) |
188 | 188 |
|
189 | | -# Represents the array of arrays of a `Transpose` |
190 | | -# wrapping a block spare array, i.e. `blocks(array)` where `a` is a `Transpose`. |
191 | | -struct SparseTransposeBlocks{T,BlockType<:AbstractArray{T},Array<:Transpose{T}} <: |
192 | | - AbstractSparseMatrix{BlockType} |
193 | | - array::Array |
194 | | -end |
195 | | -function blocksparse_blocks(a::Transpose) |
196 | | - return SparseTransposeBlocks{eltype(a),blocktype(parent(a)),typeof(a)}(a) |
197 | | -end |
198 | | -function Base.size(a::SparseTransposeBlocks) |
199 | | - return reverse(size(blocks(parent(a.array)))) |
200 | | -end |
201 | | -function Base.getindex(a::SparseTransposeBlocks, index::Vararg{Int,2}) |
202 | | - return transpose(blocks(parent(a.array))[reverse(index)...]) |
203 | | -end |
204 | | -# TODO: This should be handled by generic `AbstractSparseArray` code. |
205 | | -function Base.getindex(a::SparseTransposeBlocks, index::CartesianIndex{2}) |
206 | | - return a[Tuple(index)...] |
207 | | -end |
208 | | -# TODO: Create a generic `parent_index` function to map an index |
209 | | -# a parent index. |
210 | | -function Base.isassigned(a::SparseTransposeBlocks, index::Vararg{Int,2}) |
211 | | - return isassigned(blocks(parent(a.array)), reverse(index)...) |
212 | | -end |
213 | | -function SparseArrayInterface.stored_indices(a::SparseTransposeBlocks) |
214 | | - return map(reverse_index, stored_indices(blocks(parent(a.array)))) |
215 | | -end |
216 | | -# TODO: Either make this the generic interface or define |
217 | | -# `SparseArrayInterface.sparse_storage`, which is used |
218 | | -# to defined this. |
219 | | -SparseArrayInterface.stored_length(a::SparseTransposeBlocks) = length(stored_indices(a)) |
220 | | -function SparseArrayInterface.sparse_storage(a::SparseTransposeBlocks) |
221 | | - return error("Not implemented") |
222 | | -end |
223 | | - |
224 | | -# Represents the array of arrays of a `Adjoint` |
225 | | -# wrapping a block spare array, i.e. `blocks(array)` where `a` is a `Adjoint`. |
226 | | -struct SparseAdjointBlocks{T,BlockType<:AbstractArray{T},Array<:Adjoint{T}} <: |
227 | | - AbstractSparseMatrix{BlockType} |
228 | | - array::Array |
229 | | -end |
230 | | -function blocksparse_blocks(a::Adjoint) |
231 | | - return SparseAdjointBlocks{eltype(a),blocktype(parent(a)),typeof(a)}(a) |
232 | | -end |
233 | | -function Base.size(a::SparseAdjointBlocks) |
234 | | - return reverse(size(blocks(parent(a.array)))) |
235 | | -end |
236 | | -# TODO: Create a generic `parent_index` function to map an index |
237 | | -# a parent index. |
238 | | -function Base.getindex(a::SparseAdjointBlocks, index::Vararg{Int,2}) |
239 | | - return blocks(parent(a.array))[reverse(index)...]' |
240 | | -end |
241 | | -# TODO: Create a generic `parent_index` function to map an index |
242 | | -# a parent index. |
243 | | -# TODO: This should be handled by generic `AbstractSparseArray` code. |
244 | | -function Base.getindex(a::SparseAdjointBlocks, index::CartesianIndex{2}) |
245 | | - return a[Tuple(index)...] |
246 | | -end |
247 | | -# TODO: Create a generic `parent_index` function to map an index |
248 | | -# a parent index. |
249 | | -function Base.isassigned(a::SparseAdjointBlocks, index::Vararg{Int,2}) |
250 | | - return isassigned(blocks(parent(a.array)), reverse(index)...) |
251 | | -end |
252 | | -function SparseArrayInterface.stored_indices(a::SparseAdjointBlocks) |
253 | | - return map(reverse_index, stored_indices(blocks(parent(a.array)))) |
254 | | -end |
255 | | -# TODO: Either make this the generic interface or define |
256 | | -# `SparseArrayInterface.sparse_storage`, which is used |
257 | | -# to defined this. |
258 | | -SparseArrayInterface.stored_length(a::SparseAdjointBlocks) = length(stored_indices(a)) |
259 | | -function SparseArrayInterface.sparse_storage(a::SparseAdjointBlocks) |
260 | | - return error("Not implemented") |
261 | | -end |
| 189 | +blocksparse_blocks(a::Transpose) = transpose(blocks(parent(a))) |
| 190 | +blocksparse_blocks(a::Adjoint) = adjoint(blocks(parent(a))) |
262 | 191 |
|
263 | 192 | # Represents the array of arrays of a `SubArray` |
264 | 193 | # wrapping a block spare array, i.e. `blocks(array)` where `a` is a `SubArray`. |
|
0 commit comments