1#ifndef TATAMI_CONVERT_TO_FRAGMENTED_SPARSE_H
2#define TATAMI_CONVERT_TO_FRAGMENTED_SPARSE_H
7#include "../utils/Index_to_container.hpp"
31template<
typename Value_,
typename Index_>
48 std::vector<std::vector<Value_> >
value;
55 std::vector<std::vector<Index_> >
index;
80template<
typename StoredValue_,
typename StoredIndex_,
typename InputValue_,
typename InputIndex_>
86 InputIndex_ NR = matrix.
nrow();
87 InputIndex_ NC = matrix.
ncol();
88 InputIndex_ primary = (row ? NR : NC);
89 InputIndex_ secondary = (row ? NC : NR);
92 auto& store_v = output.
value;
93 auto& store_i = output.
index;
97 parallelize([&](
int, InputIndex_ start, InputIndex_ length) ->
void {
102 for (InputIndex_ p = start, pe = start + length; p < pe; ++p) {
103 auto range = wrk->fetch(buffer_v.data(), buffer_i.data());
104 auto& sv = store_v[p];
105 auto& si = store_i[p];
106 sv.reserve(range.number);
107 si.reserve(range.number);
109 for (InputIndex_ i = 0; i < range.number; ++i, ++range.value, ++range.index) {
111 sv.push_back(*range.value);
112 si.push_back(*range.index);
119 parallelize([&](
int, InputIndex_ start, InputIndex_ length) ->
void {
125 for (InputIndex_ p = start, pe = start + length; p < pe; ++p) {
126 auto ptr = wrk->fetch(buffer_v.data());
127 auto& sv = store_v[p];
128 auto& si = store_i[p];
130 for (InputIndex_ s = 0; s < secondary; ++s, ++ptr) {
147 parallelize([&](
int, InputIndex_ start, InputIndex_ length) ->
void {
152 for (InputIndex_ x = 0; x < secondary; ++x) {
153 auto range = wrk->fetch(buffer_v.data(), buffer_i.data());
154 for (InputIndex_ i = 0; i < range.number; ++i, ++range.value, ++range.index) {
156 store_v[*range.index].push_back(*range.value);
157 store_i[*range.index].push_back(x);
164 parallelize([&](
int, InputIndex_ start, InputIndex_ length) ->
void {
168 for (InputIndex_ x = 0; x < secondary; ++x) {
169 auto ptr = wrk->fetch(buffer_v.data());
170 for (InputIndex_ p = start, pe = start + length; p < pe; ++p, ++ptr) {
172 store_v[p].push_back(*ptr);
173 store_i[p].push_back(x);
212 typename StoredValue_ = Value_,
213 typename StoredIndex_ = Index_,
214 typename InputValue_,
231 return std::shared_ptr<Matrix<Value_, Index_> >(
235 std::vector<std::vector<StoredValue_> >,
236 std::vector<std::vector<StoredIndex_> >
240 std::move(frag.value),
241 std::move(frag.index),
244 FragmentedSparseMatrixOptions fopt;
256template<
typename Value_,
typename Index_,
typename StoredValue_ = Value_,
typename StoredIndex_ = Index_,
typename InputValue_,
typename InputIndex_>
257std::shared_ptr<Matrix<Value_, Index_> >
convert_to_fragmented_sparse(
const Matrix<InputValue_, InputIndex_>* matrix,
bool row,
int threads = 1) {
262 ConvertToFragmentedSparseOptions opt;
263 opt.num_threads = threads;
269template<
typename StoredValue_,
typename StoredIndex_,
typename InputValue_,
typename InputIndex_>
275 RetrieveFragmentedSparseContentsOptions opt;
276 opt.num_threads = threads;
282template <
bool row_,
typename StoredValue_,
typename StoredIndex_,
typename InputValue_,
typename InputIndex_>
287template <
bool row_,
typename Value_,
typename Index_,
typename StoredValue_ = Value_,
typename StoredIndex_ = Index_,
typename InputValue_,
typename InputIndex_>
Fragmented sparse matrix representation.
Fragmented sparse matrix representation.
Definition FragmentedSparseMatrix.hpp:464
Virtual class for a matrix.
Definition Matrix.hpp:59
virtual Index_ ncol() const =0
virtual Index_ nrow() const =0
virtual bool prefer_rows() const =0
virtual bool is_sparse() const =0
Flexible representations for matrix data.
Definition Extractor.hpp:15
Container_ create_container_of_Index_size(Index_ x)
Definition Index_to_container.hpp:69
decltype(std::declval< Container_ >().size()) cast_Index_to_container_size(Index_ x)
Definition Index_to_container.hpp:54
void parallelize(Function_ fun, Index_ tasks, int threads)
Definition parallelize.hpp:42
FragmentedSparseContents< StoredValue_, StoredIndex_ > retrieve_fragmented_sparse_contents(const Matrix< InputValue_, InputIndex_ > &matrix, bool row, const RetrieveFragmentedSparseContentsOptions &options)
Definition convert_to_fragmented_sparse.hpp:81
std::shared_ptr< Matrix< Value_, Index_ > > convert_to_fragmented_sparse(const Matrix< InputValue_, InputIndex_ > &matrix, bool row, const ConvertToFragmentedSparseOptions &options)
Definition convert_to_fragmented_sparse.hpp:217
auto consecutive_extractor(const Matrix< Value_, Index_ > &matrix, bool row, Index_ iter_start, Index_ iter_length, Args_ &&... args)
Definition consecutive_extractor.hpp:35
Parallelized iteration over a tatami::Matrix.
Options for convert_to_fragmented_sparse().
Definition convert_to_fragmented_sparse.hpp:187
int num_threads
Definition convert_to_fragmented_sparse.hpp:191
Fragmented sparse contents.
Definition convert_to_fragmented_sparse.hpp:32
std::vector< std::vector< Value_ > > value
Definition convert_to_fragmented_sparse.hpp:48
std::vector< std::vector< Index_ > > index
Definition convert_to_fragmented_sparse.hpp:55
Options for retrieve_fragmented_sparse_contents().
Definition convert_to_fragmented_sparse.hpp:61
int num_threads
Definition convert_to_fragmented_sparse.hpp:65