1#ifndef TATAMI_CONSTANT_MATRIX_HPP
2#define TATAMI_CONSTANT_MATRIX_HPP
4#include "../base/Matrix.hpp"
5#include "../dense/SparsifiedWrapper.hpp"
6#include "../utils/new_extractor.hpp"
22template<
bool oracle_,
typename Value_,
typename Index_>
25 DenseFiller(Index_ length, Value_ value) : my_length(length), my_value(value) {}
27 const Value_* fetch(Index_, Value_* buffer) {
28 std::fill_n(buffer, my_length, my_value);
36template<
bool oracle_,
typename Value_,
typename Index_>
39 SparseFiller(
const Options& opt) : my_needs_value(opt.sparse_extract_value), my_needs_index(opt.sparse_extract_index) {}
41 SparseRange<Value_, Index_> fetch(Index_, Value_* value_buffer, Index_* index_buffer) {
42 return SparseRange<Value_, Index_>(0, (my_needs_value ? value_buffer : NULL), (my_needs_index ? index_buffer : NULL));
63template<
typename Value_,
typename Index_>
91 return static_cast<double>(my_value == 0);
110 template<
bool oracle_>
112 return std::make_unique<ConstantMatrix_internal::DenseFiller<oracle_, Value_, Index_> >(
row ? my_ncol : my_nrow, my_value);
115 template<
bool oracle_>
117 return std::make_unique<ConstantMatrix_internal::DenseFiller<oracle_, Value_, Index_> >(
block_length, my_value);
120 template<
bool oracle_>
122 return std::make_unique<ConstantMatrix_internal::DenseFiller<oracle_, Value_, Index_> >(
indices_ptr->size(), my_value);
158 template<
bool oracle_>
161 return std::make_unique<ConstantMatrix_internal::SparseFiller<oracle_, Value_, Index_> >(
opt);
167 template<
bool oracle_>
170 return std::make_unique<ConstantMatrix_internal::SparseFiller<oracle_, Value_, Index_> >(
opt);
176 template<
bool oracle_>
179 return std::make_unique<ConstantMatrix_internal::SparseFiller<oracle_, Value_, Index_> >(
opt);
181 auto host = std::make_unique<ConstantMatrix_internal::DenseFiller<oracle_, Value_, Index_> >(
indices_ptr->size(), my_value);
182 return std::make_unique<IndexSparsifiedWrapper<oracle_, Value_, Index_> >(std::move(
host), std::move(
indices_ptr),
opt);
Matrix containing a constant value.
Definition ConstantMatrix.hpp:64
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 ConstantMatrix.hpp:207
bool is_sparse() const
Definition ConstantMatrix.hpp:86
std::unique_ptr< MyopicDenseExtractor< Value_, Index_ > > dense(bool row, Index_ block_start, Index_ block_length, const Options &opt) const
Definition ConstantMatrix.hpp:130
std::unique_ptr< MyopicSparseExtractor< Value_, Index_ > > sparse(bool row, const Options &opt) const
Definition ConstantMatrix.hpp:187
double is_sparse_proportion() const
Definition ConstantMatrix.hpp:90
Index_ nrow() const
Definition ConstantMatrix.hpp:78
double prefer_rows_proportion() const
Definition ConstantMatrix.hpp:98
std::unique_ptr< MyopicSparseExtractor< Value_, Index_ > > sparse(bool row, VectorPtr< Index_ > indices_ptr, const Options &opt) const
Definition ConstantMatrix.hpp:195
bool uses_oracle(bool) const
Definition ConstantMatrix.hpp:102
Index_ ncol() const
Definition ConstantMatrix.hpp:82
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 ConstantMatrix.hpp:150
std::unique_ptr< OracularSparseExtractor< Value_, Index_ > > sparse(bool row, std::shared_ptr< const Oracle< Index_ > > oracle, const Options &opt) const
Definition ConstantMatrix.hpp:203
std::unique_ptr< MyopicDenseExtractor< Value_, Index_ > > dense(bool row, VectorPtr< Index_ > indices_ptr, const Options &opt) const
Definition ConstantMatrix.hpp:134
ConstantMatrix(Index_ nrow, Index_ ncol, Value_ value)
Definition ConstantMatrix.hpp:71
std::unique_ptr< MyopicDenseExtractor< Value_, Index_ > > dense(bool row, const Options &opt) const
Definition ConstantMatrix.hpp:126
std::unique_ptr< MyopicSparseExtractor< Value_, Index_ > > sparse(bool row, Index_ block_start, Index_ block_length, const Options &opt) const
Definition ConstantMatrix.hpp:191
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 ConstantMatrix.hpp:146
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 ConstantMatrix.hpp:211
std::unique_ptr< OracularDenseExtractor< Value_, Index_ > > dense(bool row, std::shared_ptr< const Oracle< Index_ > > oracle, const Options &opt) const
Definition ConstantMatrix.hpp:142
bool prefer_rows() const
Definition ConstantMatrix.hpp:94
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_, 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
typename std::conditional< oracle_, std::shared_ptr< const Oracle< Index_ > >, bool >::type MaybeOracle
Definition new_extractor.hpp:20
std::shared_ptr< const std::vector< Index_ > > VectorPtr
Definition Matrix.hpp:26
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