1#ifndef TATAMI_CONVERT_TO_FRAGMENTED_SPARSE_H
2#define TATAMI_CONVERT_TO_FRAGMENTED_SPARSE_H
12#include "../utils/Index_to_container.hpp"
32template<
typename Value_,
typename Index_>
49 std::vector<std::vector<Value_> >
value;
56 std::vector<std::vector<Index_> >
index;
81template<
typename StoredValue_,
typename StoredIndex_,
typename InputValue_,
typename InputIndex_>
87 const InputIndex_ NR = matrix.
nrow();
88 const InputIndex_ NC = matrix.
ncol();
89 const InputIndex_ primary = (row ? NR : NC);
90 const InputIndex_ secondary = (row ? NC : NR);
93 auto& store_v = output.
value;
94 auto& store_i = output.
index;
98 parallelize([&](
const int,
const InputIndex_ start,
const InputIndex_ length) ->
void {
103 for (InputIndex_ p = start, pe = start + length; p < pe; ++p) {
104 const auto range = wrk->fetch(buffer_v.data(), buffer_i.data());
105 auto& sv = store_v[p];
106 auto& si = store_i[p];
107 sv.reserve(range.number);
108 si.reserve(range.number);
110 for (InputIndex_ i = 0; i < range.number; ++i) {
111 const auto val = range.value[i];
114 si.push_back(range.index[i]);
121 parallelize([&](
const int,
const InputIndex_ start,
const InputIndex_ length) ->
void {
127 for (InputIndex_ p = start, pe = start + length; p < pe; ++p) {
128 const auto ptr = wrk->fetch(buffer_v.data());
129 auto& sv = store_v[p];
130 auto& si = store_i[p];
132 for (InputIndex_ s = 0; s < secondary; ++s) {
133 const auto val = ptr[s];
150 parallelize([&](
const int,
const InputIndex_ start,
const InputIndex_ length) ->
void {
155 for (InputIndex_ x = 0; x < secondary; ++x) {
156 const auto range = wrk->fetch(buffer_v.data(), buffer_i.data());
157 for (InputIndex_ i = 0; i < range.number; ++i) {
158 const auto val = range.value[i];
160 const auto idx = range.index[i];
161 store_v[idx].push_back(val);
162 store_i[idx].push_back(x);
169 parallelize([&](
const int,
const InputIndex_ start,
const InputIndex_ length) ->
void {
173 for (InputIndex_ x = 0; x < secondary; ++x) {
174 const auto ptr = wrk->fetch(buffer_v.data());
175 for (InputIndex_ p = 0; p < length; ++p) {
176 const auto val = ptr[p];
178 const auto idx = p + start;
179 store_v[idx].push_back(val);
180 store_i[idx].push_back(x);
219 typename StoredValue_ = Value_,
220 typename StoredIndex_ = Index_,
221 typename InputValue_,
238 return std::shared_ptr<Matrix<Value_, Index_> >(
242 std::vector<std::vector<StoredValue_> >,
243 std::vector<std::vector<StoredIndex_> >
247 std::move(frag.value),
248 std::move(frag.index),
251 FragmentedSparseMatrixOptions fopt;
263template<
typename Value_,
typename Index_,
typename StoredValue_ = Value_,
typename StoredIndex_ = Index_,
typename InputValue_,
typename InputIndex_>
264std::shared_ptr<Matrix<Value_, Index_> >
convert_to_fragmented_sparse(
const Matrix<InputValue_, InputIndex_>* matrix,
bool row,
int threads = 1) {
269 ConvertToFragmentedSparseOptions opt;
270 opt.num_threads = threads;
276template<
typename StoredValue_,
typename StoredIndex_,
typename InputValue_,
typename InputIndex_>
282 RetrieveFragmentedSparseContentsOptions opt;
283 opt.num_threads = threads;
289template <
bool row_,
typename StoredValue_,
typename StoredIndex_,
typename InputValue_,
typename InputIndex_>
294template <
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:569
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
Copy data from one buffer to another.
Flexible representations for matrix data.
Definition Extractor.hpp:15
void parallelize(Function_ fun, const Index_ tasks, const int threads)
Definition parallelize.hpp:42
FragmentedSparseContents< StoredValue_, StoredIndex_ > retrieve_fragmented_sparse_contents(const Matrix< InputValue_, InputIndex_ > &matrix, const bool row, const RetrieveFragmentedSparseContentsOptions &options)
Definition convert_to_fragmented_sparse.hpp:82
I< decltype(std::declval< Container_ >().size())> cast_Index_to_container_size(const Index_ x)
Definition Index_to_container.hpp:56
std::shared_ptr< Matrix< Value_, Index_ > > convert_to_fragmented_sparse(const Matrix< InputValue_, InputIndex_ > &matrix, const bool row, const ConvertToFragmentedSparseOptions &options)
Definition convert_to_fragmented_sparse.hpp:224
Container_ create_container_of_Index_size(const Index_ x, Args_ &&... args)
Definition Index_to_container.hpp:73
auto consecutive_extractor(const Matrix< Value_, Index_ > &matrix, const bool row, const Index_ iter_start, const 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:194
int num_threads
Definition convert_to_fragmented_sparse.hpp:198
Fragmented sparse contents.
Definition convert_to_fragmented_sparse.hpp:33
std::vector< std::vector< Value_ > > value
Definition convert_to_fragmented_sparse.hpp:49
std::vector< std::vector< Index_ > > index
Definition convert_to_fragmented_sparse.hpp:56
Options for retrieve_fragmented_sparse_contents().
Definition convert_to_fragmented_sparse.hpp:62
int num_threads
Definition convert_to_fragmented_sparse.hpp:66