11using ArrayLayouts: LayoutArray
22using BlockArrays: blockisequal
3+ using Derive: @interface , interface
34using LinearAlgebra: Adjoint, Transpose
45using SparseArraysBase:
56 SparseArraysBase,
@@ -16,7 +17,7 @@ using SparseArraysBase:
1617function union_stored_blocked_cartesianindices (as:: Vararg{AbstractArray} )
1718 combined_axes = combine_axes (axes .(as)... )
1819 stored_blocked_cartesianindices_as = map (as) do a
19- return blocked_cartesianindices (axes (a), combined_axes, block_stored_indices (a))
20+ return blocked_cartesianindices (axes (a), combined_axes, block_eachstoredindex (a))
2021 end
2122 return ∪ (stored_blocked_cartesianindices_as... )
2223end
@@ -57,14 +58,14 @@ function reblock(
5758 return @view parent (a)[map (I -> Vector (I. blocks), parentindices (a))... ]
5859end
5960
61+ # TODO : Move to `blocksparsearrayinterface/map.jl`.
6062# TODO : Rewrite this so that it takes the blocking structure
6163# made by combining the blocking of the axes (i.e. the blocking that
6264# is used to determine `union_stored_blocked_cartesianindices(...)`).
6365# `reblock` is a partial solution to that, but a bit ad-hoc.
64- # TODO : Move to `blocksparsearrayinterface/map.jl`.
6566# # TODO : Make this an `@interface AbstractBlockSparseArrayInterface` function.
66- function sparse_map ! (
67- :: BlockSparseArrayStyle , f, a_dest:: AbstractArray , a_srcs:: Vararg{ AbstractArray}
67+ @interface :: AbstractBlockSparseArrayInterface function Base . map ! (
68+ f, a_dest:: AbstractArray , a_srcs:: AbstractArray...
6869)
6970 a_dest, a_srcs = reblock (a_dest), reblock .(a_srcs)
7071 for I in union_stored_blocked_cartesianindices (a_dest, a_srcs... )
@@ -89,12 +90,28 @@ function sparse_map!(
8990 return a_dest
9091end
9192
92- # TODO : Implement this.
93- # function SparseArraysBase.sparse_mapreduce(::BlockSparseArrayStyle, f, a_dest::AbstractArray, a_srcs::Vararg{AbstractArray})
94- # end
93+ # TODO : Move to `blocksparsearrayinterface/map.jl`.
94+ @interface :: AbstractBlockSparseArrayInterface function Base. mapreduce (
95+ f, op, as:: AbstractArray... ; kwargs...
96+ )
97+ # TODO : Define an `init` value based on the element type.
98+ return @interface interface (blocks .(as)... ) mapreduce (
99+ block -> mapreduce (f, op, block), op, blocks .(as)... ; kwargs...
100+ )
101+ end
102+
103+ # TODO : Move to `blocksparsearrayinterface/map.jl`.
104+ @interface :: AbstractBlockSparseArrayInterface function Base. iszero (a:: AbstractArray )
105+ return @interface interface (blocks (a)) iszero (blocks (a))
106+ end
107+
108+ # TODO : Move to `blocksparsearrayinterface/map.jl`.
109+ @interface :: AbstractBlockSparseArrayInterface function Base. isreal (a:: AbstractArray )
110+ return @interface interface (blocks (a)) isreal (blocks (a))
111+ end
95112
96- function Base. map! (f, a_dest:: AbstractArray , a_srcs:: Vararg{ AnyAbstractBlockSparseArray} )
97- sparse_map ! (f, a_dest, a_srcs... )
113+ function Base. map! (f, a_dest:: AbstractArray , a_srcs:: AnyAbstractBlockSparseArray... )
114+ @interface interface (a_srcs ... ) map ! (f, a_dest, a_srcs... )
98115 return a_dest
99116end
100117
@@ -103,50 +120,53 @@ function Base.map(f, as::Vararg{AnyAbstractBlockSparseArray})
103120end
104121
105122function Base. copy! (a_dest:: AbstractArray , a_src:: AnyAbstractBlockSparseArray )
123+ # TODO : Call `@interface`.
106124 sparse_copy! (a_dest, a_src)
107125 return a_dest
108126end
109127
110128function Base. copyto! (a_dest:: AbstractArray , a_src:: AnyAbstractBlockSparseArray )
129+ # TODO : Call `@interface`.
111130 sparse_copyto! (a_dest, a_src)
112131 return a_dest
113132end
114133
115134# Fix ambiguity error
116135function Base. copyto! (a_dest:: LayoutArray , a_src:: AnyAbstractBlockSparseArray )
136+ # TODO : Call `@interface`.
117137 sparse_copyto! (a_dest, a_src)
118138 return a_dest
119139end
120140
121141function Base. copyto! (
122142 a_dest:: AbstractMatrix , a_src:: Transpose{T,<:AbstractBlockSparseMatrix{T}}
123143) where {T}
144+ # TODO : Call `@interface`.
124145 sparse_copyto! (a_dest, a_src)
125146 return a_dest
126147end
127148
128149function Base. copyto! (
129150 a_dest:: AbstractMatrix , a_src:: Adjoint{T,<:AbstractBlockSparseMatrix{T}}
130151) where {T}
152+ # TODO : Call `@interface`.
131153 sparse_copyto! (a_dest, a_src)
132154 return a_dest
133155end
134156
135157function Base. permutedims! (a_dest, a_src:: AnyAbstractBlockSparseArray , perm)
136- sparse_permutedims! (a_dest, a_src, perm)
137- return a_dest
158+ return @interface interface (a_src) permutedims! (a_dest, a_src, perm)
138159end
139160
140- function Base. mapreduce (f, op, as:: Vararg{AnyAbstractBlockSparseArray} ; kwargs... )
141- return sparse_mapreduce (f, op, as... ; kwargs... )
161+ function Base. mapreduce (f, op, as:: AnyAbstractBlockSparseArray... ; kwargs... )
162+ @show interface (as... )
163+ return @interface interface (as... ) mapreduce (f, op, as... ; kwargs... )
142164end
143165
144- # TODO : Why isn't this calling `mapreduce` already?
145166function Base. iszero (a:: AnyAbstractBlockSparseArray )
146- return sparse_iszero ( blocks (a) )
167+ return @interface interface (a) iszero (a )
147168end
148169
149- # TODO : Why isn't this calling `mapreduce` already?
150170function Base. isreal (a:: AnyAbstractBlockSparseArray )
151- return sparse_isreal ( blocks (a) )
171+ return @interface interface (a) isreal (a )
152172end
0 commit comments