@@ -69,12 +69,14 @@ spzeros(dims::Dims) = spzeros(Float64, dims)
69
69
spzeros (:: Type{T} , dims:: Dims ) where {T} = SparseArrayDOK {T} (undef, dims)
70
70
71
71
@doc """
72
- sprand([rng], [T::Type], dims; density::Real=0.5, rfn ::Function=rand) -> A::SparseArrayDOK{T}
72
+ sprand([rng], [T::Type], dims; density::Real=0.5, rand_function ::Function=rand) -> A::SparseArrayDOK{T}
73
73
74
74
Create a random size `dims` sparse array in which the probability of any element being stored is independently given by `density`.
75
75
The optional `rng` argument specifies a random number generator, see also `Random`.
76
76
The optional `T` argument specifies the element type, which defaults to `Float64`.
77
- The optional `rfn` argument can be used to control the type of random elements.
77
+ The optional `rand_function` argument can be used to control the type of random elements, and should support
78
+ the signature `rand_function(rng, T, N)` to generate `N` entries of type `T`.
79
+
78
80
79
81
See also [`sprand!`](@ref).
80
82
""" sprand
@@ -93,22 +95,23 @@ function sprand(rng::AbstractRNG, ::Type{T}, dims::Dims; kwargs...) where {T}
93
95
end
94
96
95
97
@doc """
96
- sprand!([rng], A::AbstractArray; density::Real=0.5, rfn ::Function=rand) -> A
98
+ sprand!([rng], A::AbstractArray; density::Real=0.5, rand_function ::Function=rand) -> A
97
99
98
100
Overwrite part of an array with random entries, where the probability of overwriting is independently given by `density`.
99
101
The optional `rng` argument specifies a random number generator, see also `Random`.
100
- The optional `rfn` argument can be used to control the type of random elements.
102
+ The optional `rand_function` argument can be used to control the type of random elements, and should support
103
+ the signature `rand_function(rng, T, N)` to generate `N` entries of type `T`.
101
104
102
105
See also [`sprand`](@ref).
103
106
""" sprand!
104
107
105
108
sprand! (A:: AbstractArray ; kwargs... ) = sprand! (default_rng (), A; kwargs... )
106
109
function sprand! (
107
- rng:: AbstractRNG , A:: AbstractArray ; density:: Real = 0.5 , rfn :: Function = Random. rand
110
+ rng:: AbstractRNG , A:: AbstractArray ; density:: Real = 0.5 , rand_function :: Function = Random. rand
108
111
)
109
112
ArrayLayouts. zero! (A)
110
113
rand_inds = Random. randsubseq (rng, eachindex (A), density)
111
- rand_entries = rfn (rng, eltype (A), length (rand_inds))
114
+ rand_entries = rand_function (rng, eltype (A), length (rand_inds))
112
115
for (I, v) in zip (rand_inds, rand_entries)
113
116
A[I] = v
114
117
end
0 commit comments