From d7185036578832e890ce6136fd6e4c22e42f54ad Mon Sep 17 00:00:00 2001 From: Pieter Ghysels Date: Tue, 28 May 2024 17:04:43 -0700 Subject: [PATCH] Add randombinary --- src/HSS/HSSMatrix.compress_stable.hpp | 5 +---- src/dense/DenseMatrix.cpp | 11 +++++++++++ src/dense/DenseMatrix.hpp | 6 ++++++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/HSS/HSSMatrix.compress_stable.hpp b/src/HSS/HSSMatrix.compress_stable.hpp index f8865773..fd927b84 100644 --- a/src/HSS/HSSMatrix.compress_stable.hpp +++ b/src/HSS/HSSMatrix.compress_stable.hpp @@ -94,16 +94,13 @@ namespace strumpack { << "# Total nnz in each row: " << total_nnz << std::endl; } else if (opts.compression_sketch() == CompressionSketch::SRHT) { - std::unique_ptr> rgen; - rgen = random::make_random_generator - (opts.random_engine(), opts.random_distribution()); auto d = opts.d0(); auto dd = opts.dd(); auto n = this->cols(); auto m = this->rows(); DenseM_t Br, Cr, Sr, Rr, Bc, Cc, Sc, Rc; DenseM_t pvrc(1, n+m); - pvrc.randombinary(*rgen); // Generate the pvrc matrix + pvrc.randombinary(); // Generate the pvrc matrix int min_mn = std::min(m, n); d = std::min(d, min_mn); dd = std::min(opts.dd(), opts.max_rank()-d); diff --git a/src/dense/DenseMatrix.cpp b/src/dense/DenseMatrix.cpp index 59281ff4..5515847c 100644 --- a/src/dense/DenseMatrix.cpp +++ b/src/dense/DenseMatrix.cpp @@ -180,6 +180,17 @@ namespace strumpack { STRUMPACK_FLOPS(rgen.flops_per_prng()*cols()*rows()); } + template void + DenseMatrix::randombinary() { + TIMER_TIME(TaskType::RANDOM_GENERATE, 1, t_gen); + std::random_device rd; + std::mt19937 gen(rd()); + std::uniform_int_distribution<> distrib(0, 1); + for (std::size_t j=0; j void DenseMatrix::random() { TIMER_TIME(TaskType::RANDOM_GENERATE, 1, t_gen); auto rgen = random::make_default_random_generator(); diff --git a/src/dense/DenseMatrix.hpp b/src/dense/DenseMatrix.hpp index 639b53e2..64867a65 100644 --- a/src/dense/DenseMatrix.hpp +++ b/src/dense/DenseMatrix.hpp @@ -354,6 +354,12 @@ namespace strumpack { void random(random::RandomGeneratorBase:: value_type>& rgen); + /** + * Fill the matrix with random 0, 1 entries, using the specified + * random number generator. + */ + void randombinary(); + /** * Fill matrix with a constant value *