diff --git a/README.md b/README.md index b7dfe19..62e8f66 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/src/RandomBooleanMatrices.jl b/src/RandomBooleanMatrices.jl index 64e13d1..85fbf7c 100644 --- a/src/RandomBooleanMatrices.jl +++ b/src/RandomBooleanMatrices.jl @@ -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 @@ -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 diff --git a/test/runtests.jl b/test/runtests.jl index cec40d5..ea7c235 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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)