@@ -74,28 +74,36 @@ storage(a::SparseArrayDOK) = a.storage
7474Base. size (a:: SparseArrayDOK ) = a. size
7575
7676storedvalues (a:: SparseArrayDOK ) = values (storage (a))
77- function isstored (a:: SparseArrayDOK{<:Any,N} , I:: Vararg{Int,N} ) where {N}
78- return @interface interface (a) isstored (a, I... )
77+ @inline function isstored (a:: SparseArrayDOK{<:Any,N} , I:: Vararg{Int,N} ) where {N}
78+ @boundscheck checkbounds (a, I... )
79+ return haskey (storage (a), CartesianIndex (I))
7980end
80- function eachstoredindex (a:: SparseArrayDOK )
81+ function eachstoredindex (:: IndexCartesian , a:: SparseArrayDOK )
8182 return keys (storage (a))
8283end
83- function getstoredindex (a:: SparseArrayDOK , I:: Int... )
84+ @inline function getstoredindex (a:: SparseArrayDOK{<:Any,N} , I:: Vararg{Int,N} ) where {N}
85+ @boundscheck checkbounds (a, I... )
8486 return storage (a)[CartesianIndex (I)]
8587end
86- function getunstoredindex (a:: SparseArrayDOK , I:: Int... )
88+ @inline function getunstoredindex (a:: SparseArrayDOK{<:Any,N} , I:: Vararg{Int,N} ) where {N}
89+ @boundscheck checkbounds (a, I... )
8790 return a. getunstored (a, I... )
8891end
89- function setstoredindex! (a:: SparseArrayDOK , value, I:: Int... )
90- # TODO : Have a way to disable this check, analogous to `checkbounds`,
91- # since this is already checked in `setindex!`.
92- isstored (a, I... ) || throw (IndexError (" key $(CartesianIndex (I)) not found" ))
92+ @inline function setstoredindex! (
93+ a:: SparseArrayDOK{<:Any,N} , value, I:: Vararg{Int,N}
94+ ) where {N}
95+ # `isstored` includes a boundscheck as well
96+ @boundscheck isstored (a, I... ) ||
97+ throw (IndexError (lazy " key $(CartesianIndex(I...)) not found" ))
9398 # TODO : If `iszero(value)`, unstore the index.
9499 storage (a)[CartesianIndex (I)] = value
95100 return a
96101end
97- function setunstoredindex! (a:: SparseArrayDOK , value, I:: Int... )
98- set! (storage (a), CartesianIndex (I), value)
102+ @inline function setunstoredindex! (
103+ a:: SparseArrayDOK{<:Any,N} , value, I:: Vararg{Int,N}
104+ ) where {N}
105+ @boundscheck checkbounds (a, I... )
106+ insert! (storage (a), CartesianIndex (I), value)
99107 return a
100108end
101109
0 commit comments