1#ifndef TATAMI_DELAYED_SUBSET_SORTED_UNIQUE_HPP
2#define TATAMI_DELAYED_SUBSET_SORTED_UNIQUE_HPP
4#include "../base/Matrix.hpp"
23template<
typename Index_,
class SubsetStorage_>
25 return std::make_shared<std::vector<Index_> >(
subset.begin(),
subset.end());
28template<
typename Index_,
class SubsetStorage_>
34template<
typename Index_,
class SubsetStorage_>
36 auto rawptr = std::make_shared<std::vector<Index_> >();
49template<
bool oracle_,
typename Value_,
typename Index_,
class SubsetStorage_>
51 const Matrix<Value_, Index_>*
matrix,
60template<
bool oracle_,
typename Value_,
typename Index_,
class SubsetStorage_>
62 const Matrix<Value_, Index_>*
matrix,
73template<
bool oracle_,
typename Value_,
typename Index_,
class SubsetStorage_>
75 const Matrix<Value_, Index_>*
matrix,
85template<
bool oracle_,
typename Value_,
typename Index_>
88 template<
class SubsetStorage_>
90 const Matrix<Value_, Index_>* matrix,
91 const SubsetStorage_& subset,
92 const std::vector<Index_>& remap,
94 MaybeOracle<oracle_, Index_> oracle,
97 my_ext(
new_extractor<true, oracle_>(matrix, row, std::move(oracle), create<Index_>(subset), opt)),
101 template<
class SubsetStorage_>
103 const Matrix<Value_, Index_>* matrix,
104 const SubsetStorage_& subset,
105 const std::vector<Index_>& remap,
106 bool row, MaybeOracle<oracle_, Index_> oracle,
111 my_ext(
new_extractor<true, oracle_>(matrix, row, std::move(oracle), create<Index_>(subset, block_start, block_length), opt)),
115 template<
class SubsetStorage_>
117 const Matrix<Value_, Index_>* matrix,
118 const SubsetStorage_& subset,
119 const std::vector<Index_>& remap,
121 MaybeOracle<oracle_, Index_> oracle,
122 VectorPtr<Index_> indices_ptr,
125 my_ext(
new_extractor<true, oracle_>(matrix, row, std::move(oracle), create<Index_>(subset, indices_ptr), opt)),
130 SparseRange<Value_, Index_> fetch(Index_ i, Value_* value_buffer, Index_* index_buffer) {
131 auto out = my_ext->fetch(i, value_buffer, index_buffer);
133 for (Index_ i = 0; i < out.number; ++i) {
134 index_buffer[i] = my_remapping[out.index[i]];
136 out.index = index_buffer;
142 std::unique_ptr<SparseExtractor<oracle_, Value_, Index_> > my_ext;
143 const std::vector<Index_>& my_remapping;
161template<
typename Value_,
typename Index_,
class SubsetStorage_>
176 for (
Index_ i = 1, end = my_subset.size();
i < end; ++
i) {
177 if (my_subset[
i] <= my_subset[
i-1]) {
178 throw std::runtime_error(
"subset should be unique and sorted");
185 for (
Index_ i = 0, end = my_subset.size();
i < end; ++
i) {
186 my_mapping_single[my_subset[
i]] =
i;
191 std::shared_ptr<const Matrix<Value_, Index_> > my_matrix;
194 std::vector<Index_> my_mapping_single;
199 return my_subset.size();
201 return my_matrix->nrow();
207 return my_matrix->ncol();
209 return my_subset.size();
214 return my_matrix->is_sparse();
218 return my_matrix->is_sparse_proportion();
222 return my_matrix->prefer_rows();
226 return my_matrix->prefer_rows_proportion();
230 return my_matrix->uses_oracle(
row);
241 template<
typename ...
Args_>
242 std::unique_ptr<MyopicDenseExtractor<Value_, Index_> > populate_myopic_dense(
bool row,
Args_&& ...
args)
const {
243 if (
row == my_by_row) {
244 return std::make_unique<subset_utils::MyopicPerpendicularDense<Value_, Index_, SubsetStorage_> >(my_matrix.get(), my_subset,
row, std::forward<Args_>(
args)...);
246 return DelayedSubsetSortedUnique_internal::create_parallel_dense<false>(my_matrix.get(), my_subset,
row,
false, std::forward<Args_>(
args)...);
252 return populate_myopic_dense(
row,
opt);
267 template<
typename ...
Args_>
268 std::unique_ptr<MyopicSparseExtractor<Value_, Index_> > populate_myopic_sparse(
bool row,
Args_&& ...
args)
const {
269 if (
row == my_by_row) {
270 return std::make_unique<subset_utils::MyopicPerpendicularSparse<Value_, Index_, SubsetStorage_> >(my_matrix.get(), my_subset,
row, std::forward<Args_>(
args)...);
272 return std::make_unique<DelayedSubsetSortedUnique_internal::ParallelSparse<false, Value_, Index_> >(my_matrix.get(), my_subset, my_mapping_single,
row,
false, std::forward<Args_>(
args)...);
278 return populate_myopic_sparse(
row,
opt);
293 template<
typename ...
Args_>
294 std::unique_ptr<OracularDenseExtractor<Value_, Index_> > populate_oracular_dense(
bool row, std::shared_ptr<
const Oracle<Index_> >
oracle,
Args_&& ...
args)
const {
295 if (
row == my_by_row) {
296 return std::make_unique<subset_utils::OracularPerpendicularDense<Value_, Index_> >(my_matrix.get(), my_subset,
row, std::move(
oracle), std::forward<Args_>(
args)...);
298 return DelayedSubsetSortedUnique_internal::create_parallel_dense<true>(my_matrix.get(), my_subset,
row, std::move(
oracle), std::forward<Args_>(
args)...);
304 return populate_oracular_dense(
row, std::move(
oracle),
opt);
319 template<
typename ...
Args_>
320 std::unique_ptr<OracularSparseExtractor<Value_, Index_> > populate_oracular_sparse(
bool row, std::shared_ptr<
const Oracle<Index_> >
oracle,
Args_&& ...
args)
const {
321 if (
row == my_by_row) {
322 return std::make_unique<subset_utils::OracularPerpendicularSparse<Value_, Index_> >(my_matrix.get(), my_subset,
row, std::move(
oracle), std::forward<Args_>(
args)...);
324 return std::make_unique<DelayedSubsetSortedUnique_internal::ParallelSparse<true, Value_, Index_> >(my_matrix.get(), my_subset, my_mapping_single,
row, std::move(
oracle), std::forward<Args_>(
args)...);
330 return populate_oracular_sparse(
row, std::move(
oracle),
opt);
Delayed subsetting of a matrix with sorted, unique indices.
Definition DelayedSubsetSortedUnique.hpp:162
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 DelayedSubsetSortedUnique.hpp:337
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 DelayedSubsetSortedUnique.hpp:307
Index_ ncol() const
Definition DelayedSubsetSortedUnique.hpp:205
double prefer_rows_proportion() const
Definition DelayedSubsetSortedUnique.hpp:225
std::unique_ptr< OracularDenseExtractor< Value_, Index_ > > dense(bool row, std::shared_ptr< const Oracle< Index_ > > oracle, const Options &opt) const
Definition DelayedSubsetSortedUnique.hpp:303
std::unique_ptr< MyopicSparseExtractor< Value_, Index_ > > sparse(bool row, VectorPtr< Index_ > indices_ptr, const Options &opt) const
Definition DelayedSubsetSortedUnique.hpp:285
std::unique_ptr< OracularSparseExtractor< Value_, Index_ > > sparse(bool row, std::shared_ptr< const Oracle< Index_ > > oracle, const Options &opt) const
Definition DelayedSubsetSortedUnique.hpp:329
std::unique_ptr< MyopicSparseExtractor< Value_, Index_ > > sparse(bool row, const Options &opt) const
Definition DelayedSubsetSortedUnique.hpp:277
double is_sparse_proportion() const
Definition DelayedSubsetSortedUnique.hpp:217
DelayedSubsetSortedUnique(std::shared_ptr< const Matrix< Value_, Index_ > > matrix, SubsetStorage_ subset, bool by_row, bool check=true)
Definition DelayedSubsetSortedUnique.hpp:172
Index_ nrow() const
Definition DelayedSubsetSortedUnique.hpp:197
std::unique_ptr< MyopicSparseExtractor< Value_, Index_ > > sparse(bool row, Index_ block_start, Index_ block_length, const Options &opt) const
Definition DelayedSubsetSortedUnique.hpp:281
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 DelayedSubsetSortedUnique.hpp:333
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 DelayedSubsetSortedUnique.hpp:311
std::unique_ptr< MyopicDenseExtractor< Value_, Index_ > > dense(bool row, VectorPtr< Index_ > indices_ptr, const Options &opt) const
Definition DelayedSubsetSortedUnique.hpp:259
bool uses_oracle(bool row) const
Definition DelayedSubsetSortedUnique.hpp:229
std::unique_ptr< MyopicDenseExtractor< Value_, Index_ > > dense(bool row, const Options &opt) const
Definition DelayedSubsetSortedUnique.hpp:251
bool is_sparse() const
Definition DelayedSubsetSortedUnique.hpp:213
std::unique_ptr< MyopicDenseExtractor< Value_, Index_ > > dense(bool row, Index_ block_start, Index_ block_length, const Options &opt) const
Definition DelayedSubsetSortedUnique.hpp:255
bool prefer_rows() const
Definition DelayedSubsetSortedUnique.hpp:221
Virtual class for a matrix.
Definition Matrix.hpp:59
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_, OracularSparseExtractor< Value_, Index_ >, MyopicSparseExtractor< Value_, Index_ > >::type SparseExtractor
Definition Extractor.hpp:284
std::shared_ptr< const std::vector< Index_ > > VectorPtr
Definition Matrix.hpp:26
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