@@ -23,11 +23,6 @@ const AnyAbstractSparseVecOrMat{T} = Union{
2323
2424Base. convert (T:: Type{<:AbstractSparseArray} , a:: AbstractArray ) = a isa T ? a : T (a)
2525
26- using FunctionImplementations: FunctionImplementations
27- function FunctionImplementations. ImplementationStyle (:: Type{<:AnyAbstractSparseArray} )
28- return SparseArrayImplementationStyle ()
29- end
30-
3126function Base. copy (a:: AnyAbstractSparseArray )
3227 return copyto! (similar (a), a)
3328end
6661using ArrayLayouts: ArrayLayouts
6762using LinearAlgebra: LinearAlgebra
6863
69- Base. getindex (a:: AnyAbstractSparseArray , I:: Any... ) = style (a)(getindex)(a, I... )
70- Base. getindex (a:: AnyAbstractSparseArray , I:: Int... ) = style (a)(getindex)(a, I... )
71- Base. setindex! (a:: AnyAbstractSparseArray , x, I:: Any... ) = style (a)(setindex!)(a, x, I... )
72- Base. setindex! (a:: AnyAbstractSparseArray , x, I:: Int... ) = style (a)(setindex!)(a, x, I... )
73- Base. copy! (dst:: AbstractArray , src:: AnyAbstractSparseArray ) = style (src)(copy!)(dst, src)
64+ # `copy!` and `real` are routed to sparse implementations that are not (yet)
65+ # defined, matching the prior behavior where these threw a `MethodError`.
66+ function copy!_sparse end
67+ function real_sparse end
68+
69+ Base. getindex (a:: AnyAbstractSparseArray , I:: Any... ) = getindex_sparse (a, I... )
70+ Base. getindex (a:: AnyAbstractSparseArray , I:: Int... ) = getindex_sparse (a, I... )
71+ Base. setindex! (a:: AnyAbstractSparseArray , x, I:: Any... ) = setindex!_sparse (a, x, I... )
72+ Base. setindex! (a:: AnyAbstractSparseArray , x, I:: Int... ) = setindex!_sparse (a, x, I... )
73+ Base. copy! (dst:: AbstractArray , src:: AnyAbstractSparseArray ) = copy!_sparse (dst, src)
7474function Base. copyto! (dst:: AbstractArray , src:: AnyAbstractSparseArray )
75- return style (src)( copyto!) (dst, src)
75+ return copyto!_sparse (dst, src)
7676end
77- Base. map (f, as:: AnyAbstractSparseArray... ) = style (as ... )(map) (f, as... )
77+ Base. map (f, as:: AnyAbstractSparseArray... ) = map_sparse (f, as... )
7878function Base. map! (f, dst:: AbstractArray , as:: AnyAbstractSparseArray... )
79- return style (as ... )( map!) (f, dst, as... )
79+ return map!_sparse (f, dst, as... )
8080end
8181function Base. mapreduce (f, op, as:: AnyAbstractSparseArray... ; kwargs... )
82- return style (as ... )(mapreduce) (f, op, as... ; kwargs... )
82+ return mapreduce_sparse (f, op, as... ; kwargs... )
8383end
8484function Base. reduce (f, as:: AnyAbstractSparseArray... ; kwargs... )
85- return style (as ... )(reduce) (f, as... ; kwargs... )
86- end
87- Base. all (f:: Function , a:: AnyAbstractSparseArray ) = style (a)(all) (f, a)
88- Base. all (a:: AnyAbstractSparseArray ) = style (a)(all) (a)
89- Base. iszero (a:: AnyAbstractSparseArray ) = style (a)(iszero) (a)
90- Base. isreal (a:: AnyAbstractSparseArray ) = style (a)(isreal) (a)
91- Base. real (a:: AnyAbstractSparseArray ) = style (a)(real) (a)
92- Base. fill! (a:: AnyAbstractSparseArray , x) = style (a)( fill!) (a, x)
93- FunctionImplementations . zero! (a:: AnyAbstractSparseArray ) = style (a)( zero!) (a)
94- Base. zero (a:: AnyAbstractSparseArray ) = style (a)(zero) (a)
85+ return reduce_sparse (f, as... ; kwargs... )
86+ end
87+ Base. all (f:: Function , a:: AnyAbstractSparseArray ) = all_sparse (f, a)
88+ Base. all (a:: AnyAbstractSparseArray ) = all_sparse (a)
89+ Base. iszero (a:: AnyAbstractSparseArray ) = iszero_sparse (a)
90+ Base. isreal (a:: AnyAbstractSparseArray ) = isreal_sparse (a)
91+ Base. real (a:: AnyAbstractSparseArray ) = real_sparse (a)
92+ Base. fill! (a:: AnyAbstractSparseArray , x) = fill!_sparse (a, x)
93+ zero! (a:: AnyAbstractSparseArray ) = zero!_sparse (a)
94+ Base. zero (a:: AnyAbstractSparseArray ) = zero_sparse (a)
9595function Base. permutedims! (dst, a:: AnyAbstractSparseArray , perm)
96- return style (a)( permutedims!) (dst, a, perm)
96+ return permutedims!_sparse (dst, a, perm)
9797end
9898function LinearAlgebra. mul! (
9999 dst:: AbstractMatrix , a1:: AnyAbstractSparseArray , a2:: AnyAbstractSparseArray ,
100100 α:: Number , β:: Number
101101 )
102- return style (a1, a2)(mul!)(dst, a1, a2, α, β)
102+ return mul!_sparse (dst, a1, a2, α, β)
103+ end
104+
105+ # Wire the sparse stored-entry implementations (defined in `indexing.jl`) to the
106+ # generic interface functions for sparse array types. Concrete sparse types and
107+ # wrappers may override the canonical methods directly.
108+ @inline getstoredindex (a:: AnyAbstractSparseArray , I:: Int... ) =
109+ getstoredindex_sparse (a, I... )
110+ @inline function getunstoredindex (a:: AnyAbstractSparseArray , I:: Int... )
111+ return getunstoredindex_sparse (a, I... )
112+ end
113+ @inline isstored (a:: AbstractSparseArray , i:: Int , I:: Int... ) = isstored_sparse (a, i, I... )
114+ @inline function setstoredindex! (a:: AnyAbstractSparseArray , v, I:: Int... )
115+ return setstoredindex!_sparse (a, v, I... )
116+ end
117+ @inline function setunstoredindex! (a:: AnyAbstractSparseArray , v, I:: Int... )
118+ return setunstoredindex!_sparse (a, v, I... )
119+ end
120+ storedvalues (a:: AnyAbstractSparseArray ) = storedvalues_sparse (a)
121+ storedpairs (a:: AnyAbstractSparseArray ) = storedpairs_sparse (a)
122+ function eachstoredindex (style:: IndexStyle , a:: AnyAbstractSparseArray , bs:: AbstractArray... )
123+ return eachstoredindex_sparse (style, a, bs... )
103124end
104125
105126function Base. Broadcast. BroadcastStyle (type:: Type{<:AnyAbstractSparseArray} )
109130using ArrayLayouts: ArrayLayouts
110131ArrayLayouts. MemoryLayout (type:: Type{<:AnyAbstractSparseArray} ) = SparseLayout ()
111132
112- using FunctionImplementations . Concatenate: concatenate
133+ using . Concatenate: concatenate
113134# We overload `Base._cat` instead of `Base.cat` since it
114135# is friendlier for invalidations/compile times, see:
115136# https://github.com/ITensor/SparseArraysBase.jl/issues/25
0 commit comments