1#ifndef TATAMI_CONSTANT_MATRIX_HPP
2#define TATAMI_CONSTANT_MATRIX_HPP
20namespace ConstantMatrix_internal {
22template<
bool oracle_,
typename Value_,
typename Index_>
23class DenseFiller final :
public DenseExtractor<oracle_, Value_, Index_> {
25 DenseFiller(
const Index_ length,
const Value_ value) : my_length(length), my_value(value) {}
27 const Value_* fetch(
const Index_, Value_*
const buffer) {
28 std::fill_n(buffer, my_length, my_value);
36template<
bool oracle_,
typename Value_,
typename Index_>
37class SparseFiller final :
public SparseExtractor<oracle_, Value_, 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(
const Index_, Value_*
const value_buffer, Index_*
const 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_>
74 Index_ my_nrow, my_ncol;
91 return static_cast<double>(my_value == 0);
110 template<
bool oracle_>
111 std::unique_ptr<DenseExtractor<oracle_, Value_, Index_> > dense_internal(
116 return std::make_unique<ConstantMatrix_internal::DenseFiller<oracle_, Value_, Index_> >(row ? my_ncol : my_nrow, my_value);
119 template<
bool oracle_>
120 std::unique_ptr<DenseExtractor<oracle_, Value_, Index_> > dense_internal(
123 [[maybe_unused]]
const Index_ block_start,
124 const Index_ block_length,
127 return std::make_unique<ConstantMatrix_internal::DenseFiller<oracle_, Value_, Index_> >(block_length, my_value);
130 template<
bool oracle_>
131 std::unique_ptr<DenseExtractor<oracle_, Value_, Index_> > dense_internal(
137 return std::make_unique<ConstantMatrix_internal::DenseFiller<oracle_, Value_, Index_> >(indices_ptr->size(), my_value);
141 std::unique_ptr<MyopicDenseExtractor<Value_, Index_> >
dense(
145 return dense_internal<false>(row,
false, opt);
148 std::unique_ptr<MyopicDenseExtractor<Value_, Index_> >
dense(
150 const Index_ block_start,
151 const Index_ block_length,
154 return dense_internal<false>(row,
false, block_start, block_length, opt);
157 std::unique_ptr<MyopicDenseExtractor<Value_, Index_> >
dense(
162 return dense_internal<false>(row,
false, std::move(indices_ptr), opt);
169 std::unique_ptr<OracularDenseExtractor<Value_, Index_> >
dense(
174 return dense_internal<true>(row, std::move(oracle), opt);
177 std::unique_ptr<OracularDenseExtractor<Value_, Index_> >
dense(
180 const Index_ block_start,
181 const Index_ block_length,
184 return dense_internal<true>(row, std::move(oracle), block_start, block_length, opt);
187 std::unique_ptr<OracularDenseExtractor<Value_, Index_> >
dense(
193 return dense_internal<true>(row, std::move(oracle), std::move(indices_ptr), opt);
200 template<
bool oracle_>
201 std::unique_ptr<SparseExtractor<oracle_, Value_, Index_> > sparse_internal(
207 return std::make_unique<ConstantMatrix_internal::SparseFiller<oracle_, Value_, Index_> >(opt);
209 return std::make_unique<FullSparsifiedWrapper<oracle_, Value_, Index_> >(
210 dense_internal<oracle_>(row, std::move(oracle), opt),
211 (row ? my_ncol : my_nrow),
217 template<
bool oracle_>
218 std::unique_ptr<SparseExtractor<oracle_, Value_, Index_> > sparse_internal(
221 const Index_ block_start,
222 const Index_ block_length,
226 return std::make_unique<ConstantMatrix_internal::SparseFiller<oracle_, Value_, Index_> >(opt);
228 return std::make_unique<BlockSparsifiedWrapper<oracle_, Value_, Index_> >(
229 dense_internal<oracle_>(row, std::move(oracle), block_start, block_length, opt),
237 template<
bool oracle_>
238 std::unique_ptr<SparseExtractor<oracle_, Value_, Index_> > sparse_internal(
245 return std::make_unique<ConstantMatrix_internal::SparseFiller<oracle_, Value_, Index_> >(opt);
247 return std::make_unique<IndexSparsifiedWrapper<oracle_, Value_, Index_> >(
248 std::make_unique<ConstantMatrix_internal::DenseFiller<oracle_, Value_, Index_> >(indices_ptr->size(), my_value),
249 std::move(indices_ptr),
256 std::unique_ptr<MyopicSparseExtractor<Value_, Index_> >
sparse(
260 return sparse_internal<false>(row,
false, opt);
263 std::unique_ptr<MyopicSparseExtractor<Value_, Index_> >
sparse(
265 const Index_ block_start,
266 const Index_ block_length,
269 return sparse_internal<false>(row,
false, block_start, block_length, opt);
272 std::unique_ptr<MyopicSparseExtractor<Value_, Index_> >
sparse(
277 return sparse_internal<false>(row,
false, std::move(indices_ptr), opt);
284 std::unique_ptr<OracularSparseExtractor<Value_, Index_> >
sparse(
289 return sparse_internal<true>(row, std::move(oracle), opt);
292 std::unique_ptr<OracularSparseExtractor<Value_, Index_> >
sparse(
295 const Index_ block_start,
296 const Index_ block_length,
299 return sparse_internal<true>(row, std::move(oracle), block_start, block_length, opt);
302 std::unique_ptr<OracularSparseExtractor<Value_, Index_> >
sparse(
308 return sparse_internal<true>(row, std::move(oracle), std::move(indices_ptr), opt);
Virtual class for a matrix of some numeric type.
Wrapper classes for sparse extraction from a dense tatami::Matrix.
Matrix containing a constant value.
Definition ConstantMatrix.hpp:64
std::unique_ptr< MyopicSparseExtractor< Value_, Index_ > > sparse(const bool row, const Options &opt) const
Definition ConstantMatrix.hpp:256
bool is_sparse() const
Definition ConstantMatrix.hpp:86
ConstantMatrix(const Index_ nrow, const Index_ ncol, const Value_ value)
Definition ConstantMatrix.hpp:71
std::unique_ptr< MyopicSparseExtractor< Value_, Index_ > > sparse(const bool row, VectorPtr< Index_ > indices_ptr, const Options &opt) const
Definition ConstantMatrix.hpp:272
std::unique_ptr< MyopicSparseExtractor< Value_, Index_ > > sparse(const bool row, const Index_ block_start, const Index_ block_length, const Options &opt) const
Definition ConstantMatrix.hpp:263
std::unique_ptr< OracularDenseExtractor< Value_, Index_ > > dense(const bool row, std::shared_ptr< const Oracle< Index_ > > oracle, const Options &opt) const
Definition ConstantMatrix.hpp:169
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< OracularSparseExtractor< Value_, Index_ > > sparse(const bool row, std::shared_ptr< const Oracle< Index_ > > oracle, const Index_ block_start, const Index_ block_length, const Options &opt) const
Definition ConstantMatrix.hpp:292
Index_ ncol() const
Definition ConstantMatrix.hpp:82
std::unique_ptr< OracularSparseExtractor< Value_, Index_ > > sparse(const bool row, std::shared_ptr< const Oracle< Index_ > > oracle, const Options &opt) const
Definition ConstantMatrix.hpp:284
std::unique_ptr< MyopicDenseExtractor< Value_, Index_ > > dense(const bool row, const Options &opt) const
Definition ConstantMatrix.hpp:141
std::unique_ptr< OracularSparseExtractor< Value_, Index_ > > sparse(const bool row, std::shared_ptr< const Oracle< Index_ > > oracle, VectorPtr< Index_ > indices_ptr, const Options &opt) const
Definition ConstantMatrix.hpp:302
std::unique_ptr< MyopicDenseExtractor< Value_, Index_ > > dense(const bool row, VectorPtr< Index_ > indices_ptr, const Options &opt) const
Definition ConstantMatrix.hpp:157
std::unique_ptr< OracularDenseExtractor< Value_, Index_ > > dense(const bool row, std::shared_ptr< const Oracle< Index_ > > oracle, const Index_ block_start, const Index_ block_length, const Options &opt) const
Definition ConstantMatrix.hpp:177
bool uses_oracle(const bool) const
Definition ConstantMatrix.hpp:102
std::unique_ptr< MyopicDenseExtractor< Value_, Index_ > > dense(const bool row, const Index_ block_start, const Index_ block_length, const Options &opt) const
Definition ConstantMatrix.hpp:148
std::unique_ptr< OracularDenseExtractor< Value_, Index_ > > dense(const bool row, std::shared_ptr< const Oracle< Index_ > > oracle, VectorPtr< Index_ > indices_ptr, const Options &opt) const
Definition ConstantMatrix.hpp:187
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:29
Flexible representations for matrix data.
Definition Extractor.hpp:15
std::shared_ptr< const std::vector< Index_ > > VectorPtr
Definition Matrix.hpp:26
typename std::conditional< oracle_, std::shared_ptr< const Oracle< Index_ > >, bool >::type MaybeOracle
Definition new_extractor.hpp:20
typename std::conditional< oracle_, OracularDenseExtractor< Value_, Index_ >, MyopicDenseExtractor< Value_, Index_ > >::type DenseExtractor
Definition Extractor.hpp:273
Options for accessing data from a Matrix instance.
Definition Options.hpp:30