tatami
C++ API for different matrix representations
Loading...
Searching...
No Matches
FixedOracle.hpp
Go to the documentation of this file.
1#ifndef TATAMI_FIXED_ORACLE_HPP
2#define TATAMI_FIXED_ORACLE_HPP
3
4#include "../base/Oracle.hpp"
5
6#include <vector>
7#include <cstddef>
8
9#include "sanisizer/sanisizer.hpp"
10
17namespace tatami {
18
24template<typename Index_>
25class FixedViewOracle final : public Oracle<Index_> {
26public:
32 FixedViewOracle(const Index_* ptr, PredictionIndex number) : my_reference(ptr), my_length(number) {
33 sanisizer::can_cast<std::size_t>(number); // make sure that array is addressable by all [0, number).
34 }
35
37 return my_length;
38 }
39
40 Index_ get(PredictionIndex i) const {
41 return my_reference[i];
42 }
43
44private:
45 const Index_* my_reference;
46 PredictionIndex my_length;
47};
48
54template<typename Index_>
55class FixedVectorOracle final : public Oracle<Index_> {
56public:
60 FixedVectorOracle(std::vector<Index_> vector) : my_sequence(std::move(vector)) {
61 sanisizer::can_cast<PredictionIndex>(my_sequence.size()); // make sure that total() will return a sensible value.
62 }
63
65 return my_sequence.size();
66 }
67
68 Index_ get(PredictionIndex i) const {
69 return my_sequence[i];
70 }
71
72private:
73 std::vector<Index_> my_sequence;
74};
75
76}
77
78#endif
Oracle for data access.
Predict future accesses from a vector containing a fixed sequence.
Definition FixedOracle.hpp:55
PredictionIndex total() const
Definition FixedOracle.hpp:64
Index_ get(PredictionIndex i) const
Definition FixedOracle.hpp:68
FixedVectorOracle(std::vector< Index_ > vector)
Definition FixedOracle.hpp:60
Predict future accesses from a view on a fixed sequence.
Definition FixedOracle.hpp:25
PredictionIndex total() const
Definition FixedOracle.hpp:36
Index_ get(PredictionIndex i) const
Definition FixedOracle.hpp:40
FixedViewOracle(const Index_ *ptr, PredictionIndex number)
Definition FixedOracle.hpp:32
Predict future access requests on the target dimension.
Definition Oracle.hpp:29
Flexible representations for matrix data.
Definition Extractor.hpp:15
std::size_t PredictionIndex
Definition Oracle.hpp:18