Skip to content

Commit

Permalink
rename matrixgenerator --> matrixrandomizer
Browse files Browse the repository at this point in the history
  • Loading branch information
mkborregaard committed Jan 7, 2019
1 parent 4d2eeea commit 03af2c3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ randomize_matrix!(m)

# using a Matrix generator object
m = sprand(Bool, 1000, 1000, 0.1)
rmg = matrixgenerator(m)
rmg = matrixrandomizer(m)
m1 = rand(rmg) # creates a new random matrix
m2 = rand(rmg)

Expand Down
20 changes: 11 additions & 9 deletions src/RandomBooleanMatrices.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ end
show(io::IO, m::MatrixGenerator) = println(io, "Boolean MatrixGenerator with size $(size(m.m)) and $(nnz(m.m)) occurrences")

"""
matrixgenerator(m [,rng]; method = curveball)
matrixrandomizer(m [,rng]; method = curveball)
Create a matrix generator function that will return a random boolean matrix
every time it is called, maintaining row and column sums. Non-boolean input
Expand All @@ -39,21 +39,23 @@ matrix are interpreted as boolean, where values != 0 are `true`.
# Examples
```
m = rand(0:4, 5, 6)
rmg = matrixgenerator(m)
rmg = matrixrandomizer(m)
random1 = rmg()
random2 = rmg()
random1 = rand(rmg)
random2 = rand(rmg)
``
"""
matrixgenerator(m::AbstractMatrix, rng = Xoroshiro128Plus(); method::matrixrandomizations = curveball) =
MatrixGenerator{typeof(rng)}(dropzeros!(sparse(m)), method, rng)
matrixgenerator(m::SparseMatrixCSC{Bool, Int}, rng = Xoroshiro128Plus(); method::matrixrandomizations = curveball) =
MatrixGenerator{typeof(rng)}(dropzeros(m), method, rng)
matrixrandomizer(m, rng) = error("No matrixrandomizer defined for $(typeof(m))")
matrixrandomizer(m) = error("No matrixrandomizer defined for $(typeof(m))")
matrixrandomizer(m::AbstractMatrix, rng = Xoroshiro128Plus(); method::matrixrandomizations = curveball) =
MatrixGenerator{typeof(rng), SparseMatrixCSC{Bool, Int}}(dropzeros!(sparse(m)), method, rng)
matrixrandomizer(m::SparseMatrixCSC{Bool, Int}, rng = Xoroshiro128Plus(); method::matrixrandomizations = curveball) =
MatrixGenerator{typeof(rng), SparseMatrixCSC{Bool, Int}}(dropzeros(m), method, rng)

Random.rand(r::MatrixGenerator; method::matrixrandomizations = curveball) = copy(randomize_matrix!(r.m, r.rng, method = r.method))
Random.rand!(r::MatrixGenerator; method::matrixrandomizations = curveball) = randomize_matrix!(r.m, r.rng, method = r.method)

export randomize_matrix!, matrixgenerator
export randomize_matrix!, matrixrandomizer, matrixrandomizations
export curveball

end
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Random.seed!(1337)
m2 = rand(0:1, 6, 5)
rsm = sum(m2, dims = 1)
csm = sum(m2, dims = 2)
rmg = matrixgenerator(m2, method = curveball)
rmg = matrixrandomizer(m2, method = curveball)
m3 = rand(rmg)

@test rsm == sum(m3, dims = 1)
Expand Down

0 comments on commit 03af2c3

Please sign in to comment.