tatami_test
Utilities for testing tatami libraries
Loading...
Searching...
No Matches
create_indexed_subset.hpp
Go to the documentation of this file.
1#ifndef TATAMI_TEST_CREATE_INDEXED_SUBSET_HPP
2#define TATAMI_TEST_CREATE_INDEXED_SUBSET_HPP
3
4#include <vector>
5#include <random>
6
7#include "tatami/tatami.hpp"
8
9#include "utils.hpp"
10
16namespace tatami_test {
17
35template<typename Index_>
36tatami::VectorPtr<Index_> create_indexed_subset(const Index_ extent, const double relative_start, const double probability, const SeedType seed) {
37 auto ptr = new std::vector<Index_>;
38 tatami::VectorPtr<Index_> output(ptr);
39
40 Index_ start = extent * relative_start;
41 if (start >= extent) {
42 return output;
43 }
44
45 ptr->push_back(Fix(start));
46 RngEngine rng(seed);
47 std::uniform_real_distribution udist;
48 for (Index_ i = start + 1; i < extent; ++i) {
49 if (udist(rng) < probability) {
50 ptr->push_back(Fix(i));
51 }
52 }
53
54 return output;
55}
56
57}
58
59#endif
Utilities for testing tatami libraries.
Definition create_indexed_subset.hpp:16
tatami::VectorPtr< Index_ > create_indexed_subset(const Index_ extent, const double relative_start, const double probability, const SeedType seed)
Definition create_indexed_subset.hpp:36
std::mt19937_64 RngEngine
Definition utils.hpp:34
RngEngine::result_type SeedType
Definition utils.hpp:39
std::shared_ptr< const std::vector< Index_ > > VectorPtr
Miscellaneous utilities.