Skip to content

Commit a8bc4cc

Browse files
authored
document rfn argument of sprand (#309)
* document rfn argument of sprand * Update src/sparsematrix.jl
1 parent 57cbb74 commit a8bc4cc

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/sparsematrix.jl

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1898,14 +1898,24 @@ function sparse_sortedlinearindices!(I::Vector{Ti}, V::Vector, m::Int, n::Int) w
18981898
end
18991899

19001900
"""
1901-
sprand([rng],[type],m,[n],p::AbstractFloat,[rfn])
1901+
sprand([rng],[T::Type],m,[n],p::AbstractFloat)
1902+
sprand([rng],m,[n],p::AbstractFloat,[rfn=rand])
19021903
19031904
Create a random length `m` sparse vector or `m` by `n` sparse matrix, in
19041905
which the probability of any element being nonzero is independently given by
1905-
`p` (and hence the mean density of nonzeros is also exactly `p`). Nonzero
1906-
values are sampled from the distribution specified by `rfn` and have the type `type`. The uniform
1907-
distribution is used in case `rfn` is not specified. The optional `rng`
1908-
argument specifies a random number generator, see [Random Numbers](@ref).
1906+
`p` (and hence the mean density of nonzeros is also exactly `p`).
1907+
The optional `rng` argument specifies a random number generator, see [Random Numbers](@ref).
1908+
The optional `T` argument specifies the element type, which defaults to `Float64`.
1909+
1910+
By default, nonzero values are sampled from a uniform distribution using
1911+
the [`rand`](@ref) function, i.e. by `rand(T)`, or `rand(rng, T)` if `rng`
1912+
is supplied; for the default `T=Float64`, this corresponds to nonzero values
1913+
sampled uniformly in `[0,1)`.
1914+
1915+
You can sample nonzero values from a different distribution by passing a
1916+
custom `rfn` function instead of `rand`. This should be a function `rfn(k)`
1917+
that returns an array of `k` random numbers sampled from the desired distribution;
1918+
alternatively, if `rng` is supplied, it should instead be a function `rfn(rng, k)`.
19091919
19101920
# Examples
19111921
```jldoctest; setup = :(using Random; Random.seed!(1234))

0 commit comments

Comments
 (0)