@@ -3,7 +3,6 @@ using DerivableInterfaces: DerivableInterfaces, @derive, @interface, AbstractArr
33# This is to bring `ArrayLayouts.zero!` into the namespace
44# since it is considered part of the sparse array interface.
55using ArrayLayouts: zero!
6- using Random: Random, AbstractRNG, default_rng
76
87function eachstoredindex end
98function getstoredindex end
@@ -33,62 +32,6 @@ function densearray(a::AbstractArray)
3332 return Array (a)
3433end
3534
36- @doc """
37- spzeros([T::Type], dims) -> A::SparseArrayDOK{T}
38-
39- Create an empty size `dims` sparse array.
40- The optional `T` argument specifies the element type, which defaults to `Float64`.
41- """ spzeros
42-
43- spzeros (dims:: Dims ) = spzeros (Float64, dims)
44- spzeros (:: Type{T} , dims:: Dims ) where {T} = SparseArrayDOK {T} (undef, dims)
45-
46- @doc """
47- sprand([rng], [T::Type], dims; density::Real=0.5, rfn::Function=rand) -> A::SparseArrayDOK{T}
48-
49- Create a random size `dims` sparse array in which the probability of any element being stored is independently given by `density`.
50- The optional `rng` argument specifies a random number generator, see also `Random`.
51- The optional `T` argument specifies the element type, which defaults to `Float64`.
52- The optional `rfn` argument can be used to control the type of random elements.
53-
54- See also [`sprand!`](@ref).
55- """ sprand
56-
57- function sprand (:: Type{T} , dims:: Dims ; kwargs... ) where {T}
58- return sprand (default_rng (), T, dims; kwargs... )
59- end
60- sprand (dims:: Dims ; kwargs... ) = sprand (default_rng (), Float64, dims; kwargs... )
61- function sprand (rng:: AbstractRNG , dims:: Dims ; kwargs... )
62- return sprand (rng, Float64, dims; kwargs... )
63- end
64- function sprand (rng:: AbstractRNG , :: Type{T} , dims:: Dims ; kwargs... ) where {T}
65- A = SparseArrayDOK {T} (undef, dims)
66- sprand! (rng, A; kwargs... )
67- return A
68- end
69-
70- @doc """
71- sprand!([rng], A::AbstractArray; density::Real=0.5, rfn::Function=rand) -> A
72-
73- Overwrite part of an array with random entries, where the probability of overwriting is independently given by `density`.
74- The optional `rng` argument specifies a random number generator, see also `Random`.
75- The optional `rfn` argument can be used to control the type of random elements.
76-
77- See also [`sprand`](@ref).
78- """ sprand!
79-
80- sprand! (A:: AbstractArray ; kwargs... ) = sprand! (default_rng (), A; kwargs... )
81- function sprand! (
82- rng:: AbstractRNG , A:: AbstractArray ; density:: Real = 0.5 , rfn:: Function = Random. rand
83- )
84- ArrayLayouts. zero! (A)
85- rand_inds = Random. randsubseq (rng, eachindex (A), density)
86- rand_entries = rfn (rng, eltype (A), length (rand_inds))
87- for (I, v) in zip (rand_inds, rand_entries)
88- A[I] = v
89- end
90- end
91-
9235# Minimal interface for `SparseArrayInterface`.
9336# Fallbacks for dense/non-sparse arrays.
9437@interface :: AbstractArrayInterface isstored (a:: AbstractArray , I:: Int... ) = true
0 commit comments