tatami_test
Utilities for testing tatami libraries
Loading...
Searching...
No Matches
fetch.hpp
Go to the documentation of this file.
1#ifndef TATAMI_TEST_FETCH_HPP
2#define TATAMI_TEST_FETCH_HPP
3
7
8#include <vector>
9
15namespace tatami_test {
16
20namespace internal {
21
22template<typename Value_, typename Index_>
23void trim_sparse(const tatami::SparseRange<Value_, Index_>& raw, std::vector<Value_>& output_v, std::vector<Index_>& output_i) {
24 tatami::copy_n(raw.value, raw.number, output_v.data());
25 output_v.resize(raw.number);
26 tatami::copy_n(raw.index, raw.number, output_i.data());
27 output_i.resize(raw.number);
28}
29
30}
45template<typename Value_, typename Index_>
46std::vector<Value_> fetch(tatami::MyopicDenseExtractor<Value_, Index_>& ext, Index_ i, size_t number) {
47 std::vector<Value_> output(number);
48 auto raw = ext.fetch(i, output.data());
49 tatami::copy_n(raw, output.size(), output.data());
50 return output;
51}
52
62template<typename Value_, typename Index_>
63std::vector<Value_> fetch(tatami::OracularDenseExtractor<Value_, Index_>& ext, size_t number) {
64 std::vector<Value_> output(number);
65 auto raw = ext.fetch(output.data());
66 tatami::copy_n(raw, output.size(), output.data());
67 return output;
68}
69
75template<typename Value_, typename Index_>
80 SparseVector(size_t n) : value(n), index(n) {}
88 std::vector<Value_> value;
89
94 std::vector<Index_> index;
95};
96
107template<typename Value_, typename Index_>
109 SparseVector<Value_, Index_> output(number);
110 auto raw = ext.fetch(i, output.value.data(), output.index.data());
111 internal::trim_sparse(raw, output.value, output.index);
112 return output;
113}
114
124template<typename Value_, typename Index_>
126 SparseVector<Value_, Index_> output(number);
127 auto raw = ext.fetch(output.value.data(), output.index.data());
128 internal::trim_sparse(raw, output.value, output.index);
129 return output;
130}
131
132}
133
134#endif
virtual const Value_ * fetch(Index_ i, Value_ *buffer)=0
virtual SparseRange< Value_, Index_ > fetch(Index_ i, Value_ *value_buffer, Index_ *index_buffer)=0
const Value_ * fetch(Value_ *buffer)
SparseRange< Value_, Index_ > fetch(Value_ *value_buffer, Index_ *index_buffer)
Utilities for testing tatami libraries.
Definition create_indexed_subset.hpp:15
std::vector< Value_ > fetch(tatami::MyopicDenseExtractor< Value_, Index_ > &ext, Index_ i, size_t number)
Definition fetch.hpp:46
Value_ * copy_n(const Value_ *input, Size_ n, Value_ *output)
const Value_ * value
const Index_ * index
Sparse vector.
Definition fetch.hpp:76
std::vector< Index_ > index
Definition fetch.hpp:94
std::vector< Value_ > value
Definition fetch.hpp:88