tatami_test
Utilities for testing tatami libraries
Loading...
Searching...
No Matches
simulate_vector.hpp
Go to the documentation of this file.
1#ifndef TATAMI_TEST_SIMULATE_VECTOR_HPP
2#define TATAMI_TEST_SIMULATE_VECTOR_HPP
3
4#include <random>
5#include <vector>
6#include <cstdint>
7
13namespace tatami_test {
14
22 double lower = 0;
23
27 double upper = 100;
28
32 double density = 1;
33
37 uint64_t seed = 1234567890;
38};
39
49template<typename Type_>
50std::vector<Type_> simulate_vector(size_t length, const SimulateVectorOptions& options) {
51 std::vector<Type_> output(length);
52 std::mt19937_64 rng(options.seed);
53 std::uniform_real_distribution<> unif(options.lower, options.upper);
54
55 if (options.density == 1) {
56 for (auto& v : output) {
57 v = unif(rng);
58 }
59 } else {
60 std::uniform_real_distribution<> nonzero(0.0, 1.0);
61 for (auto& v : output) {
62 if (nonzero(rng) <= options.density) {
63 v = unif(rng);
64 }
65 }
66 }
67
68 return output;
69}
70
71}
72
73#endif
Utilities for testing tatami libraries.
Definition create_indexed_subset.hpp:15
std::vector< Type_ > simulate_vector(size_t length, const SimulateVectorOptions &options)
Definition simulate_vector.hpp:50
Options for simulate_vector().
Definition simulate_vector.hpp:18
double upper
Definition simulate_vector.hpp:27
double density
Definition simulate_vector.hpp:32
double lower
Definition simulate_vector.hpp:22
uint64_t seed
Definition simulate_vector.hpp:37