Skip to content

Commit

Permalink
Add randombinary
Browse files Browse the repository at this point in the history
  • Loading branch information
pghysels committed May 29, 2024
1 parent a892cf9 commit d718503
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
5 changes: 1 addition & 4 deletions src/HSS/HSSMatrix.compress_stable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<random::RandomGeneratorBase<real_t>> rgen;
rgen = random::make_random_generator<real_t>
(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);
Expand Down
11 changes: 11 additions & 0 deletions src/dense/DenseMatrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,17 @@ namespace strumpack {
STRUMPACK_FLOPS(rgen.flops_per_prng()*cols()*rows());
}

template<typename scalar_t> void
DenseMatrix<scalar_t>::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<cols(); j++)
for (std::size_t i=0; i<rows(); i++)
operator()(i,j) = distrib(gen);
}

template<typename scalar_t> void DenseMatrix<scalar_t>::random() {
TIMER_TIME(TaskType::RANDOM_GENERATE, 1, t_gen);
auto rgen = random::make_default_random_generator<real_t>();
Expand Down
6 changes: 6 additions & 0 deletions src/dense/DenseMatrix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,12 @@ namespace strumpack {
void random(random::RandomGeneratorBase<typename RealType<scalar_t>::
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
*
Expand Down

0 comments on commit d718503

Please sign in to comment.