1#ifndef TATAMI_CONVERT_TO_FRAGMENTED_SPARSE_H
2#define TATAMI_CONVERT_TO_FRAGMENTED_SPARSE_H
29template<
typename Value_,
typename Index_>
43 std::vector<std::vector<Value_> >
value;
50 std::vector<std::vector<Index_> >
index;
75template<
typename StoredValue_,
typename StoredIndex_,
typename InputValue_,
typename InputIndex_>
81 InputIndex_ NR = matrix.
nrow();
82 InputIndex_ NC = matrix.
ncol();
83 InputIndex_ primary = (row ? NR : NC);
84 InputIndex_ secondary = (row ? NC : NR);
87 auto& store_v = output.
value;
88 auto& store_i = output.
index;
92 parallelize([&](
int, InputIndex_ start, InputIndex_ length) ->
void {
93 std::vector<InputValue_> buffer_v(secondary);
94 std::vector<InputIndex_> buffer_i(secondary);
97 for (InputIndex_ p = start, pe = start + length; p < pe; ++p) {
98 auto range = wrk->fetch(buffer_v.data(), buffer_i.data());
99 auto& sv = store_v[p];
100 auto& si = store_i[p];
101 sv.reserve(range.number);
102 si.reserve(range.number);
104 for (InputIndex_ i = 0; i < range.number; ++i, ++range.value, ++range.index) {
106 sv.push_back(*range.value);
107 si.push_back(*range.index);
114 parallelize([&](
int, InputIndex_ start, InputIndex_ length) ->
void {
115 std::vector<InputValue_> buffer_v(secondary);
120 for (InputIndex_ p = start, pe = start + length; p < pe; ++p) {
121 auto ptr = wrk->fetch(buffer_v.data());
122 auto& sv = store_v[p];
123 auto& si = store_i[p];
125 for (InputIndex_ s = 0; s < secondary; ++s, ++ptr) {
142 parallelize([&](
int, InputIndex_ start, InputIndex_ length) ->
void {
143 std::vector<InputValue_> buffer_v(primary);
144 std::vector<InputIndex_> buffer_i(primary);
147 for (InputIndex_ x = 0; x < secondary; ++x) {
148 auto range = wrk->fetch(buffer_v.data(), buffer_i.data());
149 for (InputIndex_ i = 0; i < range.number; ++i, ++range.value, ++range.index) {
151 store_v[*range.index].push_back(*range.value);
152 store_i[*range.index].push_back(x);
159 parallelize([&](
int, InputIndex_ start, InputIndex_ length) ->
void {
161 std::vector<InputValue_> buffer_v(length);
163 for (InputIndex_ x = 0; x < secondary; ++x) {
164 auto ptr = wrk->fetch(buffer_v.data());
165 for (InputIndex_ p = start, pe = start + length; p < pe; ++p, ++ptr) {
167 store_v[p].push_back(*ptr);
168 store_i[p].push_back(x);
207 typename StoredValue_ = Value_,
208 typename StoredIndex_ = Index_,
209 typename InputValue_,
226 return std::shared_ptr<Matrix<Value_, Index_> >(
230 std::vector<std::vector<StoredValue_> >,
231 std::vector<std::vector<StoredIndex_> >
235 std::move(frag.value),
236 std::move(frag.index),
239 FragmentedSparseMatrixOptions fopt;
251template<
typename Value_,
typename Index_,
typename StoredValue_ = Value_,
typename StoredIndex_ = Index_,
typename InputValue_,
typename InputIndex_>
252std::shared_ptr<Matrix<Value_, Index_> >
convert_to_fragmented_sparse(
const Matrix<InputValue_, InputIndex_>* matrix,
bool row,
int threads = 1) {
257 ConvertToFragmentedSparseOptions opt;
258 opt.num_threads = threads;
264template<
typename StoredValue_,
typename StoredIndex_,
typename InputValue_,
typename InputIndex_>
270 RetrieveFragmentedSparseContentsOptions opt;
271 opt.num_threads = threads;
277template <
bool row_,
typename StoredValue_,
typename StoredIndex_,
typename InputValue_,
typename InputIndex_>
282template <
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:465
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:76
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:212
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:182
int num_threads
Definition convert_to_fragmented_sparse.hpp:186
Fragmented sparse contents.
Definition convert_to_fragmented_sparse.hpp:30
std::vector< std::vector< Value_ > > value
Definition convert_to_fragmented_sparse.hpp:43
std::vector< std::vector< Index_ > > index
Definition convert_to_fragmented_sparse.hpp:50
Options for retrieve_fragmented_sparse_contents().
Definition convert_to_fragmented_sparse.hpp:56
int num_threads
Definition convert_to_fragmented_sparse.hpp:60