1#ifndef TATAMI_COMPRESSED_SPARSE_MATRIX_H
2#define TATAMI_COMPRESSED_SPARSE_MATRIX_H
5#include "primary_extraction.hpp"
6#include "secondary_extraction.hpp"
30namespace CompressedSparseMatrix_internal {
36template<
typename Value_,
typename Index_,
class ValueStorage_,
class IndexStorage_,
class Po
interStorage_>
37class PrimaryMyopicFullDense final :
public MyopicDenseExtractor<Value_, Index_> {
39 PrimaryMyopicFullDense(
const ValueStorage_& values,
const IndexStorage_& indices,
const PointerStorage_& pointers, Index_ secondary) :
42 my_pointers(pointers),
43 my_secondary(secondary)
46 const Value_* fetch(Index_ i, Value_* buffer) {
47 auto start_pos = my_pointers[i], end_pos = my_pointers[i+1];
48 std::fill_n(buffer, my_secondary,
static_cast<Value_
>(0));
49 for (
auto x = start_pos; x < end_pos; ++x) {
50 buffer[my_indices[x]] = my_values[x];
56 const ValueStorage_& my_values;
57 const IndexStorage_& my_indices;
58 const PointerStorage_& my_pointers;
62template<
typename Value_,
typename Index_,
class ValueStorage_,
class IndexStorage_,
class Po
interStorage_>
63class PrimaryMyopicFullSparse final :
public MyopicSparseExtractor<Value_, Index_> {
65 PrimaryMyopicFullSparse(
const ValueStorage_& values,
const IndexStorage_& indices,
const PointerStorage_& pointers, Index_ secondary,
const Options& opt) :
68 my_pointers(pointers),
69 my_secondary(secondary),
70 my_needs_value(opt.sparse_extract_value),
71 my_needs_index(opt.sparse_extract_index)
74 SparseRange<Value_, Index_> fetch(Index_ i, Value_* value_buffer, Index_* index_buffer) {
75 auto offset = my_pointers[i];
76 decltype(offset) delta = my_pointers[i+1] - offset;
78 SparseRange<Value_, Index_> output(delta, NULL, NULL);
80 output.value = sparse_utils::extract_primary_vector(my_values, offset, delta, value_buffer);
83 output.index = sparse_utils::extract_primary_vector(my_indices, offset, delta, index_buffer);
89 const ValueStorage_& my_values;
90 const IndexStorage_& my_indices;
91 const PointerStorage_& my_pointers;
93 bool my_needs_value, my_needs_index;
100template<
typename Value_,
typename Index_,
class ValueStorage_,
class IndexStorage_,
class Po
interStorage_>
101class PrimaryMyopicBlockDense final :
public MyopicDenseExtractor<Value_, Index_> {
103 PrimaryMyopicBlockDense(
const ValueStorage_& values,
const IndexStorage_& indices,
const PointerStorage_& pointers, Index_ secondary, Index_ block_start, Index_ block_length) :
106 my_pointers(pointers),
107 my_secondary(secondary),
108 my_block_start(block_start),
109 my_block_length(block_length)
112 const Value_* fetch(Index_ i, Value_* buffer) {
113 auto iStart = my_indices.begin() + my_pointers[i];
114 auto iEnd = my_indices.begin() + my_pointers[i + 1];
115 sparse_utils::refine_primary_block_limits(iStart, iEnd, my_secondary, my_block_start, my_block_length);
116 auto start_pos = (iStart - my_indices.begin());
117 auto end_pos = (iEnd - my_indices.begin());
119 std::fill_n(buffer, my_block_length,
static_cast<Value_
>(0));
120 for (
auto x = start_pos; x < end_pos; ++x) {
121 buffer[my_indices[x] - my_block_start] = my_values[x];
127 const ValueStorage_& my_values;
128 const IndexStorage_& my_indices;
129 const PointerStorage_& my_pointers;
131 Index_ my_block_start, my_block_length;
134template<
typename Value_,
typename Index_,
class ValueStorage_,
class IndexStorage_,
class Po
interStorage_>
135class PrimaryMyopicBlockSparse final :
public MyopicSparseExtractor<Value_, Index_> {
137 PrimaryMyopicBlockSparse(
const ValueStorage_& values,
const IndexStorage_& indices,
const PointerStorage_& pointers, Index_ secondary, Index_ block_start, Index_ block_length,
const Options& opt) :
140 my_pointers(pointers),
141 my_secondary(secondary),
142 my_block_start(block_start),
143 my_block_length(block_length),
144 my_needs_value(opt.sparse_extract_value),
145 my_needs_index(opt.sparse_extract_index)
148 SparseRange<Value_, Index_> fetch(Index_ i, Value_* value_buffer, Index_* index_buffer) {
149 auto iStart = my_indices.begin() + my_pointers[i];
150 auto iEnd = my_indices.begin() + my_pointers[i + 1];
151 sparse_utils::refine_primary_block_limits(iStart, iEnd, my_secondary, my_block_start, my_block_length);
152 auto offset = iStart - my_indices.begin();
153 auto delta = iEnd - iStart;
155 SparseRange<Value_, Index_> output(delta, NULL, NULL);
156 if (my_needs_value) {
157 output.value = sparse_utils::extract_primary_vector(my_values, offset, delta, value_buffer);
159 if (my_needs_index) {
160 output.index = sparse_utils::extract_primary_vector(my_indices, offset, delta, index_buffer);
166 const ValueStorage_& my_values;
167 const IndexStorage_& my_indices;
168 const PointerStorage_& my_pointers;
170 Index_ my_block_start, my_block_length;
171 bool my_needs_value, my_needs_index;
178template<
typename Value_,
typename Index_,
class ValueStorage_,
class IndexStorage_,
class Po
interStorage_>
179class PrimaryMyopicIndexDense final :
public MyopicDenseExtractor<Value_, Index_> {
181 PrimaryMyopicIndexDense(
const ValueStorage_& values,
const IndexStorage_& indices,
const PointerStorage_& pointers, Index_ secondary,
const VectorPtr<Index_>& indices_ptr) :
184 my_pointers(pointers),
185 my_retriever(*indices_ptr, secondary),
186 my_num_indices(indices_ptr->size())
189 const Value_* fetch(Index_ i, Value_* buffer) {
190 std::fill_n(buffer, my_num_indices,
static_cast<Value_
>(0));
191 auto vIt = my_values.begin() + my_pointers[i];
192 my_retriever.populate(
193 my_indices.begin() + my_pointers[i],
194 my_indices.begin() + my_pointers[i+1],
195 [&](
auto s,
auto offset) ->
void {
196 buffer[s] = *(vIt + offset);
203 const ValueStorage_& my_values;
204 const IndexStorage_& my_indices;
205 const PointerStorage_& my_pointers;
206 sparse_utils::RetrievePrimarySubsetDense<Index_> my_retriever;
207 std::size_t my_num_indices;
210template<
typename Value_,
typename Index_,
class ValueStorage_,
class IndexStorage_,
class Po
interStorage_>
211class PrimaryMyopicIndexSparse final :
public MyopicSparseExtractor<Value_, Index_> {
213 PrimaryMyopicIndexSparse(
const ValueStorage_& values,
const IndexStorage_& indices,
const PointerStorage_& pointers, Index_ secondary,
const VectorPtr<Index_>& indices_ptr,
const Options& opt) :
216 my_pointers(pointers),
217 my_retriever(*indices_ptr, secondary),
218 my_needs_value(opt.sparse_extract_value),
219 my_needs_index(opt.sparse_extract_index) {}
221 SparseRange<Value_, Index_> fetch(Index_ i, Value_* value_buffer, Index_* index_buffer) {
223 auto vcopy = value_buffer;
224 auto icopy = index_buffer;
226 auto vIt = my_values.begin() + my_pointers[i];
227 my_retriever.populate(
228 my_indices.begin() + my_pointers[i],
229 my_indices.begin() + my_pointers[i+1],
230 [&](
auto offset,
auto ix) ->
void {
232 if (my_needs_value) {
233 *vcopy = *(vIt + offset);
236 if (my_needs_index) {
243 return SparseRange<Value_, Index_>(count, my_needs_value ? value_buffer : NULL, my_needs_index ? index_buffer : NULL);
247 const ValueStorage_& my_values;
248 const IndexStorage_& my_indices;
249 const PointerStorage_& my_pointers;
250 sparse_utils::RetrievePrimarySubsetSparse<Index_> my_retriever;
251 bool my_needs_value, my_needs_index;
258template<
typename Index_,
class IndexStorage_,
class Po
interStorage_>
261 ServeIndices(
const IndexStorage_& i,
const PointerStorage_& p) : my_indices(i), my_pointers(p) {}
264 const IndexStorage_& my_indices;
265 const PointerStorage_& my_pointers;
268 typedef ElementType<PointerStorage_> pointer_type;
270 pointer_type start_offset(Index_ primary)
const {
271 return my_pointers[primary];
274 pointer_type end_offset(Index_ primary)
const {
275 return my_pointers[primary + 1];
278 auto raw(Index_)
const {
279 return my_indices.begin();
283template<
typename Index_,
class IndexStorage_,
class Po
interStorage_>
284auto make_ServeIndices(
const IndexStorage_& i,
const PointerStorage_& p) {
285 return ServeIndices<Index_, IndexStorage_, PointerStorage_>(i, p);
288template<
typename Value_,
typename Index_,
class ValueStorage_,
class IndexStorage_,
class Po
interStorage_>
289class SecondaryMyopicFullDense final :
public MyopicDenseExtractor<Value_, Index_> {
291 SecondaryMyopicFullDense(
const ValueStorage_& values,
const IndexStorage_& indices,
const PointerStorage_& pointers, Index_ secondary) :
293 my_cache(make_ServeIndices<Index_>(indices, pointers), secondary, pointers.size() - 1)
296 const Value_* fetch(Index_ i, Value_* buffer) {
297 std::fill_n(buffer, my_cache.size(),
static_cast<Value_
>(0));
300 [&](Index_, Index_ index_primary,
auto ptr) ->
void {
301 buffer[index_primary] = my_values[ptr];
308 const ValueStorage_& my_values;
309 sparse_utils::FullSecondaryExtractionCache<Index_, ServeIndices<Index_, IndexStorage_, PointerStorage_> > my_cache;
312template<
typename Value_,
typename Index_,
class ValueStorage_,
class IndexStorage_,
class Po
interStorage_>
313class SecondaryMyopicFullSparse final :
public MyopicSparseExtractor<Value_, Index_> {
315 SecondaryMyopicFullSparse(
const ValueStorage_& values,
const IndexStorage_& indices,
const PointerStorage_& pointers, Index_ secondary,
const Options& opt) :
317 my_cache(make_ServeIndices<Index_>(indices, pointers), secondary, pointers.size() - 1),
318 my_needs_value(opt.sparse_extract_value),
319 my_needs_index(opt.sparse_extract_index)
322 SparseRange<Value_, Index_> fetch(Index_ i, Value_* value_buffer, Index_* index_buffer) {
324 my_cache.search(i, [&](Index_ primary, Index_, ElementType<PointerStorage_> ptr) ->
void {
325 if (my_needs_value) {
326 value_buffer[count] = my_values[ptr];
328 if (my_needs_index) {
329 index_buffer[count] = primary;
333 return SparseRange<Value_, Index_>(count, my_needs_value ? value_buffer : NULL, my_needs_index ? index_buffer : NULL);
337 const ValueStorage_& my_values;
338 sparse_utils::FullSecondaryExtractionCache<Index_, ServeIndices<Index_, IndexStorage_, PointerStorage_> > my_cache;
339 bool my_needs_value, my_needs_index;
346template<
typename Value_,
typename Index_,
class ValueStorage_,
class IndexStorage_,
class Po
interStorage_>
347class SecondaryMyopicBlockDense final :
public MyopicDenseExtractor<Value_, Index_> {
349 SecondaryMyopicBlockDense(
const ValueStorage_& values,
const IndexStorage_& indices,
const PointerStorage_& pointers, Index_ secondary, Index_ block_start, Index_ block_length) :
351 my_cache(make_ServeIndices<Index_>(indices, pointers), secondary, block_start, block_length)
354 const Value_* fetch(Index_ i, Value_* buffer) {
355 std::fill_n(buffer, my_cache.size(),
static_cast<Value_
>(0));
358 [&](Index_, Index_ index_primary,
auto ptr) ->
void {
359 buffer[index_primary] = my_values[ptr];
366 const ValueStorage_& my_values;
367 sparse_utils::BlockSecondaryExtractionCache<Index_, ServeIndices<Index_, IndexStorage_, PointerStorage_> > my_cache;
370template<
typename Value_,
typename Index_,
class ValueStorage_,
class IndexStorage_,
class Po
interStorage_>
371class SecondaryMyopicBlockSparse final :
public MyopicSparseExtractor<Value_, Index_> {
373 SecondaryMyopicBlockSparse(
const ValueStorage_& values,
const IndexStorage_& indices,
const PointerStorage_& pointers, Index_ secondary, Index_ block_start, Index_ block_length,
const Options& opt) :
375 my_cache(make_ServeIndices<Index_>(indices, pointers), secondary, block_start, block_length),
376 my_needs_value(opt.sparse_extract_value),
377 my_needs_index(opt.sparse_extract_index)
380 SparseRange<Value_, Index_> fetch(Index_ i, Value_* value_buffer, Index_* index_buffer) {
384 [&](Index_ primary, Index_,
auto ptr) ->
void {
385 if (my_needs_value) {
386 value_buffer[count] = my_values[ptr];
388 if (my_needs_index) {
389 index_buffer[count] = primary;
394 return SparseRange<Value_, Index_>(count, my_needs_value ? value_buffer : NULL, my_needs_index ? index_buffer : NULL);
398 const ValueStorage_& my_values;
399 sparse_utils::BlockSecondaryExtractionCache<Index_, ServeIndices<Index_, IndexStorage_, PointerStorage_> > my_cache;
400 bool my_needs_value, my_needs_index;
407template<
typename Value_,
typename Index_,
class ValueStorage_,
class IndexStorage_,
class Po
interStorage_>
408class SecondaryMyopicIndexDense final :
public MyopicDenseExtractor<Value_, Index_> {
410 SecondaryMyopicIndexDense(
const ValueStorage_& values,
const IndexStorage_& indices,
const PointerStorage_& pointers, Index_ secondary, VectorPtr<Index_> sub_ptr) :
411 my_values(values), my_cache(make_ServeIndices<Index_>(indices, pointers), secondary, std::move(sub_ptr)) {}
413 const Value_* fetch(Index_ i, Value_* buffer) {
414 std::fill_n(buffer, my_cache.size(),
static_cast<Value_
>(0));
417 [&](Index_, Index_ index_primary, ElementType<PointerStorage_> ptr) ->
void {
418 buffer[index_primary] = my_values[ptr];
425 const ValueStorage_& my_values;
426 sparse_utils::IndexSecondaryExtractionCache<Index_, ServeIndices<Index_, IndexStorage_, PointerStorage_> > my_cache;
429template<
typename Value_,
typename Index_,
class ValueStorage_,
class IndexStorage_,
class Po
interStorage_>
430class SecondaryMyopicIndexSparse final :
public MyopicSparseExtractor<Value_, Index_> {
432 SecondaryMyopicIndexSparse(
const ValueStorage_& values,
const IndexStorage_& indices,
const PointerStorage_& pointers, Index_ secondary, VectorPtr<Index_> sub_ptr,
const Options& opt) :
434 my_cache(make_ServeIndices<Index_>(indices, pointers), secondary, std::move(sub_ptr)),
435 my_needs_value(opt.sparse_extract_value),
436 my_needs_index(opt.sparse_extract_index)
439 SparseRange<Value_, Index_> fetch(Index_ i, Value_* value_buffer, Index_* index_buffer) {
443 [&](Index_ primary, Index_, ElementType<PointerStorage_> ptr) ->
void {
444 if (my_needs_value) {
445 value_buffer[count] = my_values[ptr];
447 if (my_needs_index) {
448 index_buffer[count] = primary;
453 return SparseRange<Value_, Index_>(count, my_needs_value ? value_buffer : NULL, my_needs_index ? index_buffer : NULL);
457 const ValueStorage_& my_values;
458 sparse_utils::IndexSecondaryExtractionCache<Index_, ServeIndices<Index_, IndexStorage_, PointerStorage_> > my_cache;
459 bool my_needs_value, my_needs_index;
502template<
typename Value_,
typename Index_,
class ValueStorage_,
class IndexStorage_,
class Po
interStorage_>
515 my_nrow(nrow), my_ncol(ncol), my_values(std::move(values)), my_indices(std::move(indices)), my_pointers(std::move(pointers)), my_csr(csr)
518 auto nnzero = my_values.size();
519 if (!safe_non_negative_equal(nnzero, my_indices.size())) {
520 throw std::runtime_error(
"'my_values' and 'my_indices' should be of the same length");
523 auto npointers = my_pointers.size();
524 auto check_pointers = [&](
auto dim) {
526 return npointers >= 1 && safe_non_negative_equal(npointers - 1, dim);
529 if (!check_pointers(my_nrow)) {
530 throw std::runtime_error(
"length of 'pointers' should be equal to 'nrow + 1'");
533 if (!check_pointers(my_ncol)){
534 throw std::runtime_error(
"length of 'pointers' should be equal to 'ncols + 1'");
538 if (my_pointers[0] != 0) {
539 throw std::runtime_error(
"first element of 'pointers' should be zero");
541 auto last = my_pointers[npointers - 1];
543 throw std::runtime_error(
"last element of 'pointers' should be equal to length of 'indices'");
547 for (
decltype(npointers) i = 1; i < npointers; ++i) {
548 auto start = my_pointers[i - 1], end = my_pointers[i];
549 if (end < start || end > last) {
550 throw std::runtime_error(
"'pointers' should be in non-decreasing order");
553 for (
auto x = start; x < end; ++x) {
554 if (my_indices[x] < 0 || my_indices[x] >= max_index) {
555 throw std::runtime_error(
"'indices' should contain non-negative integers less than the number of " + (my_csr ? std::string(
"columns") : std::string(
"rows")));
559 for (
decltype(start) j = start + 1; j < end; ++j) {
560 if (my_indices[j] <= my_indices[j - 1]) {
561 throw std::runtime_error(
"'indices' should be strictly increasing within each " + (my_csr ? std::string(
"row") : std::string(
"column")));
572 CompressedSparseMatrix(Index_ nrow, Index_ ncol, ValueStorage_ values, IndexStorage_ indices, PointerStorage_ pointers,
bool csr,
bool check =
true) :
573 CompressedSparseMatrix(
581 CompressedSparseMatrixOptions options;
582 options.check = check;
592 Index_ my_nrow, my_ncol;
593 ValueStorage_ my_values;
594 IndexStorage_ my_indices;
595 PointerStorage_ my_pointers;
599 Index_
nrow()
const {
return my_nrow; }
601 Index_
ncol()
const {
return my_ncol; }
613 using Matrix<Value_, Index_>::dense_row;
615 using Matrix<Value_, Index_>::dense_column;
617 using Matrix<Value_, Index_>::sparse_row;
619 using Matrix<Value_, Index_>::sparse_column;
622 Index_ secondary()
const {
634 std::unique_ptr<MyopicDenseExtractor<Value_, Index_> >
dense(
bool row,
const Options&)
const {
636 return std::make_unique<CompressedSparseMatrix_internal::PrimaryMyopicFullDense<Value_, Index_, ValueStorage_, IndexStorage_, PointerStorage_> >(
637 my_values, my_indices, my_pointers, secondary()
640 return std::make_unique<CompressedSparseMatrix_internal::SecondaryMyopicFullDense<Value_, Index_, ValueStorage_, IndexStorage_, PointerStorage_> >(
641 my_values, my_indices, my_pointers, secondary()
646 std::unique_ptr<MyopicDenseExtractor<Value_, Index_> >
dense(
bool row, Index_ block_start, Index_ block_end,
const Options&)
const {
648 return std::make_unique<CompressedSparseMatrix_internal::PrimaryMyopicBlockDense<Value_, Index_, ValueStorage_, IndexStorage_, PointerStorage_> >(
649 my_values, my_indices, my_pointers, secondary(), block_start, block_end
652 return std::make_unique<CompressedSparseMatrix_internal::SecondaryMyopicBlockDense<Value_, Index_, ValueStorage_, IndexStorage_, PointerStorage_> >(
653 my_values, my_indices, my_pointers, secondary(), block_start, block_end
660 return std::make_unique<CompressedSparseMatrix_internal::PrimaryMyopicIndexDense<Value_, Index_, ValueStorage_, IndexStorage_, PointerStorage_> >(
661 my_values, my_indices, my_pointers, secondary(), std::move(indices_ptr)
664 return std::make_unique<CompressedSparseMatrix_internal::SecondaryMyopicIndexDense<Value_, Index_, ValueStorage_, IndexStorage_, PointerStorage_> >(
665 my_values, my_indices, my_pointers, secondary(), std::move(indices_ptr)
674 std::unique_ptr<MyopicSparseExtractor<Value_, Index_> >
sparse(
bool row,
const Options& opt)
const {
676 return std::make_unique<CompressedSparseMatrix_internal::PrimaryMyopicFullSparse<Value_, Index_, ValueStorage_, IndexStorage_, PointerStorage_> >(
677 my_values, my_indices, my_pointers, secondary(), opt
680 return std::make_unique<CompressedSparseMatrix_internal::SecondaryMyopicFullSparse<Value_, Index_, ValueStorage_, IndexStorage_, PointerStorage_> >(
681 my_values, my_indices, my_pointers, secondary(), opt
686 std::unique_ptr<MyopicSparseExtractor<Value_, Index_> >
sparse(
bool row, Index_ block_start, Index_ block_end,
const Options& opt)
const {
688 return std::make_unique<CompressedSparseMatrix_internal::PrimaryMyopicBlockSparse<Value_, Index_, ValueStorage_, IndexStorage_, PointerStorage_> >(
689 my_values, my_indices, my_pointers, secondary(), block_start, block_end, opt
692 return std::make_unique<CompressedSparseMatrix_internal::SecondaryMyopicBlockSparse<Value_, Index_, ValueStorage_, IndexStorage_, PointerStorage_> >(
693 my_values, my_indices, my_pointers, secondary(), block_start, block_end, opt
700 return std::make_unique<CompressedSparseMatrix_internal::PrimaryMyopicIndexSparse<Value_, Index_, ValueStorage_, IndexStorage_, PointerStorage_> >(
701 my_values, my_indices, my_pointers, secondary(), std::move(indices_ptr), opt
704 return std::make_unique<CompressedSparseMatrix_internal::SecondaryMyopicIndexSparse<Value_, Index_, ValueStorage_, IndexStorage_, PointerStorage_> >(
705 my_values, my_indices, my_pointers, secondary(), std::move(indices_ptr), opt
714 std::unique_ptr<OracularDenseExtractor<Value_, Index_> >
dense(
bool row, std::shared_ptr<
const Oracle<Index_> > oracle,
const Options& opt)
const {
715 return std::make_unique<PseudoOracularDenseExtractor<Value_, Index_> >(std::move(oracle), dense(row, opt));
718 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 {
719 return std::make_unique<PseudoOracularDenseExtractor<Value_, Index_> >(std::move(oracle), dense(row, block_start, block_end, opt));
723 return std::make_unique<PseudoOracularDenseExtractor<Value_, Index_> >(std::move(oracle), dense(row, std::move(my_indices_ptr), opt));
730 std::unique_ptr<OracularSparseExtractor<Value_, Index_> >
sparse(
bool row, std::shared_ptr<
const Oracle<Index_> > oracle,
const Options& opt)
const {
731 return std::make_unique<PseudoOracularSparseExtractor<Value_, Index_> >(std::move(oracle), sparse(row, opt));
734 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 {
735 return std::make_unique<PseudoOracularSparseExtractor<Value_, Index_> >(std::move(oracle), sparse(row, block_start, block_end, opt));
739 return std::make_unique<PseudoOracularSparseExtractor<Value_, Index_> >(std::move(oracle), sparse(row, std::move(my_indices_ptr), opt));
748template<
typename Value_,
typename Index_,
class ValueStorage_ = std::vector<Value_>,
class IndexStorage_ = std::vector<Index_>,
class Po
interStorage_ = std::vector<std::
size_t> >
760 CompressedSparseMatrix<Value_, Index_, ValueStorage_, IndexStorage_, PointerStorage_>(nrow, ncol, std::move(values), std::move(indices), std::move(pointers), false, check) {}
768template<
typename Value_,
typename Index_,
class ValueStorage_ = std::vector<Value_>,
class IndexStorage_ = std::vector<Index_>,
class Po
interStorage_ = std::vector<std::
size_t> >
779 CompressedSparseRowMatrix(Index_ nrow, Index_ ncol, ValueStorage_ values, IndexStorage_ indices, PointerStorage_ pointers,
bool check =
true) :
780 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:749
CompressedSparseColumnMatrix(Index_ nrow, Index_ ncol, ValueStorage_ values, IndexStorage_ indices, PointerStorage_ pointers, bool check=true)
Definition CompressedSparseMatrix.hpp:759
Compressed sparse matrix representation.
Definition CompressedSparseMatrix.hpp:503
CompressedSparseMatrix(Index_ nrow, Index_ ncol, ValueStorage_ values, IndexStorage_ indices, PointerStorage_ pointers, bool csr, const CompressedSparseMatrixOptions &options)
Definition CompressedSparseMatrix.hpp:514
std::unique_ptr< OracularSparseExtractor< Value_, Index_ > > sparse(bool row, std::shared_ptr< const Oracle< Index_ > > oracle, const Options &opt) const
Definition CompressedSparseMatrix.hpp:730
std::unique_ptr< MyopicSparseExtractor< Value_, Index_ > > sparse(bool row, const Options &opt) const
Definition CompressedSparseMatrix.hpp:674
Index_ nrow() const
Definition CompressedSparseMatrix.hpp:599
bool prefer_rows() const
Definition CompressedSparseMatrix.hpp:607
double prefer_rows_proportion() const
Definition CompressedSparseMatrix.hpp:609
std::unique_ptr< MyopicSparseExtractor< Value_, Index_ > > sparse(bool row, Index_ block_start, Index_ block_end, const Options &opt) const
Definition CompressedSparseMatrix.hpp:686
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:738
bool uses_oracle(bool) const
Definition CompressedSparseMatrix.hpp:611
double is_sparse_proportion() const
Definition CompressedSparseMatrix.hpp:605
std::unique_ptr< MyopicDenseExtractor< Value_, Index_ > > dense(bool row, Index_ block_start, Index_ block_end, const Options &) const
Definition CompressedSparseMatrix.hpp:646
std::unique_ptr< OracularDenseExtractor< Value_, Index_ > > dense(bool row, std::shared_ptr< const Oracle< Index_ > > oracle, const Options &opt) const
Definition CompressedSparseMatrix.hpp:714
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:734
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:718
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:722
std::unique_ptr< MyopicDenseExtractor< Value_, Index_ > > dense(bool row, VectorPtr< Index_ > indices_ptr, const Options &) const
Definition CompressedSparseMatrix.hpp:658
bool is_sparse() const
Definition CompressedSparseMatrix.hpp:603
std::unique_ptr< MyopicSparseExtractor< Value_, Index_ > > sparse(bool row, VectorPtr< Index_ > indices_ptr, const Options &opt) const
Definition CompressedSparseMatrix.hpp:698
Index_ ncol() const
Definition CompressedSparseMatrix.hpp:601
std::unique_ptr< MyopicDenseExtractor< Value_, Index_ > > dense(bool row, const Options &) const
Definition CompressedSparseMatrix.hpp:634
Compressed sparse row matrix.
Definition CompressedSparseMatrix.hpp:769
CompressedSparseRowMatrix(Index_ nrow, Index_ ncol, ValueStorage_ values, IndexStorage_ indices, PointerStorage_ pointers, bool check=true)
Definition CompressedSparseMatrix.hpp:779
Virtual class for a matrix.
Definition Matrix.hpp:59
Predict future access requests on the target dimension.
Definition Oracle.hpp:23
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
bool safe_non_negative_equal(Left_ l, Right_ r)
Definition integer_comparisons.hpp:23
typename std::remove_cv< typename std::remove_reference< decltype(std::declval< Array_ >()[0])>::type >::type ElementType
Definition ElementType.hpp:17
Options for the CompressedSparseMatrix.
Definition CompressedSparseMatrix.hpp:470
bool check
Definition CompressedSparseMatrix.hpp:483
Options for accessing data from a Matrix instance.
Definition Options.hpp:30