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:
40 virtual const Value_* fetch(Index_ i, Value_* buffer) = 0;
41
45 MyopicDenseExtractor() = default;
47 MyopicDenseExtractor& operator=(const MyopicDenseExtractor&) = default;
49 MyopicDenseExtractor& operator=(MyopicDenseExtractor&&) = default;
50 virtual ~MyopicDenseExtractor() = default;
58 // No-op for back-compatibility only.
59 template<class Oracle_>
60 void set_oracle(Oracle_) {}
64};
65
71template<typename Value_, typename Index_>
73public:
85 const Value_* fetch(Value_* buffer) {
86 return fetch(0, buffer);
87 }
88
108 virtual const Value_* fetch(Index_ i, Value_* buffer) = 0;
109
113 OracularDenseExtractor() = default;
115 OracularDenseExtractor& operator=(const OracularDenseExtractor&) = default;
117 OracularDenseExtractor& operator=(OracularDenseExtractor&&) = default;
118 virtual ~OracularDenseExtractor() = default;
126 // No-op for back-compatibility only.
127 template<class Oracle_>
128 void set_oracle(Oracle_) {}
132};
133
139template<typename Value_, typename Index_>
141public:
161 virtual SparseRange<Value_, Index_> fetch(Index_ i, Value_* value_buffer, Index_* index_buffer) = 0;
162
166 MyopicSparseExtractor() = default;
168 MyopicSparseExtractor& operator=(const MyopicSparseExtractor&) = default;
170 MyopicSparseExtractor& operator=(MyopicSparseExtractor&&) = default;
171 virtual ~MyopicSparseExtractor() = default;
179 // No-op for back-compatibility only.
180 template<class Oracle_>
181 void set_oracle(Oracle_) {}
185};
186
192template<typename Value_, typename Index_>
194public:
214 SparseRange<Value_, Index_> fetch(Value_* value_buffer, Index_* index_buffer) {
215 return fetch(0, value_buffer, index_buffer);
216 }
217
238 virtual SparseRange<Value_, Index_> fetch(Index_ i, Value_* value_buffer, Index_* index_buffer) = 0;
239
243 OracularSparseExtractor() = default;
245 OracularSparseExtractor& operator=(const OracularSparseExtractor&) = default;
247 OracularSparseExtractor& operator=(OracularSparseExtractor&&) = default;
248 virtual ~OracularSparseExtractor() = default;
256 // No-op for back-compatibility only.
257 template<class Oracle_>
258 void set_oracle(Oracle_) {}
262};
263
272template<bool oracle_, typename Value_, typename Index_>
273using DenseExtractor = typename std::conditional<oracle_, OracularDenseExtractor<Value_, Index_>, MyopicDenseExtractor<Value_, Index_> >::type;
274
283template<bool oracle_, typename Value_, typename Index_>
284using SparseExtractor = typename std::conditional<oracle_, OracularSparseExtractor<Value_, Index_>, MyopicSparseExtractor<Value_, Index_> >::type;
285
286}
287
288#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:140
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:72
virtual const Value_ * fetch(Index_ i, Value_ *buffer)=0
const Value_ * fetch(Value_ *buffer)
Definition Extractor.hpp:85
Extract an element of the target dimension in sparse form with an oracle.
Definition Extractor.hpp:193
virtual SparseRange< Value_, Index_ > fetch(Index_ i, Value_ *value_buffer, Index_ *index_buffer)=0
SparseRange< Value_, Index_ > fetch(Value_ *value_buffer, Index_ *index_buffer)
Definition Extractor.hpp:214
Flexible representations for matrix data.
Definition Extractor.hpp:15
typename std::conditional< oracle_, OracularDenseExtractor< Value_, Index_ >, MyopicDenseExtractor< Value_, Index_ > >::type DenseExtractor
Definition Extractor.hpp:273
typename std::conditional< oracle_, OracularSparseExtractor< Value_, Index_ >, MyopicSparseExtractor< Value_, Index_ > >::type SparseExtractor
Definition Extractor.hpp:284
A range of a sparse vector.
Definition SparseRange.hpp:32