tatami_test
Utilities for testing tatami libraries
Loading...
Searching...
No Matches
simulate_compressed_sparse.hpp
Go to the documentation of this file.
1#ifndef TATAMI_TEST_SIMULATE_COMPRESSED_SPARSE_HPP
2#define TATAMI_TEST_SIMULATE_COMPRESSED_SPARSE_HPP
3
4#include <random>
5#include <vector>
6#include <cstddef>
7
8#include "sanisizer/sanisizer.hpp"
9
10#include "utils.hpp"
11
17namespace tatami_test {
18
26 double lower = 0;
27
31 double upper = 100;
32
36 double density = 0.1;
37
41 SeedType seed = sanisizer::cap<SeedType>(1234567890);
42};
43
50template<typename Value_, typename Index_>
56 std::vector<Value_> data;
57
63 std::vector<Index_> index;
64
70 std::vector<std::size_t> indptr;
71};
72
85template<typename Value_, typename Index_>
87 RngEngine rng(options.seed);
88 std::uniform_real_distribution<> nonzero(0.0, 1.0);
89 std::uniform_real_distribution<> unif(options.lower, options.upper);
90
92 output.indptr.resize(sanisizer::sum<I<decltype(output.indptr.size())> >(primary, 1));
93 for (I<decltype(primary)> p = 0; p < primary; ++p) {
94 auto idx = output.indptr[p];
95 for (I<decltype(secondary)> s = 0; s < secondary; ++s) {
96 if (nonzero(rng) < options.density) {
97 output.data.push_back(unif(rng));
98 output.index.push_back(s);
99 ++idx;
100 }
101 }
102 output.indptr[p + 1] = idx;
103 }
104
105 return output;
106}
107
108}
109
110#endif
Utilities for testing tatami libraries.
Definition create_indexed_subset.hpp:16
std::mt19937_64 RngEngine
Definition utils.hpp:34
RngEngine::result_type SeedType
Definition utils.hpp:39
SimulateCompressedSparseResult< Value_, Index_ > simulate_compressed_sparse(const Index_ primary, const Index_ secondary, const SimulateCompressedSparseOptions &options)
Definition simulate_compressed_sparse.hpp:86
Options for simulate_compressed_sparse().
Definition simulate_compressed_sparse.hpp:22
double lower
Definition simulate_compressed_sparse.hpp:26
double upper
Definition simulate_compressed_sparse.hpp:31
SeedType seed
Definition simulate_compressed_sparse.hpp:41
double density
Definition simulate_compressed_sparse.hpp:36
Result of simulate_compressed_sparse().
Definition simulate_compressed_sparse.hpp:51
std::vector< std::size_t > indptr
Definition simulate_compressed_sparse.hpp:70
std::vector< Value_ > data
Definition simulate_compressed_sparse.hpp:56
std::vector< Index_ > index
Definition simulate_compressed_sparse.hpp:63
Miscellaneous utilities.