tatami_test
Utilities for testing tatami libraries
All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Pages
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 <cstdint>
7
13namespace tatami_test {
14
22 double lower = 0;
23
27 double upper = 100;
28
32 double density = 0.1;
33
37 uint64_t seed = 1234567890;
38};
39
46template<typename Value_, typename Index_>
52 std::vector<Value_> data;
53
59 std::vector<Index_> index;
60
66 std::vector<size_t> indptr;
67};
68
81template<typename Value_, typename Index_>
83 std::mt19937_64 rng(options.seed);
84 std::uniform_real_distribution<> nonzero(0.0, 1.0);
85 std::uniform_real_distribution<> unif(options.lower, options.upper);
86
88 output.indptr.resize(primary + 1);
89 for (size_t p = 0; p < primary; ++p) {
90 size_t idx = output.indptr[p];
91 for (size_t s = 0; s < secondary; ++s) {
92 if (nonzero(rng) < options.density) {
93 output.data.push_back(unif(rng));
94 output.index.push_back(s);
95 ++idx;
96 }
97 }
98 output.indptr[p + 1] = idx;
99 }
100
101 return output;
102}
103
104}
105
106#endif
Utilities for testing tatami libraries.
Definition create_indexed_subset.hpp:15
SimulateCompressedSparseResult< Value_, Index_ > simulate_compressed_sparse(size_t primary, size_t secondary, const SimulateCompressedSparseOptions &options)
Definition simulate_compressed_sparse.hpp:82
Options for simulate_compressed_sparse().
Definition simulate_compressed_sparse.hpp:18
double lower
Definition simulate_compressed_sparse.hpp:22
double upper
Definition simulate_compressed_sparse.hpp:27
uint64_t seed
Definition simulate_compressed_sparse.hpp:37
double density
Definition simulate_compressed_sparse.hpp:32
Result of simulate_compressed_sparse().
Definition simulate_compressed_sparse.hpp:47
std::vector< size_t > indptr
Definition simulate_compressed_sparse.hpp:66
std::vector< Value_ > data
Definition simulate_compressed_sparse.hpp:52
std::vector< Index_ > index
Definition simulate_compressed_sparse.hpp:59