1#ifndef TATAMI_COMPRESSED_SPARSE_MATRIX_H
2#define TATAMI_COMPRESSED_SPARSE_MATRIX_H
5#include "primary_extraction.hpp"
6#include "secondary_extraction.hpp"
29namespace CompressedSparseMatrix_internal {
35template<
typename Value_,
typename Index_,
class ValueStorage_,
class IndexStorage_,
class Po
interStorage_>
36class PrimaryMyopicFullDense :
public MyopicDenseExtractor<Value_, Index_> {
38 PrimaryMyopicFullDense(
const ValueStorage_& values,
const IndexStorage_& indices,
const PointerStorage_& pointers, Index_ secondary) :
41 my_pointers(pointers),
42 my_secondary(secondary)
45 const Value_* fetch(Index_ i, Value_* buffer) {
46 auto offset = my_pointers[i];
47 size_t delta = my_pointers[i+1] - my_pointers[i];
48 std::fill_n(buffer, my_secondary,
static_cast<Value_
>(0));
49 for (
size_t x = 0; x < delta; ++x) {
50 auto cur_offset = offset + x;
51 buffer[my_indices[cur_offset]] = my_values[cur_offset];
57 const ValueStorage_& my_values;
58 const IndexStorage_& my_indices;
59 const PointerStorage_& my_pointers;
63template<
typename Value_,
typename Index_,
class ValueStorage_,
class IndexStorage_,
class Po
interStorage_>
64class PrimaryMyopicFullSparse :
public MyopicSparseExtractor<Value_, Index_> {
66 PrimaryMyopicFullSparse(
const ValueStorage_& values,
const IndexStorage_& indices,
const PointerStorage_& pointers, Index_ secondary,
const Options& opt) :
69 my_pointers(pointers),
70 my_secondary(secondary),
71 my_needs_value(opt.sparse_extract_value),
72 my_needs_index(opt.sparse_extract_index)
75 SparseRange<Value_, Index_> fetch(Index_ i, Value_* value_buffer, Index_* index_buffer) {
76 auto offset = my_pointers[i];
77 auto delta = my_pointers[i+1] - my_pointers[i];
79 SparseRange<Value_, Index_> output(delta, NULL, NULL);
81 output.value = sparse_utils::extract_primary_vector(my_values, offset, delta, value_buffer);
84 output.index = sparse_utils::extract_primary_vector(my_indices, offset, delta, index_buffer);
90 const ValueStorage_& my_values;
91 const IndexStorage_& my_indices;
92 const PointerStorage_& my_pointers;
94 bool my_needs_value, my_needs_index;
101template<
typename Value_,
typename Index_,
class ValueStorage_,
class IndexStorage_,
class Po
interStorage_>
102class PrimaryMyopicBlockDense :
public MyopicDenseExtractor<Value_, Index_> {
104 PrimaryMyopicBlockDense(
const ValueStorage_& values,
const IndexStorage_& indices,
const PointerStorage_& pointers, Index_ secondary, Index_ block_start, Index_ block_length) :
107 my_pointers(pointers),
108 my_secondary(secondary),
109 my_block_start(block_start),
110 my_block_length(block_length)
113 const Value_* fetch(Index_ i, Value_* buffer) {
114 auto iStart = my_indices.begin() + my_pointers[i];
115 auto iEnd = my_indices.begin() + my_pointers[i + 1];
116 sparse_utils::refine_primary_block_limits(iStart, iEnd, my_secondary, my_block_start, my_block_length);
117 size_t offset = (iStart - my_indices.begin());
118 size_t number = iEnd - iStart;
120 std::fill_n(buffer, my_block_length,
static_cast<Value_
>(0));
121 for (
size_t i = 0; i < number; ++i) {
122 auto cur_offset = offset + i;
123 buffer[my_indices[cur_offset] - my_block_start] = my_values[cur_offset];
129 const ValueStorage_& my_values;
130 const IndexStorage_& my_indices;
131 const PointerStorage_& my_pointers;
133 Index_ my_block_start, my_block_length;
136template<
typename Value_,
typename Index_,
class ValueStorage_,
class IndexStorage_,
class Po
interStorage_>
137class PrimaryMyopicBlockSparse :
public MyopicSparseExtractor<Value_, Index_> {
139 PrimaryMyopicBlockSparse(
const ValueStorage_& values,
const IndexStorage_& indices,
const PointerStorage_& pointers, Index_ secondary, Index_ block_start, Index_ block_length,
const Options& opt) :
142 my_pointers(pointers),
143 my_secondary(secondary),
144 my_block_start(block_start),
145 my_block_length(block_length),
146 my_needs_value(opt.sparse_extract_value),
147 my_needs_index(opt.sparse_extract_index)
150 SparseRange<Value_, Index_> fetch(Index_ i, Value_* value_buffer, Index_* index_buffer) {
151 auto iStart = my_indices.begin() + my_pointers[i];
152 auto iEnd = my_indices.begin() + my_pointers[i + 1];
153 sparse_utils::refine_primary_block_limits(iStart, iEnd, my_secondary, my_block_start, my_block_length);
154 size_t offset = iStart - my_indices.begin();
155 size_t delta = iEnd - iStart;
157 SparseRange<Value_, Index_> output(delta, NULL, NULL);
158 if (my_needs_value) {
159 output.value = sparse_utils::extract_primary_vector(my_values, offset, delta, value_buffer);
161 if (my_needs_index) {
162 output.index = sparse_utils::extract_primary_vector(my_indices, offset, delta, index_buffer);
168 const ValueStorage_& my_values;
169 const IndexStorage_& my_indices;
170 const PointerStorage_& my_pointers;
172 Index_ my_block_start, my_block_length;
173 bool my_needs_value, my_needs_index;
180template<
typename Value_,
typename Index_,
class ValueStorage_,
class IndexStorage_,
class Po
interStorage_>
181class PrimaryMyopicIndexDense :
public MyopicDenseExtractor<Value_, Index_> {
183 PrimaryMyopicIndexDense(
const ValueStorage_& values,
const IndexStorage_& indices,
const PointerStorage_& pointers, Index_ secondary,
const VectorPtr<Index_>& indices_ptr) :
186 my_pointers(pointers),
187 my_retriever(*indices_ptr, secondary),
188 my_num_indices(indices_ptr->size())
191 const Value_* fetch(Index_ i, Value_* buffer) {
192 std::fill_n(buffer, my_num_indices,
static_cast<Value_
>(0));
193 auto vIt = my_values.begin() + my_pointers[i];
194 my_retriever.populate(
195 my_indices.begin() + my_pointers[i],
196 my_indices.begin() + my_pointers[i+1],
197 [&](
size_t s,
size_t offset) ->
void {
198 buffer[s] = *(vIt + offset);
205 const ValueStorage_& my_values;
206 const IndexStorage_& my_indices;
207 const PointerStorage_& my_pointers;
208 sparse_utils::RetrievePrimarySubsetDense<Index_> my_retriever;
209 size_t my_num_indices;
212template<
typename Value_,
typename Index_,
class ValueStorage_,
class IndexStorage_,
class Po
interStorage_>
213class PrimaryMyopicIndexSparse :
public MyopicSparseExtractor<Value_, Index_> {
215 PrimaryMyopicIndexSparse(
const ValueStorage_& values,
const IndexStorage_& indices,
const PointerStorage_& pointers, Index_ secondary,
const VectorPtr<Index_>& indices_ptr,
const Options& opt) :
218 my_pointers(pointers),
219 my_retriever(*indices_ptr, secondary),
220 my_needs_value(opt.sparse_extract_value),
221 my_needs_index(opt.sparse_extract_index) {}
223 SparseRange<Value_, Index_> fetch(Index_ i, Value_* value_buffer, Index_* index_buffer) {
225 auto vcopy = value_buffer;
226 auto icopy = index_buffer;
228 auto vIt = my_values.begin() + my_pointers[i];
229 my_retriever.populate(
230 my_indices.begin() + my_pointers[i],
231 my_indices.begin() + my_pointers[i+1],
232 [&](
size_t offset, Index_ ix) ->
void {
234 if (my_needs_value) {
235 *vcopy = *(vIt + offset);
238 if (my_needs_index) {
245 return SparseRange<Value_, Index_>(count, my_needs_value ? value_buffer : NULL, my_needs_index ? index_buffer : NULL);
249 const ValueStorage_& my_values;
250 const IndexStorage_& my_indices;
251 const PointerStorage_& my_pointers;
252 sparse_utils::RetrievePrimarySubsetSparse<Index_> my_retriever;
253 bool my_needs_value, my_needs_index;
260template<
typename Index_,
class IndexStorage_,
class Po
interStorage_>
263 ServeIndices(
const IndexStorage_& i,
const PointerStorage_& p) : my_indices(i), my_pointers(p) {}
266 const IndexStorage_& my_indices;
267 const PointerStorage_& my_pointers;
270 typedef ElementType<PointerStorage_> pointer_type;
272 pointer_type start_offset(Index_ primary)
const {
273 return my_pointers[primary];
276 pointer_type end_offset(Index_ primary)
const {
277 return my_pointers[primary + 1];
280 auto raw(Index_)
const {
281 return my_indices.begin();
285template<
typename Index_,
class IndexStorage_,
class Po
interStorage_>
286auto make_ServeIndices(
const IndexStorage_& i,
const PointerStorage_& p) {
287 return ServeIndices<Index_, IndexStorage_, PointerStorage_>(i, p);
290template<
typename Value_,
typename Index_,
class ValueStorage_,
class IndexStorage_,
class Po
interStorage_>
291class SecondaryMyopicFullDense :
public MyopicDenseExtractor<Value_, Index_> {
293 SecondaryMyopicFullDense(
const ValueStorage_& values,
const IndexStorage_& indices,
const PointerStorage_& pointers, Index_ secondary) :
295 my_cache(make_ServeIndices<Index_>(indices, pointers), secondary, pointers.size() - 1)
298 const Value_* fetch(Index_ i, Value_* buffer) {
299 std::fill_n(buffer, my_cache.size(),
static_cast<Value_
>(0));
302 [&](Index_, Index_ index_primary, ElementType<PointerStorage_> ptr) ->
void {
303 buffer[index_primary] = my_values[ptr];
310 const ValueStorage_& my_values;
311 sparse_utils::FullSecondaryExtractionCache<Index_, ServeIndices<Index_, IndexStorage_, PointerStorage_> > my_cache;
314template<
typename Value_,
typename Index_,
class ValueStorage_,
class IndexStorage_,
class Po
interStorage_>
315class SecondaryMyopicFullSparse :
public MyopicSparseExtractor<Value_, Index_> {
317 SecondaryMyopicFullSparse(
const ValueStorage_& values,
const IndexStorage_& indices,
const PointerStorage_& pointers, Index_ secondary,
const Options& opt) :
319 my_cache(make_ServeIndices<Index_>(indices, pointers), secondary, pointers.size() - 1),
320 my_needs_value(opt.sparse_extract_value),
321 my_needs_index(opt.sparse_extract_index)
324 SparseRange<Value_, Index_> fetch(Index_ i, Value_* value_buffer, Index_* index_buffer) {
326 my_cache.search(i, [&](Index_ primary, Index_, ElementType<PointerStorage_> ptr) ->
void {
327 if (my_needs_value) {
328 value_buffer[count] = my_values[ptr];
330 if (my_needs_index) {
331 index_buffer[count] = primary;
335 return SparseRange<Value_, Index_>(count, my_needs_value ? value_buffer : NULL, my_needs_index ? index_buffer : NULL);
339 const ValueStorage_& my_values;
340 sparse_utils::FullSecondaryExtractionCache<Index_, ServeIndices<Index_, IndexStorage_, PointerStorage_> > my_cache;
341 bool my_needs_value, my_needs_index;
348template<
typename Value_,
typename Index_,
class ValueStorage_,
class IndexStorage_,
class Po
interStorage_>
349class SecondaryMyopicBlockDense :
public MyopicDenseExtractor<Value_, Index_> {
351 SecondaryMyopicBlockDense(
const ValueStorage_& values,
const IndexStorage_& indices,
const PointerStorage_& pointers, Index_ secondary, Index_ block_start, Index_ block_length) :
353 my_cache(make_ServeIndices<Index_>(indices, pointers), secondary, block_start, block_length)
356 const Value_* fetch(Index_ i, Value_* buffer) {
357 std::fill_n(buffer, my_cache.size(),
static_cast<Value_
>(0));
360 [&](Index_, Index_ index_primary, ElementType<PointerStorage_> ptr) ->
void {
361 buffer[index_primary] = my_values[ptr];
368 const ValueStorage_& my_values;
369 sparse_utils::BlockSecondaryExtractionCache<Index_, ServeIndices<Index_, IndexStorage_, PointerStorage_> > my_cache;
372template<
typename Value_,
typename Index_,
class ValueStorage_,
class IndexStorage_,
class Po
interStorage_>
373class SecondaryMyopicBlockSparse :
public MyopicSparseExtractor<Value_, Index_> {
375 SecondaryMyopicBlockSparse(
const ValueStorage_& values,
const IndexStorage_& indices,
const PointerStorage_& pointers, Index_ secondary, Index_ block_start, Index_ block_length,
const Options& opt) :
377 my_cache(make_ServeIndices<Index_>(indices, pointers), secondary, block_start, block_length),
378 my_needs_value(opt.sparse_extract_value),
379 my_needs_index(opt.sparse_extract_index)
382 SparseRange<Value_, Index_> fetch(Index_ i, Value_* value_buffer, Index_* index_buffer) {
386 [&](Index_ primary, Index_, ElementType<PointerStorage_> ptr) ->
void {
387 if (my_needs_value) {
388 value_buffer[count] = my_values[ptr];
390 if (my_needs_index) {
391 index_buffer[count] = primary;
396 return SparseRange<Value_, Index_>(count, my_needs_value ? value_buffer : NULL, my_needs_index ? index_buffer : NULL);
400 const ValueStorage_& my_values;
401 sparse_utils::BlockSecondaryExtractionCache<Index_, ServeIndices<Index_, IndexStorage_, PointerStorage_> > my_cache;
402 bool my_needs_value, my_needs_index;
409template<
typename Value_,
typename Index_,
class ValueStorage_,
class IndexStorage_,
class Po
interStorage_>
410class SecondaryMyopicIndexDense :
public MyopicDenseExtractor<Value_, Index_> {
412 SecondaryMyopicIndexDense(
const ValueStorage_& values,
const IndexStorage_& indices,
const PointerStorage_& pointers, Index_ secondary, VectorPtr<Index_> sub_ptr) :
413 my_values(values), my_cache(make_ServeIndices<Index_>(indices, pointers), secondary, std::move(sub_ptr)) {}
415 const Value_* fetch(Index_ i, Value_* buffer) {
416 std::fill_n(buffer, my_cache.size(),
static_cast<Value_
>(0));
419 [&](Index_, Index_ index_primary, ElementType<PointerStorage_> ptr) ->
void {
420 buffer[index_primary] = my_values[ptr];
427 const ValueStorage_& my_values;
428 sparse_utils::IndexSecondaryExtractionCache<Index_, ServeIndices<Index_, IndexStorage_, PointerStorage_> > my_cache;
431template<
typename Value_,
typename Index_,
class ValueStorage_,
class IndexStorage_,
class Po
interStorage_>
432class SecondaryMyopicIndexSparse :
public MyopicSparseExtractor<Value_, Index_> {
434 SecondaryMyopicIndexSparse(
const ValueStorage_& values,
const IndexStorage_& indices,
const PointerStorage_& pointers, Index_ secondary, VectorPtr<Index_> sub_ptr,
const Options& opt) :
436 my_cache(make_ServeIndices<Index_>(indices, pointers), secondary, std::move(sub_ptr)),
437 my_needs_value(opt.sparse_extract_value),
438 my_needs_index(opt.sparse_extract_index)
441 SparseRange<Value_, Index_> fetch(Index_ i, Value_* value_buffer, Index_* index_buffer) {
445 [&](Index_ primary, Index_, ElementType<PointerStorage_> ptr) ->
void {
446 if (my_needs_value) {
447 value_buffer[count] = my_values[ptr];
449 if (my_needs_index) {
450 index_buffer[count] = primary;
455 return SparseRange<Value_, Index_>(count, my_needs_value ? value_buffer : NULL, my_needs_index ? index_buffer : NULL);
459 const ValueStorage_& my_values;
460 sparse_utils::IndexSecondaryExtractionCache<Index_, ServeIndices<Index_, IndexStorage_, PointerStorage_> > my_cache;
461 bool my_needs_value, my_needs_index;
488 class ValueStorage_ = std::vector<Value_>,
489 class IndexStorage_ = std::vector<Index_>,
490 class PointerStorage_ = std::vector<size_t>
509 CompressedSparseMatrix(Index_ nrow, Index_ ncol, ValueStorage_ values, IndexStorage_ indices, PointerStorage_ pointers,
bool csr,
bool check =
true) :
510 my_nrow(nrow), my_ncols(ncol), my_values(std::move(values)), my_indices(std::move(indices)), my_pointers(std::move(pointers)), my_csr(csr)
513 size_t nnzero = my_values.size();
514 if (nnzero != my_indices.size()) {
515 throw std::runtime_error(
"'my_values' and 'my_indices' should be of the same length");
518 size_t npointers = my_pointers.size();
520 if (npointers !=
static_cast<size_t>(my_nrow) + 1){
521 throw std::runtime_error(
"length of 'pointers' should be equal to 'nrow + 1'");
524 if (npointers !=
static_cast<size_t>(my_ncols) + 1){
525 throw std::runtime_error(
"length of 'pointers' should be equal to 'ncols + 1'");
529 if (my_pointers[0] != 0) {
530 throw std::runtime_error(
"first element of 'pointers' should be zero");
533 auto last = my_pointers[npointers - 1];
534 if (
static_cast<size_t>(last) != nnzero) {
535 throw std::runtime_error(
"last element of 'pointers' should be equal to length of 'indices'");
539 for (
size_t i = 1; i < npointers; ++i) {
540 auto start = my_pointers[i- 1], end = my_pointers[i];
541 if (end < start || end > last) {
542 throw std::runtime_error(
"'pointers' should be in non-decreasing order");
545 for (
auto x = start; x < end; ++x) {
546 if (my_indices[x] < 0 || my_indices[x] >= max_index) {
547 throw std::runtime_error(
"'indices' should contain non-negative integers less than the number of " + (my_csr ? std::string(
"columns") : std::string(
"rows")));
551 for (
decltype(start) j = start + 1; j < end; ++j) {
552 if (my_indices[j] <= my_indices[j - 1]) {
553 throw std::runtime_error(
"'indices' should be strictly increasing within each " + (my_csr ? std::string(
"row") : std::string(
"column")));
561 Index_ my_nrow, my_ncols;
562 ValueStorage_ my_values;
563 IndexStorage_ my_indices;
564 PointerStorage_ my_pointers;
568 Index_
nrow()
const {
return my_nrow; }
570 Index_
ncol()
const {
return my_ncols; }
582 using Matrix<Value_, Index_>::dense_row;
584 using Matrix<Value_, Index_>::dense_column;
586 using Matrix<Value_, Index_>::sparse_row;
588 using Matrix<Value_, Index_>::sparse_column;
591 Index_ secondary()
const {
603 std::unique_ptr<MyopicDenseExtractor<Value_, Index_> >
dense(
bool row,
const Options&)
const {
605 return std::make_unique<CompressedSparseMatrix_internal::PrimaryMyopicFullDense<Value_, Index_, ValueStorage_, IndexStorage_, PointerStorage_> >(
606 my_values, my_indices, my_pointers, secondary()
609 return std::make_unique<CompressedSparseMatrix_internal::SecondaryMyopicFullDense<Value_, Index_, ValueStorage_, IndexStorage_, PointerStorage_> >(
610 my_values, my_indices, my_pointers, secondary()
615 std::unique_ptr<MyopicDenseExtractor<Value_, Index_> >
dense(
bool row, Index_ block_start, Index_ block_end,
const Options&)
const {
617 return std::make_unique<CompressedSparseMatrix_internal::PrimaryMyopicBlockDense<Value_, Index_, ValueStorage_, IndexStorage_, PointerStorage_> >(
618 my_values, my_indices, my_pointers, secondary(), block_start, block_end
621 return std::make_unique<CompressedSparseMatrix_internal::SecondaryMyopicBlockDense<Value_, Index_, ValueStorage_, IndexStorage_, PointerStorage_> >(
622 my_values, my_indices, my_pointers, secondary(), block_start, block_end
629 return std::make_unique<CompressedSparseMatrix_internal::PrimaryMyopicIndexDense<Value_, Index_, ValueStorage_, IndexStorage_, PointerStorage_> >(
630 my_values, my_indices, my_pointers, secondary(), std::move(indices_ptr)
633 return std::make_unique<CompressedSparseMatrix_internal::SecondaryMyopicIndexDense<Value_, Index_, ValueStorage_, IndexStorage_, PointerStorage_> >(
634 my_values, my_indices, my_pointers, secondary(), std::move(indices_ptr)
643 std::unique_ptr<MyopicSparseExtractor<Value_, Index_> >
sparse(
bool row,
const Options& opt)
const {
645 return std::make_unique<CompressedSparseMatrix_internal::PrimaryMyopicFullSparse<Value_, Index_, ValueStorage_, IndexStorage_, PointerStorage_> >(
646 my_values, my_indices, my_pointers, secondary(), opt
649 return std::make_unique<CompressedSparseMatrix_internal::SecondaryMyopicFullSparse<Value_, Index_, ValueStorage_, IndexStorage_, PointerStorage_> >(
650 my_values, my_indices, my_pointers, secondary(), opt
655 std::unique_ptr<MyopicSparseExtractor<Value_, Index_> >
sparse(
bool row, Index_ block_start, Index_ block_end,
const Options& opt)
const {
657 return std::make_unique<CompressedSparseMatrix_internal::PrimaryMyopicBlockSparse<Value_, Index_, ValueStorage_, IndexStorage_, PointerStorage_> >(
658 my_values, my_indices, my_pointers, secondary(), block_start, block_end, opt
661 return std::make_unique<CompressedSparseMatrix_internal::SecondaryMyopicBlockSparse<Value_, Index_, ValueStorage_, IndexStorage_, PointerStorage_> >(
662 my_values, my_indices, my_pointers, secondary(), block_start, block_end, opt
669 return std::make_unique<CompressedSparseMatrix_internal::PrimaryMyopicIndexSparse<Value_, Index_, ValueStorage_, IndexStorage_, PointerStorage_> >(
670 my_values, my_indices, my_pointers, secondary(), std::move(indices_ptr), opt
673 return std::make_unique<CompressedSparseMatrix_internal::SecondaryMyopicIndexSparse<Value_, Index_, ValueStorage_, IndexStorage_, PointerStorage_> >(
674 my_values, my_indices, my_pointers, secondary(), std::move(indices_ptr), opt
683 std::unique_ptr<OracularDenseExtractor<Value_, Index_> >
dense(
bool row, std::shared_ptr<
const Oracle<Index_> > oracle,
const Options& opt)
const {
684 return std::make_unique<PseudoOracularDenseExtractor<Value_, Index_> >(std::move(oracle), dense(row, opt));
687 std::unique_ptr<OracularDenseExtractor<Value_, Index_> >
dense(
bool row, std::shared_ptr<
const Oracle<Index_> > oracle, Index_ block_start, Index_ block_end,
const Options& opt)
const {
688 return std::make_unique<PseudoOracularDenseExtractor<Value_, Index_> >(std::move(oracle), dense(row, block_start, block_end, opt));
692 return std::make_unique<PseudoOracularDenseExtractor<Value_, Index_> >(std::move(oracle), dense(row, std::move(my_indices_ptr), opt));
699 std::unique_ptr<OracularSparseExtractor<Value_, Index_> >
sparse(
bool row, std::shared_ptr<
const Oracle<Index_> > oracle,
const Options& opt)
const {
700 return std::make_unique<PseudoOracularSparseExtractor<Value_, Index_> >(std::move(oracle), sparse(row, opt));
703 std::unique_ptr<OracularSparseExtractor<Value_, Index_> >
sparse(
bool row, std::shared_ptr<
const Oracle<Index_> > oracle, Index_ block_start, Index_ block_end,
const Options& opt)
const {
704 return std::make_unique<PseudoOracularSparseExtractor<Value_, Index_> >(std::move(oracle), sparse(row, block_start, block_end, opt));
708 return std::make_unique<PseudoOracularSparseExtractor<Value_, Index_> >(std::move(oracle), sparse(row, std::move(my_indices_ptr), opt));
717template<
typename Value_,
typename Index_,
class ValueStorage_ = std::vector<Value_>,
class IndexStorage_ = std::vector<Index_>,
class Po
interStorage_ = std::vector<
size_t> >
729 CompressedSparseMatrix<Value_, Index_, ValueStorage_, IndexStorage_, PointerStorage_>(nrow, ncol, std::move(values), std::move(indices), std::move(pointers), false, check) {}
737template<
typename Value_,
typename Index_,
class ValueStorage_ = std::vector<Value_>,
class IndexStorage_ = std::vector<Index_>,
class Po
interStorage_ = std::vector<
size_t> >
748 CompressedSparseRowMatrix(Index_ nrow, Index_ ncol, ValueStorage_ values, IndexStorage_ indices, PointerStorage_ pointers,
bool check =
true) :
749 CompressedSparseMatrix<Value_, Index_, ValueStorage_, IndexStorage_, PointerStorage_>(nrow, ncol, std::move(values), std::move(indices), std::move(pointers), true, check) {}
Get type of elements in an array.
Virtual class for a matrix of some numeric type.
Compressed sparse column matrix.
Definition CompressedSparseMatrix.hpp:718
CompressedSparseColumnMatrix(Index_ nrow, Index_ ncol, ValueStorage_ values, IndexStorage_ indices, PointerStorage_ pointers, bool check=true)
Definition CompressedSparseMatrix.hpp:728
Compressed sparse matrix representation.
Definition CompressedSparseMatrix.hpp:492
std::unique_ptr< OracularSparseExtractor< Value_, Index_ > > sparse(bool row, std::shared_ptr< const Oracle< Index_ > > oracle, const Options &opt) const
Definition CompressedSparseMatrix.hpp:699
std::unique_ptr< MyopicSparseExtractor< Value_, Index_ > > sparse(bool row, const Options &opt) const
Definition CompressedSparseMatrix.hpp:643
Index_ nrow() const
Definition CompressedSparseMatrix.hpp:568
bool prefer_rows() const
Definition CompressedSparseMatrix.hpp:576
double prefer_rows_proportion() const
Definition CompressedSparseMatrix.hpp:578
std::unique_ptr< MyopicSparseExtractor< Value_, Index_ > > sparse(bool row, Index_ block_start, Index_ block_end, const Options &opt) const
Definition CompressedSparseMatrix.hpp:655
std::unique_ptr< OracularSparseExtractor< Value_, Index_ > > sparse(bool row, std::shared_ptr< const Oracle< Index_ > > oracle, VectorPtr< Index_ > my_indices_ptr, const Options &opt) const
Definition CompressedSparseMatrix.hpp:707
bool uses_oracle(bool) const
Definition CompressedSparseMatrix.hpp:580
CompressedSparseMatrix(Index_ nrow, Index_ ncol, ValueStorage_ values, IndexStorage_ indices, PointerStorage_ pointers, bool csr, bool check=true)
Definition CompressedSparseMatrix.hpp:509
double is_sparse_proportion() const
Definition CompressedSparseMatrix.hpp:574
std::unique_ptr< MyopicDenseExtractor< Value_, Index_ > > dense(bool row, Index_ block_start, Index_ block_end, const Options &) const
Definition CompressedSparseMatrix.hpp:615
std::unique_ptr< OracularDenseExtractor< Value_, Index_ > > dense(bool row, std::shared_ptr< const Oracle< Index_ > > oracle, const Options &opt) const
Definition CompressedSparseMatrix.hpp:683
std::unique_ptr< OracularSparseExtractor< Value_, Index_ > > sparse(bool row, std::shared_ptr< const Oracle< Index_ > > oracle, Index_ block_start, Index_ block_end, const Options &opt) const
Definition CompressedSparseMatrix.hpp:703
std::unique_ptr< OracularDenseExtractor< Value_, Index_ > > dense(bool row, std::shared_ptr< const Oracle< Index_ > > oracle, Index_ block_start, Index_ block_end, const Options &opt) const
Definition CompressedSparseMatrix.hpp:687
std::unique_ptr< OracularDenseExtractor< Value_, Index_ > > dense(bool row, std::shared_ptr< const Oracle< Index_ > > oracle, VectorPtr< Index_ > my_indices_ptr, const Options &opt) const
Definition CompressedSparseMatrix.hpp:691
std::unique_ptr< MyopicDenseExtractor< Value_, Index_ > > dense(bool row, VectorPtr< Index_ > indices_ptr, const Options &) const
Definition CompressedSparseMatrix.hpp:627
bool is_sparse() const
Definition CompressedSparseMatrix.hpp:572
std::unique_ptr< MyopicSparseExtractor< Value_, Index_ > > sparse(bool row, VectorPtr< Index_ > indices_ptr, const Options &opt) const
Definition CompressedSparseMatrix.hpp:667
Index_ ncol() const
Definition CompressedSparseMatrix.hpp:570
std::unique_ptr< MyopicDenseExtractor< Value_, Index_ > > dense(bool row, const Options &) const
Definition CompressedSparseMatrix.hpp:603
Compressed sparse row matrix.
Definition CompressedSparseMatrix.hpp:738
CompressedSparseRowMatrix(Index_ nrow, Index_ ncol, ValueStorage_ values, IndexStorage_ indices, PointerStorage_ pointers, bool check=true)
Definition CompressedSparseMatrix.hpp:748
Virtual class for a matrix.
Definition Matrix.hpp:59
Predict future access requests on the target dimension.
Definition Oracle.hpp:21
Compile-time checks for the data() method.
Flexible representations for matrix data.
Definition Extractor.hpp:15
std::shared_ptr< const std::vector< Index_ > > VectorPtr
Definition Matrix.hpp:26
typename std::remove_cv< typename std::remove_reference< decltype(std::declval< Array_ >()[0])>::type >::type ElementType
Definition ElementType.hpp:17
Options for accessing data from a Matrix instance.
Definition Options.hpp:30