1#ifndef TATAMI_CONVERT_TO_COMPRESSED_SPARSE_H
2#define TATAMI_CONVERT_TO_COMPRESSED_SPARSE_H
6#include "../utils/parallelize.hpp"
7#include "../utils/consecutive_extractor.hpp"
25template<
typename Value_,
typename Index_,
typename Count_>
29 opt.sparse_extract_value =
false;
30 opt.sparse_extract_index =
false;
31 opt.sparse_ordered_index =
false;
43 std::vector<Value_>
buffer_v(secondary);
57template<
typename Value_,
typename Index_,
typename Count_>
66 opt.sparse_extract_value =
false;
67 opt.sparse_ordered_index =
false;
70 std::vector<Index_>
buffer_i(primary);
85 std::vector<Value_>
buffer_v(primary);
104template<
typename InputValue_,
typename InputIndex_,
typename Po
inter_,
typename StoredValue_,
typename StoredIndex_>
115 if (
matrix->is_sparse()) {
117 opt.sparse_ordered_index =
false;
120 std::vector<InputValue_>
buffer_v(secondary);
121 std::vector<InputIndex_>
buffer_i(secondary);
139 std::vector<InputValue_>
buffer_v(secondary);
158template<
typename InputValue_,
typename InputIndex_,
typename Po
inter_,
typename StoredValue_,
typename StoredIndex_>
169 if (
matrix->is_sparse()) {
171 opt.sparse_ordered_index =
false;
232template<
typename Value_,
typename Index_,
typename Count_>
238 std::fill_n(
output, primary, 0);
241 convert_to_compressed_sparse_internal::count_compressed_sparse_non_zeros_consistent(
matrix, primary, secondary,
row,
output,
threads);
243 convert_to_compressed_sparse_internal::count_compressed_sparse_non_zeros_inconsistent(
matrix, primary, secondary,
row,
output,
threads);
266template<
typename InputValue_,
typename InputIndex_,
typename Po
inter_,
typename StoredValue_,
typename StoredIndex_>
297template<
typename Value_,
typename Index_,
typename Po
inter_ =
size_t>
333template<
typename StoredValue_,
typename StoredIndex_,
typename StoredPo
inter_ =
size_t,
typename InputValue_,
typename InputIndex_>
351 output_p.resize(
static_cast<size_t>(primary) + 1);
363 }
else if (
row ==
matrix->prefer_rows()) {
365 output_p.resize(
static_cast<size_t>(primary) + 1);
366 convert_to_compressed_sparse_internal::count_compressed_sparse_non_zeros_consistent(
matrix, primary, secondary,
row,
output_p.data() + 1,
threads);
374 convert_to_compressed_sparse_internal::fill_compressed_sparse_matrix_consistent(
387 output_p.resize(
static_cast<size_t>(primary) + 1);
388 convert_to_compressed_sparse_internal::count_compressed_sparse_non_zeros_inconsistent(
matrix, primary, secondary,
row,
output_p.data() + 1,
threads);
396 convert_to_compressed_sparse_internal::fill_compressed_sparse_matrix_inconsistent(
437 return std::shared_ptr<Matrix<Value_, Index_> >(
441 std::vector<StoredValue_>,
442 std::vector<StoredIndex_>,
447 std::move(
comp.value),
448 std::move(
comp.index),
449 std::move(
comp.pointers),
460template <
bool row_,
typename Value_,
typename Index_,
typename InputValue_,
typename InputIndex_>
465template <
bool row_,
typename Value_,
typename Index_,
typename StoredValue_ = Value_,
typename StoredIndex_ = Index_,
typename InputValue_,
typename InputIndex_>
Compressed sparse matrix representation.
Compressed sparse matrix representation.
Definition CompressedSparseMatrix.hpp:477
Virtual class for a matrix.
Definition Matrix.hpp:59
Convert a matrix into a fragmented sparse format.
Flexible representations for matrix data.
Definition Extractor.hpp:15
std::shared_ptr< Matrix< Value_, Index_ > > convert_to_compressed_sparse(const Matrix< InputValue_, InputIndex_ > *matrix, bool row, bool two_pass=false, int threads=1)
Definition convert_to_compressed_sparse.hpp:435
void parallelize(Function_ fun, Index_ tasks, int threads)
Definition parallelize.hpp:42
CompressedSparseContents< StoredValue_, StoredIndex_, StoredPointer_ > retrieve_compressed_sparse_contents(const Matrix< InputValue_, InputIndex_ > *matrix, bool row, bool two_pass, int threads=1)
Definition convert_to_compressed_sparse.hpp:334
void fill_compressed_sparse_contents(const tatami::Matrix< InputValue_, InputIndex_ > *matrix, bool row, const Pointer_ *pointers, StoredValue_ *output_value, StoredIndex_ *output_index, int threads)
Definition convert_to_compressed_sparse.hpp:267
void count_compressed_sparse_non_zeros(const tatami::Matrix< Value_, Index_ > *matrix, bool row, Count_ *output, int threads)
Definition convert_to_compressed_sparse.hpp:233
auto consecutive_extractor(const Matrix< Value_, Index_ > *mat, bool row, Index_ iter_start, Index_ iter_length, Args_ &&... args)
Definition consecutive_extractor.hpp:35
Compressed sparse contents.
Definition convert_to_compressed_sparse.hpp:298
std::vector< Index_ > index
Definition convert_to_compressed_sparse.hpp:307
std::vector< Value_ > value
Definition convert_to_compressed_sparse.hpp:302
std::vector< Pointer_ > pointers
Definition convert_to_compressed_sparse.hpp:312