1#ifndef TATAMI_CONVERT_TO_FRAGMENTED_SPARSE_H
2#define TATAMI_CONVERT_TO_FRAGMENTED_SPARSE_H
30template<
typename Value_,
typename Index_>
44 std::vector<std::vector<Value_> >
value;
51 std::vector<std::vector<Index_> >
index;
76template<
typename StoredValue_,
typename StoredIndex_,
typename InputValue_,
typename InputIndex_>
82 InputIndex_ NR = matrix.
nrow();
83 InputIndex_ NC = matrix.
ncol();
84 InputIndex_ primary = (row ? NR : NC);
85 InputIndex_ secondary = (row ? NC : NR);
88 auto& store_v = output.
value;
89 auto& store_i = output.
index;
93 parallelize([&](
int, InputIndex_ start, InputIndex_ length) ->
void {
94 std::vector<InputValue_> buffer_v(secondary);
95 std::vector<InputIndex_> buffer_i(secondary);
98 for (InputIndex_ p = start, pe = start + length; p < pe; ++p) {
99 auto range = wrk->fetch(buffer_v.data(), buffer_i.data());
100 auto& sv = store_v[p];
101 auto& si = store_i[p];
102 sv.reserve(range.number);
103 si.reserve(range.number);
105 for (InputIndex_ i = 0; i < range.number; ++i, ++range.value, ++range.index) {
107 sv.push_back(*range.value);
108 si.push_back(*range.index);
115 parallelize([&](
int, InputIndex_ start, InputIndex_ length) ->
void {
116 std::vector<InputValue_> buffer_v(secondary);
121 for (InputIndex_ p = start, pe = start + length; p < pe; ++p) {
122 auto ptr = wrk->fetch(buffer_v.data());
123 auto& sv = store_v[p];
124 auto& si = store_i[p];
126 for (InputIndex_ s = 0; s < secondary; ++s, ++ptr) {
143 parallelize([&](
int, InputIndex_ start, InputIndex_ length) ->
void {
144 std::vector<InputValue_> buffer_v(primary);
145 std::vector<InputIndex_> buffer_i(primary);
148 for (InputIndex_ x = 0; x < secondary; ++x) {
149 auto range = wrk->fetch(buffer_v.data(), buffer_i.data());
150 for (InputIndex_ i = 0; i < range.number; ++i, ++range.value, ++range.index) {
152 store_v[*range.index].push_back(*range.value);
153 store_i[*range.index].push_back(x);
160 parallelize([&](
int, InputIndex_ start, InputIndex_ length) ->
void {
162 std::vector<InputValue_> buffer_v(length);
164 for (InputIndex_ x = 0; x < secondary; ++x) {
165 auto ptr = wrk->fetch(buffer_v.data());
166 for (InputIndex_ p = start, pe = start + length; p < pe; ++p, ++ptr) {
168 store_v[p].push_back(*ptr);
169 store_i[p].push_back(x);
208 typename StoredValue_ = Value_,
209 typename StoredIndex_ = Index_,
210 typename InputValue_,
227 return std::shared_ptr<Matrix<Value_, Index_> >(
231 std::vector<std::vector<StoredValue_> >,
232 std::vector<std::vector<StoredIndex_> >
236 std::move(frag.value),
237 std::move(frag.index),
240 FragmentedSparseMatrixOptions fopt;
252template<
typename Value_,
typename Index_,
typename StoredValue_ = Value_,
typename StoredIndex_ = Index_,
typename InputValue_,
typename InputIndex_>
253std::shared_ptr<Matrix<Value_, Index_> >
convert_to_fragmented_sparse(
const Matrix<InputValue_, InputIndex_>* matrix,
bool row,
int threads = 1) {
258 ConvertToFragmentedSparseOptions opt;
259 opt.num_threads = threads;
265template<
typename StoredValue_,
typename StoredIndex_,
typename InputValue_,
typename InputIndex_>
271 RetrieveFragmentedSparseContentsOptions opt;
272 opt.num_threads = threads;
278template <
bool row_,
typename StoredValue_,
typename StoredIndex_,
typename InputValue_,
typename InputIndex_>
283template <
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
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:77
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:213
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:183
int num_threads
Definition convert_to_fragmented_sparse.hpp:187
Fragmented sparse contents.
Definition convert_to_fragmented_sparse.hpp:31
std::vector< std::vector< Value_ > > value
Definition convert_to_fragmented_sparse.hpp:44
std::vector< std::vector< Index_ > > index
Definition convert_to_fragmented_sparse.hpp:51
Options for retrieve_fragmented_sparse_contents().
Definition convert_to_fragmented_sparse.hpp:57
int num_threads
Definition convert_to_fragmented_sparse.hpp:61