Skip to content

Commit 6adeb52

Browse files
committed
Excise SparseTransposeBlocks and SparseAdjointBlocks
1 parent 632405b commit 6adeb52

File tree

2 files changed

+12
-73
lines changed

2 files changed

+12
-73
lines changed

NDTensors/src/lib/BlockSparseArrays/src/blocksparsearrayinterface/blocksparsearrayinterface.jl

Lines changed: 2 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -186,79 +186,8 @@ end
186186
reverse_index(index) = reverse(index)
187187
reverse_index(index::CartesianIndex) = CartesianIndex(reverse(Tuple(index)))
188188

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)))
262191

263192
# Represents the array of arrays of a `SubArray`
264193
# wrapping a block spare array, i.e. `blocks(array)` where `a` is a `SubArray`.

NDTensors/src/lib/SparseArrayInterface/src/abstractsparsearray/wrappedabstractsparsearray.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,13 @@ const WrappedAbstractSparseArray{T,N,A} = WrappedArray{
77
const AnyAbstractSparseArray{T,N} = Union{
88
<:AbstractSparseArray{T,N},<:WrappedAbstractSparseArray{T,N}
99
}
10+
11+
function stored_indices(a::Adjoint)
12+
return Iterators.map(I -> CartesianIndex(reverse(I.I)), stored_indices(parent(a)))
13+
end
14+
stored_length(a::Adjoint) = stored_length(parent(a))
15+
16+
function stored_indices(a::Transpose)
17+
return Iterators.map(I -> CartesianIndex(reverse(I.I)), stored_indices(parent(a)))
18+
end
19+
stored_length(a::Transpose) = stored_length(parent(a))

0 commit comments

Comments
 (0)