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 <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 = 1;
37
41 SeedType seed = 1234567890;
42};
43
55template<typename Type_, typename Length_>
56std::vector<Type_> simulate_vector(const Length_ length, const SimulateVectorOptions& options) {
57 auto output = sanisizer::create<std::vector<Type_> >(length);
58 RngEngine rng(options.seed);
59 std::uniform_real_distribution<> unif(options.lower, options.upper);
60
61 if (options.density == 1) {
62 for (auto& v : output) {
63 v = unif(rng);
64 }
65 } else {
66 std::uniform_real_distribution<> nonzero(0.0, 1.0);
67 for (auto& v : output) {
68 if (nonzero(rng) <= options.density) {
69 v = unif(rng);
70 }
71 }
72 }
73
74 return output;
75}
76
89template<typename Type_, typename Index_>
90std::vector<Type_> simulate_vector(const Index_ nrow, const Index_ ncol, const SimulateVectorOptions& options) {
91 return simulate_vector<Type_>(sanisizer::product<typename std::vector<Type_>::size_type>(nrow, ncol), options);
92}
93
94}
95
96#endif
Utilities for testing tatami libraries.
Definition create_indexed_subset.hpp:16
std::vector< Type_ > simulate_vector(const Length_ length, const SimulateVectorOptions &options)
Definition simulate_vector.hpp:56
std::mt19937_64 RngEngine
Definition utils.hpp:34
RngEngine::result_type SeedType
Definition utils.hpp:39
Options for simulate_vector().
Definition simulate_vector.hpp:22
double upper
Definition simulate_vector.hpp:31
double density
Definition simulate_vector.hpp:36
double lower
Definition simulate_vector.hpp:26
SeedType seed
Definition simulate_vector.hpp:41
Miscellaneous utilities.