Skip to content

Commit a55f7f6

Browse files
committed
change rfn to rand_function
1 parent 5ab189a commit a55f7f6

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/abstractsparsearray.jl

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,14 @@ spzeros(dims::Dims) = spzeros(Float64, dims)
6969
spzeros(::Type{T}, dims::Dims) where {T} = SparseArrayDOK{T}(undef, dims)
7070

7171
@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}
7373
7474
Create a random size `dims` sparse array in which the probability of any element being stored is independently given by `density`.
7575
The optional `rng` argument specifies a random number generator, see also `Random`.
7676
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+
7880
7981
See also [`sprand!`](@ref).
8082
""" sprand
@@ -93,22 +95,23 @@ function sprand(rng::AbstractRNG, ::Type{T}, dims::Dims; kwargs...) where {T}
9395
end
9496

9597
@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
9799
98100
Overwrite part of an array with random entries, where the probability of overwriting is independently given by `density`.
99101
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`.
101104
102105
See also [`sprand`](@ref).
103106
""" sprand!
104107

105108
sprand!(A::AbstractArray; kwargs...) = sprand!(default_rng(), A; kwargs...)
106109
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
108111
)
109112
ArrayLayouts.zero!(A)
110113
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))
112115
for (I, v) in zip(rand_inds, rand_entries)
113116
A[I] = v
114117
end

0 commit comments

Comments
 (0)