1#ifndef TATAMI_DELAYED_SUBSET_BLOCK
2#define TATAMI_DELAYED_SUBSET_BLOCK
4#include "../base/Matrix.hpp"
5#include "../utils/new_extractor.hpp"
26template<
typename Index_>
31 for (
auto&
i : *
ptr2) {
37template<
bool oracle_,
typename Value_,
typename Index_>
40 AlongDense(
const Matrix<Value_, Index_>* matrix, Index_ subset_start, Index_ subset_length,
bool row, MaybeOracle<oracle_, Index_> oracle,
const Options& opt) :
41 my_ext(
new_extractor<false, oracle_>(matrix, row, std::move(oracle), subset_start, subset_length, opt)) {}
43 AlongDense(
const Matrix<Value_, Index_>* matrix, Index_ subset_start, Index_ ,
bool row, MaybeOracle<oracle_, Index_> oracle, Index_ block_start, Index_ block_length,
const Options& opt) :
44 my_ext(
new_extractor<false, oracle_>(matrix, row, std::move(oracle), subset_start + block_start, block_length, opt)) {}
46 AlongDense(
const Matrix<Value_, Index_>* matrix, Index_ subset_start, Index_ ,
bool row, MaybeOracle<oracle_, Index_> oracle, VectorPtr<Index_> indices_ptr,
const Options& opt) {
47 bump_indices(indices_ptr, subset_start);
48 my_ext = new_extractor<false, oracle_>(matrix, row, std::move(oracle), std::move(indices_ptr), opt);
51 const Value_* fetch(Index_ i, Value_* buffer) {
52 return my_ext->fetch(i, buffer);
56 std::unique_ptr<DenseExtractor<oracle_, Value_, Index_> > my_ext;
59template<
bool oracle_,
typename Value_,
typename Index_>
62 AlongSparse(
const Matrix<Value_, Index_>* matrix, Index_ subset_start, Index_ subset_length,
bool row, MaybeOracle<oracle_, Index_> oracle,
const Options& opt) :
63 my_ext(
new_extractor<true, oracle_>(matrix, row, std::move(oracle), subset_start, subset_length, opt)), my_shift(subset_start) {}
65 AlongSparse(
const Matrix<Value_, Index_>* matrix, Index_ subset_start, Index_ ,
bool row, MaybeOracle<oracle_, Index_> oracle, Index_ block_start, Index_ block_length,
const Options& opt) :
66 my_ext(
new_extractor<true, oracle_>(matrix, row, std::move(oracle), subset_start + block_start, block_length, opt)), my_shift(subset_start) {}
68 AlongSparse(
const Matrix<Value_, Index_>* matrix, Index_ subset_start, Index_ ,
bool row, MaybeOracle<oracle_, Index_> oracle, VectorPtr<Index_> indices_ptr,
const Options& opt) :
69 my_shift(subset_start)
71 bump_indices(indices_ptr, subset_start);
72 my_ext = new_extractor<true, oracle_>(matrix, row, std::move(oracle), std::move(indices_ptr), opt);
75 SparseRange<Value_, Index_> fetch(Index_ i, Value_* value_buffer, Index_* index_buffer) {
76 auto output = my_ext->fetch(i, value_buffer, index_buffer);
77 if (output.index && my_shift) {
78 for (Index_ i = 0; i < output.number; ++i) {
79 index_buffer[i] = output.index[i] - my_shift;
81 output.index = index_buffer;
87 std::unique_ptr<SparseExtractor<oracle_, Value_, Index_> > my_ext;
91template<
typename Index_>
94 SubsetOracle(std::shared_ptr<
const Oracle<Index_> > oracle, Index_ shift) : my_oracle(std::move(oracle)), my_shift(shift) {}
96 size_t total()
const {
97 return my_oracle->total();
100 Index_ get(
size_t i)
const {
101 return my_oracle->get(i) + my_shift;
105 std::shared_ptr<const Oracle<Index_> > my_oracle;
109template<
bool oracle_,
typename Value_,
typename Index_>
112 template<
typename ... Args_>
113 AcrossDense(
const Matrix<Value_, Index_>* matrix, Index_ subset_start,
bool row, MaybeOracle<oracle_, Index_> oracle, Args_&& ... args) : my_shift(subset_start) {
114 if constexpr(oracle_) {
115 auto ptr =
new SubsetOracle(std::move(oracle), my_shift);
118 my_ext = new_extractor<false, oracle_>(matrix, row, std::move(oracle), std::forward<Args_>(args)...);
121 const Value_* fetch(Index_ i, Value_* buffer) {
122 return my_ext->fetch(i + my_shift, buffer);
126 std::unique_ptr<DenseExtractor<oracle_, Value_, Index_> > my_ext;
130template<
bool oracle_,
typename Value_,
typename Index_>
133 template<
typename ... Args_>
134 AcrossSparse(
const Matrix<Value_, Index_>* matrix, Index_ subset_start,
bool row, MaybeOracle<oracle_, Index_> oracle, Args_&& ... args) : my_shift(subset_start) {
135 if constexpr(oracle_) {
136 auto ptr =
new SubsetOracle(std::move(oracle), my_shift);
139 my_ext = new_extractor<true, oracle_>(matrix, row, std::move(oracle), std::forward<Args_>(args)...);
142 SparseRange<Value_, Index_> fetch(Index_ i, Value_* value_buffer, Index_* index_buffer) {
143 return my_ext->fetch(i + my_shift, value_buffer, index_buffer);
147 std::unique_ptr<SparseExtractor<oracle_, Value_, Index_> > my_ext;
166template<
typename Value_,
typename Index_>
180 std::shared_ptr<const Matrix<Value_, Index_> > my_matrix;
181 Index_ my_subset_start, my_subset_length;
187 return my_subset_length;
189 return my_matrix->nrow();
195 return my_matrix->ncol();
197 return my_subset_length;
202 return my_matrix->is_sparse();
206 return my_matrix->is_sparse_proportion();
210 return my_matrix->prefer_rows();
214 return my_matrix->prefer_rows_proportion();
218 return my_matrix->uses_oracle(
row);
234 std::unique_ptr<DenseExtractor<oracle_, Value_, Index_> > dense_internal(
bool row,
Args_&&...
args)
const {
235 if (
row != my_by_row) {
236 return std::make_unique<DelayedSubsetBlock_internal::AlongDense<oracle_, Value_, Index_> >(my_matrix.get(), my_subset_start, my_subset_length,
row, std::forward<Args_>(
args)...);
238 return std::make_unique<DelayedSubsetBlock_internal::AcrossDense<oracle_, Value_, Index_> >(my_matrix.get(), my_subset_start,
row, std::forward<Args_>(
args)...);
260 std::unique_ptr<SparseExtractor<oracle_, Value_, Index_> > sparse_internal(
bool row,
Args_&&...
args)
const {
261 if (
row != my_by_row) {
262 return std::make_unique<DelayedSubsetBlock_internal::AlongSparse<oracle_, Value_, Index_> >(my_matrix.get(), my_subset_start, my_subset_length,
row, std::forward<Args_>(
args)...);
264 return std::make_unique<DelayedSubsetBlock_internal::AcrossSparse<oracle_, Value_, Index_> >(my_matrix.get(), my_subset_start,
row, std::forward<Args_>(
args)...);
328template<
typename Value_,
typename Index_>
336template<
typename Value_,
typename Index_>
347template<
int margin_,
typename Value_,
typename Index_>
352template<
int margin_,
typename Value_,
typename Index_>
Delayed subsetting to a contiguous block.
Definition DelayedSubsetBlock.hpp:167
Index_ nrow() const
Definition DelayedSubsetBlock.hpp:185
std::unique_ptr< OracularDenseExtractor< Value_, Index_ > > dense(bool row, std::shared_ptr< const Oracle< Index_ > > oracle, VectorPtr< Index_ > indices_ptr, const Options &opt) const
Definition DelayedSubsetBlock.hpp:293
std::unique_ptr< MyopicDenseExtractor< Value_, Index_ > > dense(bool row, Index_ block_start, Index_ block_length, const Options &opt) const
Definition DelayedSubsetBlock.hpp:247
double prefer_rows_proportion() const
Definition DelayedSubsetBlock.hpp:213
std::unique_ptr< OracularSparseExtractor< Value_, Index_ > > sparse(bool row, std::shared_ptr< const Oracle< Index_ > > oracle, const Options &opt) const
Definition DelayedSubsetBlock.hpp:301
Index_ ncol() const
Definition DelayedSubsetBlock.hpp:193
std::unique_ptr< MyopicDenseExtractor< Value_, Index_ > > dense(bool row, const Options &opt) const
Definition DelayedSubsetBlock.hpp:243
std::unique_ptr< MyopicSparseExtractor< Value_, Index_ > > sparse(bool row, VectorPtr< Index_ > indices_ptr, const Options &opt) const
Definition DelayedSubsetBlock.hpp:277
std::unique_ptr< OracularSparseExtractor< Value_, Index_ > > sparse(bool row, std::shared_ptr< const Oracle< Index_ > > oracle, VectorPtr< Index_ > indices_ptr, const Options &opt) const
Definition DelayedSubsetBlock.hpp:309
double is_sparse_proportion() const
Definition DelayedSubsetBlock.hpp:205
bool is_sparse() const
Definition DelayedSubsetBlock.hpp:201
std::unique_ptr< OracularSparseExtractor< Value_, Index_ > > sparse(bool row, std::shared_ptr< const Oracle< Index_ > > oracle, Index_ block_start, Index_ block_length, const Options &opt) const
Definition DelayedSubsetBlock.hpp:305
std::unique_ptr< MyopicDenseExtractor< Value_, Index_ > > dense(bool row, VectorPtr< Index_ > indices_ptr, const Options &opt) const
Definition DelayedSubsetBlock.hpp:251
std::unique_ptr< OracularDenseExtractor< Value_, Index_ > > dense(bool row, std::shared_ptr< const Oracle< Index_ > > oracle, const Options &opt) const
Definition DelayedSubsetBlock.hpp:285
std::unique_ptr< MyopicSparseExtractor< Value_, Index_ > > sparse(bool row, const Options &opt) const
Definition DelayedSubsetBlock.hpp:269
DelayedSubsetBlock(std::shared_ptr< const Matrix< Value_, Index_ > > matrix, Index_ subset_start, Index_ subset_length, bool by_row)
Definition DelayedSubsetBlock.hpp:176
bool uses_oracle(bool row) const
Definition DelayedSubsetBlock.hpp:217
std::unique_ptr< OracularDenseExtractor< Value_, Index_ > > dense(bool row, std::shared_ptr< const Oracle< Index_ > > oracle, Index_ block_start, Index_ block_length, const Options &opt) const
Definition DelayedSubsetBlock.hpp:289
std::unique_ptr< MyopicSparseExtractor< Value_, Index_ > > sparse(bool row, Index_ block_start, Index_ block_length, const Options &opt) const
Definition DelayedSubsetBlock.hpp:273
bool prefer_rows() const
Definition DelayedSubsetBlock.hpp:209
Virtual class for a matrix.
Definition Matrix.hpp:59
std::unique_ptr< MyopicDenseExtractor< Value_, Index_ > > dense_row() const
Definition Matrix.hpp:287
std::unique_ptr< MyopicDenseExtractor< Value_, Index_ > > dense_column() const
Definition Matrix.hpp:328
std::unique_ptr< MyopicSparseExtractor< Value_, Index_ > > sparse_column() const
Definition Matrix.hpp:537
std::unique_ptr< MyopicSparseExtractor< Value_, Index_ > > sparse_row() const
Definition Matrix.hpp:496
Predict future access requests on the target dimension.
Definition Oracle.hpp:21
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
std::shared_ptr< const std::vector< Index_ > > VectorPtr
Definition Matrix.hpp:26
std::shared_ptr< Matrix< Value_, Index_ > > make_DelayedSubsetBlock(std::shared_ptr< const Matrix< Value_, Index_ > > matrix, Index_ subset_start, Index_ subset_length, bool by_row)
Definition DelayedSubsetBlock.hpp:329
auto new_extractor(const Matrix< Value_, Index_ > *ptr, bool row, MaybeOracle< oracle_, Index_ > oracle, Args_ &&... args)
Definition new_extractor.hpp:42
auto consecutive_extractor(const Matrix< Value_, Index_ > *mat, bool row, Index_ iter_start, Index_ iter_length, Args_ &&... args)
Definition consecutive_extractor.hpp:35
Options for accessing data from a Matrix instance.
Definition Options.hpp:30