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
4#include <vector>
5#include <cstddef>
6
10
16namespace tatami_test {
17
21template<typename Value_, typename Index_>
22void trim_sparse(const tatami::SparseRange<Value_, Index_>& raw, std::vector<Value_>& output_v, std::vector<Index_>& output_i) {
23 tatami::copy_n(raw.value, raw.number, output_v.data());
24 output_v.resize(raw.number);
25 tatami::copy_n(raw.index, raw.number, output_i.data());
26 output_i.resize(raw.number);
27}
42template<typename Value_, typename Index_>
43std::vector<Value_> fetch(tatami::MyopicDenseExtractor<Value_, Index_>& ext, Index_ i, std::size_t number) {
44 std::vector<Value_> output(number);
45 auto raw = ext.fetch(i, output.data());
46 tatami::copy_n(raw, output.size(), output.data());
47 return output;
48}
49
59template<typename Value_, typename Index_>
60std::vector<Value_> fetch(tatami::OracularDenseExtractor<Value_, Index_>& ext, std::size_t number) {
61 std::vector<Value_> output(number);
62 auto raw = ext.fetch(output.data());
63 tatami::copy_n(raw, output.size(), output.data());
64 return output;
65}
66
72template<typename Value_, typename Index_>
77 SparseVector(size_t n) : value(n), index(n) {}
85 std::vector<Value_> value;
86
91 std::vector<Index_> index;
92};
93
104template<typename Value_, typename Index_>
106 SparseVector<Value_, Index_> output(number);
107 auto raw = ext.fetch(i, output.value.data(), output.index.data());
108 trim_sparse(raw, output.value, output.index);
109 return output;
110}
111
121template<typename Value_, typename Index_>
123 SparseVector<Value_, Index_> output(number);
124 auto raw = ext.fetch(output.value.data(), output.index.data());
125 trim_sparse(raw, output.value, output.index);
126 return output;
127}
128
129}
130
131#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:16
std::vector< Value_ > fetch(tatami::MyopicDenseExtractor< Value_, Index_ > &ext, Index_ i, std::size_t number)
Definition fetch.hpp:43
Value_ * copy_n(const Value_ *const input, const Size_ n, Value_ *const output)
const Value_ * value
const Index_ * index
Sparse vector.
Definition fetch.hpp:73
std::vector< Index_ > index
Definition fetch.hpp:91
std::vector< Value_ > value
Definition fetch.hpp:85