tatami
C++ API for different matrix representations
Loading...
Searching...
No Matches
Extractor.hpp
Go to the documentation of this file.
1#ifndef TATAMI_EXTRACTOR_HPP
2#define TATAMI_EXTRACTOR_HPP
3
4#include <vector>
5#include <type_traits>
6#include "SparseRange.hpp"
7#include "Options.hpp"
8
15namespace tatami {
16
23template<typename Value_, typename Index_>
25public:
48 virtual const Value_* fetch(Index_ i, Value_* buffer) = 0;
49
53 MyopicDenseExtractor() = default;
55 MyopicDenseExtractor& operator=(const MyopicDenseExtractor&) = default;
57 MyopicDenseExtractor& operator=(MyopicDenseExtractor&&) = default;
58 virtual ~MyopicDenseExtractor() = default;
62};
63
69template<typename Value_, typename Index_>
71public:
90 const Value_* next(Value_* buffer) {
91 // Use -1 to hopefully trigger a segfault somewhere if an implementation accidentally uses `i`.
92 return fetch(static_cast<Index_>(-1), buffer);
93 }
94
98 // For back-compatibility.
99 const Value_* fetch(Value_* buffer) {
100 return next(buffer);
101 }
119 virtual const Value_* fetch(Index_ i, Value_* buffer) = 0;
120
124 OracularDenseExtractor() = default;
126 OracularDenseExtractor& operator=(const OracularDenseExtractor&) = default;
128 OracularDenseExtractor& operator=(OracularDenseExtractor&&) = default;
129 virtual ~OracularDenseExtractor() = default;
133};
134
140template<typename Value_, typename Index_>
142public:
174 virtual SparseRange<Value_, Index_> fetch(Index_ i, Value_* value_buffer, Index_* index_buffer) = 0;
175
179 MyopicSparseExtractor() = default;
181 MyopicSparseExtractor& operator=(const MyopicSparseExtractor&) = default;
183 MyopicSparseExtractor& operator=(MyopicSparseExtractor&&) = default;
184 virtual ~MyopicSparseExtractor() = default;
188};
189
195template<typename Value_, typename Index_>
197public:
228 SparseRange<Value_, Index_> next(Value_* value_buffer, Index_* index_buffer) {
229 // Use -1 to hopefully trigger a segfault somewhere if an implementation accidentally uses `i`.
230 return fetch(static_cast<Index_>(-1), value_buffer, index_buffer);
231 }
232
236 // For back-compatibility.
237 SparseRange<Value_, Index_> fetch(Value_* value_buffer, Index_* index_buffer) {
238 return next(value_buffer, index_buffer);
239 }
259 virtual SparseRange<Value_, Index_> fetch(Index_ i, Value_* value_buffer, Index_* index_buffer) = 0;
260
264 OracularSparseExtractor() = default;
266 OracularSparseExtractor& operator=(const OracularSparseExtractor&) = default;
268 OracularSparseExtractor& operator=(OracularSparseExtractor&&) = default;
269 virtual ~OracularSparseExtractor() = default;
273};
274
283template<bool oracle_, typename Value_, typename Index_>
284using DenseExtractor = typename std::conditional<oracle_, OracularDenseExtractor<Value_, Index_>, MyopicDenseExtractor<Value_, Index_> >::type;
285
294template<bool oracle_, typename Value_, typename Index_>
295using SparseExtractor = typename std::conditional<oracle_, OracularSparseExtractor<Value_, Index_>, MyopicSparseExtractor<Value_, Index_> >::type;
296
297
307template<bool sparse_, bool oracle_, typename Value_, typename Index_>
308using Extractor = typename std::conditional<sparse_, SparseExtractor<oracle_, Value_, Index_>, DenseExtractor<oracle_, Value_, Index_> >::type;
309
310}
311
312#endif
Options for data access.
Store information about extracted sparse elements.
Extract an element of the target dimension in dense form without an oracle.
Definition Extractor.hpp:24
virtual const Value_ * fetch(Index_ i, Value_ *buffer)=0
Extract an element of the target dimension in sparse form without an oracle.
Definition Extractor.hpp:141
virtual SparseRange< Value_, Index_ > fetch(Index_ i, Value_ *value_buffer, Index_ *index_buffer)=0
Extract an element of the target dimension in dense form with an oracle.
Definition Extractor.hpp:70
virtual const Value_ * fetch(Index_ i, Value_ *buffer)=0
const Value_ * next(Value_ *buffer)
Definition Extractor.hpp:90
Extract an element of the target dimension in sparse form with an oracle.
Definition Extractor.hpp:196
SparseRange< Value_, Index_ > next(Value_ *value_buffer, Index_ *index_buffer)
Definition Extractor.hpp:228
virtual SparseRange< Value_, Index_ > fetch(Index_ i, Value_ *value_buffer, Index_ *index_buffer)=0
Flexible representations for matrix data.
Definition Extractor.hpp:15
typename std::conditional< oracle_, OracularSparseExtractor< Value_, Index_ >, MyopicSparseExtractor< Value_, Index_ > >::type SparseExtractor
Definition Extractor.hpp:295
typename std::conditional< sparse_, SparseExtractor< oracle_, Value_, Index_ >, DenseExtractor< oracle_, Value_, Index_ > >::type Extractor
Definition Extractor.hpp:308
typename std::conditional< oracle_, OracularDenseExtractor< Value_, Index_ >, MyopicDenseExtractor< Value_, Index_ > >::type DenseExtractor
Definition Extractor.hpp:284
A range of a sparse vector.
Definition SparseRange.hpp:32