scran_test_utils
Test utilities for libscran projects
Loading...
Searching...
No Matches
simulate_compressed_sparse_matrix.hpp
Go to the documentation of this file.
1#ifndef SCRAN_TESTS_SIMULATE_COMPRESSED_SPARSE_MATRIX_HPP
2#define SCRAN_TESTS_SIMULATE_COMPRESSED_SPARSE_MATRIX_HPP
3
4#include <random>
5#include <vector>
6#include <type_traits>
7#include <cstddef>
8
9#include "simulate_vector.hpp"
10
16namespace scran_tests {
17
23template<typename Data_ = double>
28 double density = 0.2;
29
35
40 Data_ upper = 10;
41
45 typename RngEngine::result_type seed = 1234567890;
46};
47
54template<typename Data_, typename Index_, typename Pointer_>
59 Index_ primary;
60
64 Index_ secondary;
65
69 std::vector<Data_> data;
70
74 std::vector<Index_> index;
75
79 std::vector<Pointer_> pointers;
80};
81
94template<typename Data_ = double, typename Index_ = int, typename Pointer_ = std::size_t>
96 Index_ primary,
97 Index_ secondary,
99) {
100 RngEngine rng(params.seed);
101 auto unif = create_simulating_distribution(params.lower, params.upper);
102
104 output.primary = primary;
105 output.secondary = secondary;
106 output.pointers.reserve(static_cast<typename std::vector<Pointer_>::size_type>(primary) + 1);
107 output.pointers.push_back(0);
108
109 std::uniform_real_distribution<double> nonzero(0.0, 1.0);
110 for (Index_ p = 0; p < primary; ++p) {
111 for (Index_ s = 0; s < secondary; ++s) {
112 if (nonzero(rng) <= params.density) {
113 output.index.push_back(s);
114 output.data.push_back(unif(rng));
115 }
116 }
117 output.pointers.push_back(output.index.size());
118 }
119
120 return output;
121}
122
123}
124
125#endif
Test utilites for libscran.
Definition compare_almost_equal.hpp:12
SimulatedCompressedSparseMatrix< Data_, Index_, Pointer_ > simulate_compressed_sparse_matrix(Index_ primary, Index_ secondary, const SimulateCompressedSparseMatrixParameters< Data_ > &params)
Definition simulate_compressed_sparse_matrix.hpp:95
constexpr Type_ default_simulation_min()
Definition simulate_vector.hpp:27
std::mt19937_64 RngEngine
Definition simulate_vector.hpp:20
Simulate a vector of random values.
Parameters for simulate_compressed_sparse_matrix().
Definition simulate_compressed_sparse_matrix.hpp:24
Data_ lower
Definition simulate_compressed_sparse_matrix.hpp:34
double density
Definition simulate_compressed_sparse_matrix.hpp:28
Data_ upper
Definition simulate_compressed_sparse_matrix.hpp:40
RngEngine::result_type seed
Definition simulate_compressed_sparse_matrix.hpp:45
Results of simulate_compressed_sparse_matrix().
Definition simulate_compressed_sparse_matrix.hpp:55
Index_ secondary
Definition simulate_compressed_sparse_matrix.hpp:64
std::vector< Index_ > index
Definition simulate_compressed_sparse_matrix.hpp:74
std::vector< Pointer_ > pointers
Definition simulate_compressed_sparse_matrix.hpp:79
Index_ primary
Definition simulate_compressed_sparse_matrix.hpp:59
std::vector< Data_ > data
Definition simulate_compressed_sparse_matrix.hpp:69