1#ifndef TATAMI_COMPRESSED_SPARSE_MATRIX_H
2#define TATAMI_COMPRESSED_SPARSE_MATRIX_H
11#include "sanisizer/sanisizer.hpp"
18#include "primary_extraction.hpp"
19#include "secondary_extraction.hpp"
32namespace CompressedSparseMatrix_internal {
38template<
typename Value_,
typename Index_,
class ValueStorage_,
class IndexStorage_,
class Po
interStorage_>
39class PrimaryMyopicFullDense final :
public MyopicDenseExtractor<Value_, Index_> {
41 PrimaryMyopicFullDense(
const ValueStorage_& values,
const IndexStorage_& indices,
const PointerStorage_& pointers,
const Index_ secondary) :
44 my_pointers(pointers),
45 my_secondary(secondary)
48 const Value_* fetch(
const Index_ i, Value_*
const buffer) {
49 const auto start_pos = my_pointers[i], end_pos = my_pointers[i+1];
50 std::fill_n(buffer, my_secondary,
static_cast<Value_
>(0));
51 for (
auto x = start_pos; x < end_pos; ++x) {
52 buffer[my_indices[x]] = my_values[x];
58 const ValueStorage_& my_values;
59 const IndexStorage_& my_indices;
60 const PointerStorage_& my_pointers;
64template<
typename Value_,
typename Index_,
class ValueStorage_,
class IndexStorage_,
class Po
interStorage_>
65class PrimaryMyopicFullSparse final :
public MyopicSparseExtractor<Value_, Index_> {
67 PrimaryMyopicFullSparse(
68 const ValueStorage_& values,
69 const IndexStorage_& indices,
70 const PointerStorage_& pointers,
71 const Index_ secondary,
76 my_pointers(pointers),
77 my_secondary(secondary),
78 my_needs_value(opt.sparse_extract_value),
79 my_needs_index(opt.sparse_extract_index)
82 SparseRange<Value_, Index_> fetch(
const Index_ i, Value_*
const value_buffer, Index_*
const index_buffer) {
83 const auto offset = my_pointers[i];
84 I<
decltype(offset)> delta = my_pointers[i+1] - offset;
86 SparseRange<Value_, Index_> output(delta, NULL, NULL);
88 output.value = sparse_utils::extract_primary_vector(my_values, offset, delta, value_buffer);
91 output.index = sparse_utils::extract_primary_vector(my_indices, offset, delta, index_buffer);
97 const ValueStorage_& my_values;
98 const IndexStorage_& my_indices;
99 const PointerStorage_& my_pointers;
101 bool my_needs_value, my_needs_index;
108template<
typename Value_,
typename Index_,
class ValueStorage_,
class IndexStorage_,
class Po
interStorage_>
109class PrimaryMyopicBlockDense final :
public MyopicDenseExtractor<Value_, Index_> {
111 PrimaryMyopicBlockDense(
112 const ValueStorage_& values,
113 const IndexStorage_& indices,
114 const PointerStorage_& pointers,
115 const Index_ secondary,
116 const Index_ block_start,
117 const Index_ block_length
121 my_pointers(pointers),
122 my_secondary(secondary),
123 my_block_start(block_start),
124 my_block_length(block_length)
127 const Value_* fetch(
const Index_ i, Value_*
const buffer) {
128 auto iStart = my_indices.begin() + my_pointers[i];
129 auto iEnd = my_indices.begin() + my_pointers[i + 1];
130 sparse_utils::refine_primary_block_limits(iStart, iEnd, my_secondary, my_block_start, my_block_length);
131 const auto start_pos = (iStart - my_indices.begin());
132 const auto end_pos = (iEnd - my_indices.begin());
134 std::fill_n(buffer, my_block_length,
static_cast<Value_
>(0));
135 for (
auto x = start_pos; x < end_pos; ++x) {
136 buffer[my_indices[x] - my_block_start] = my_values[x];
142 const ValueStorage_& my_values;
143 const IndexStorage_& my_indices;
144 const PointerStorage_& my_pointers;
146 Index_ my_block_start, my_block_length;
149template<
typename Value_,
typename Index_,
class ValueStorage_,
class IndexStorage_,
class Po
interStorage_>
150class PrimaryMyopicBlockSparse final :
public MyopicSparseExtractor<Value_, Index_> {
152 PrimaryMyopicBlockSparse(
153 const ValueStorage_& values,
154 const IndexStorage_& indices,
155 const PointerStorage_& pointers,
156 const Index_ secondary,
157 const Index_ block_start,
158 const Index_ block_length,
163 my_pointers(pointers),
164 my_secondary(secondary),
165 my_block_start(block_start),
166 my_block_length(block_length),
167 my_needs_value(opt.sparse_extract_value),
168 my_needs_index(opt.sparse_extract_index)
171 SparseRange<Value_, Index_> fetch(
const Index_ i, Value_*
const value_buffer, Index_*
const index_buffer) {
172 auto iStart = my_indices.begin() + my_pointers[i];
173 auto iEnd = my_indices.begin() + my_pointers[i + 1];
174 sparse_utils::refine_primary_block_limits(iStart, iEnd, my_secondary, my_block_start, my_block_length);
175 const auto offset = iStart - my_indices.begin();
176 const auto delta = iEnd - iStart;
178 SparseRange<Value_, Index_> output(delta, NULL, NULL);
179 if (my_needs_value) {
180 output.value = sparse_utils::extract_primary_vector(my_values, offset, delta, value_buffer);
182 if (my_needs_index) {
183 output.index = sparse_utils::extract_primary_vector(my_indices, offset, delta, index_buffer);
189 const ValueStorage_& my_values;
190 const IndexStorage_& my_indices;
191 const PointerStorage_& my_pointers;
193 Index_ my_block_start, my_block_length;
194 bool my_needs_value, my_needs_index;
201template<
typename Value_,
typename Index_,
class ValueStorage_,
class IndexStorage_,
class Po
interStorage_>
202class PrimaryMyopicIndexDense final :
public MyopicDenseExtractor<Value_, Index_> {
204 PrimaryMyopicIndexDense(
205 const ValueStorage_& values,
206 const IndexStorage_& indices,
207 const PointerStorage_& pointers,
208 const Index_ secondary,
209 const VectorPtr<Index_>& indices_ptr
213 my_pointers(pointers),
214 my_retriever(*indices_ptr, secondary),
215 my_num_indices(indices_ptr->size())
218 const Value_* fetch(
const Index_ i, Value_*
const buffer) {
219 std::fill_n(buffer, my_num_indices,
static_cast<Value_
>(0));
220 const auto vIt = my_values.begin() + my_pointers[i];
221 my_retriever.populate(
222 my_indices.begin() + my_pointers[i],
223 my_indices.begin() + my_pointers[i+1],
224 [&](
const auto s,
const auto offset) ->
void {
225 buffer[s] = *(vIt + offset);
232 const ValueStorage_& my_values;
233 const IndexStorage_& my_indices;
234 const PointerStorage_& my_pointers;
235 sparse_utils::RetrievePrimarySubsetDense<Index_> my_retriever;
236 std::size_t my_num_indices;
239template<
typename Value_,
typename Index_,
class ValueStorage_,
class IndexStorage_,
class Po
interStorage_>
240class PrimaryMyopicIndexSparse final :
public MyopicSparseExtractor<Value_, Index_> {
242 PrimaryMyopicIndexSparse(
243 const ValueStorage_& values,
244 const IndexStorage_& indices,
245 const PointerStorage_& pointers,
246 const Index_ secondary,
247 const VectorPtr<Index_>& indices_ptr,
252 my_pointers(pointers),
253 my_retriever(*indices_ptr, secondary),
254 my_needs_value(opt.sparse_extract_value),
255 my_needs_index(opt.sparse_extract_index) {}
257 SparseRange<Value_, Index_> fetch(
const Index_ i, Value_*
const value_buffer, Index_*
const index_buffer) {
259 auto vcopy = value_buffer;
260 auto icopy = index_buffer;
262 auto vIt = my_values.begin() + my_pointers[i];
263 my_retriever.populate(
264 my_indices.begin() + my_pointers[i],
265 my_indices.begin() + my_pointers[i+1],
266 [&](
const auto offset,
const auto ix) ->
void {
268 if (my_needs_value) {
269 *vcopy = *(vIt + offset);
272 if (my_needs_index) {
279 return SparseRange<Value_, Index_>(count, my_needs_value ? value_buffer : NULL, my_needs_index ? index_buffer : NULL);
283 const ValueStorage_& my_values;
284 const IndexStorage_& my_indices;
285 const PointerStorage_& my_pointers;
286 sparse_utils::RetrievePrimarySubsetSparse<Index_> my_retriever;
287 bool my_needs_value, my_needs_index;
294template<
typename Index_,
class IndexStorage_,
class Po
interStorage_>
297 ServeIndices(
const IndexStorage_& i,
const PointerStorage_& p) : my_indices(i), my_pointers(p) {}
300 const IndexStorage_& my_indices;
301 const PointerStorage_& my_pointers;
304 typedef ElementType<PointerStorage_> Pointer;
306 Pointer start_offset(
const Index_ primary)
const {
307 return my_pointers[primary];
310 Pointer end_offset(
const Index_ primary)
const {
311 return my_pointers[primary + 1];
314 auto raw(
const Index_)
const {
315 return my_indices.begin();
319template<
typename Index_,
class IndexStorage_,
class Po
interStorage_>
320auto make_ServeIndices(
const IndexStorage_& i,
const PointerStorage_& p) {
321 return ServeIndices<Index_, IndexStorage_, PointerStorage_>(i, p);
324template<
typename Value_,
typename Index_,
class ValueStorage_,
class IndexStorage_,
class Po
interStorage_>
325class SecondaryMyopicFullDense final :
public MyopicDenseExtractor<Value_, Index_> {
327 SecondaryMyopicFullDense(
328 const ValueStorage_& values,
329 const IndexStorage_& indices,
330 const PointerStorage_& pointers,
331 const Index_ secondary
334 my_cache(make_ServeIndices<Index_>(indices, pointers), secondary, pointers.size() - 1)
337 const Value_* fetch(
const Index_ i, Value_*
const buffer) {
338 std::fill_n(buffer, my_cache.size(),
static_cast<Value_
>(0));
341 [&](
const Index_,
const Index_ index_primary,
const auto ptr) ->
void {
342 buffer[index_primary] = my_values[ptr];
349 const ValueStorage_& my_values;
350 sparse_utils::FullSecondaryExtractionCache<Index_, ServeIndices<Index_, IndexStorage_, PointerStorage_> > my_cache;
353template<
typename Value_,
typename Index_,
class ValueStorage_,
class IndexStorage_,
class Po
interStorage_>
354class SecondaryMyopicFullSparse final :
public MyopicSparseExtractor<Value_, Index_> {
356 SecondaryMyopicFullSparse(
357 const ValueStorage_& values,
358 const IndexStorage_& indices,
359 const PointerStorage_& pointers,
360 const Index_ secondary,
364 my_cache(make_ServeIndices<Index_>(indices, pointers), secondary, pointers.size() - 1),
365 my_needs_value(opt.sparse_extract_value),
366 my_needs_index(opt.sparse_extract_index)
369 SparseRange<Value_, Index_> fetch(
const Index_ i, Value_*
const value_buffer, Index_*
const index_buffer) {
371 my_cache.search(i, [&](
const Index_ primary, Index_,
const ElementType<PointerStorage_> ptr) ->
void {
372 if (my_needs_value) {
373 value_buffer[count] = my_values[ptr];
375 if (my_needs_index) {
376 index_buffer[count] = primary;
380 return SparseRange<Value_, Index_>(count, my_needs_value ? value_buffer : NULL, my_needs_index ? index_buffer : NULL);
384 const ValueStorage_& my_values;
385 sparse_utils::FullSecondaryExtractionCache<Index_, ServeIndices<Index_, IndexStorage_, PointerStorage_> > my_cache;
386 bool my_needs_value, my_needs_index;
393template<
typename Value_,
typename Index_,
class ValueStorage_,
class IndexStorage_,
class Po
interStorage_>
394class SecondaryMyopicBlockDense final :
public MyopicDenseExtractor<Value_, Index_> {
396 SecondaryMyopicBlockDense(
397 const ValueStorage_& values,
398 const IndexStorage_& indices,
399 const PointerStorage_& pointers,
400 const Index_ secondary,
401 const Index_ block_start,
402 const Index_ block_length
405 my_cache(make_ServeIndices<Index_>(indices, pointers), secondary, block_start, block_length)
408 const Value_* fetch(
const Index_ i, Value_*
const buffer) {
409 std::fill_n(buffer, my_cache.size(),
static_cast<Value_
>(0));
412 [&](
const Index_,
const Index_ index_primary,
const auto ptr) ->
void {
413 buffer[index_primary] = my_values[ptr];
420 const ValueStorage_& my_values;
421 sparse_utils::BlockSecondaryExtractionCache<Index_, ServeIndices<Index_, IndexStorage_, PointerStorage_> > my_cache;
424template<
typename Value_,
typename Index_,
class ValueStorage_,
class IndexStorage_,
class Po
interStorage_>
425class SecondaryMyopicBlockSparse final :
public MyopicSparseExtractor<Value_, Index_> {
427 SecondaryMyopicBlockSparse(
428 const ValueStorage_& values,
429 const IndexStorage_& indices,
430 const PointerStorage_& pointers,
431 const Index_ secondary,
432 const Index_ block_start,
433 const Index_ block_length,
437 my_cache(make_ServeIndices<Index_>(indices, pointers), secondary, block_start, block_length),
438 my_needs_value(opt.sparse_extract_value),
439 my_needs_index(opt.sparse_extract_index)
442 SparseRange<Value_, Index_> fetch(
const Index_ i, Value_*
const value_buffer, Index_*
const index_buffer) {
446 [&](Index_ primary, Index_,
auto ptr) ->
void {
447 if (my_needs_value) {
448 value_buffer[count] = my_values[ptr];
450 if (my_needs_index) {
451 index_buffer[count] = primary;
456 return SparseRange<Value_, Index_>(count, my_needs_value ? value_buffer : NULL, my_needs_index ? index_buffer : NULL);
460 const ValueStorage_& my_values;
461 sparse_utils::BlockSecondaryExtractionCache<Index_, ServeIndices<Index_, IndexStorage_, PointerStorage_> > my_cache;
462 bool my_needs_value, my_needs_index;
469template<
typename Value_,
typename Index_,
class ValueStorage_,
class IndexStorage_,
class Po
interStorage_>
470class SecondaryMyopicIndexDense final :
public MyopicDenseExtractor<Value_, Index_> {
472 SecondaryMyopicIndexDense(
473 const ValueStorage_& values,
474 const IndexStorage_& indices,
475 const PointerStorage_& pointers,
476 const Index_ secondary,
477 VectorPtr<Index_> sub_ptr
480 my_cache(make_ServeIndices<Index_>(indices, pointers), secondary, std::move(sub_ptr))
483 const Value_* fetch(
const Index_ i, Value_*
const buffer) {
484 std::fill_n(buffer, my_cache.size(),
static_cast<Value_
>(0));
487 [&](
const Index_,
const Index_ index_primary,
const ElementType<PointerStorage_> ptr) ->
void {
488 buffer[index_primary] = my_values[ptr];
495 const ValueStorage_& my_values;
496 sparse_utils::IndexSecondaryExtractionCache<Index_, ServeIndices<Index_, IndexStorage_, PointerStorage_> > my_cache;
499template<
typename Value_,
typename Index_,
class ValueStorage_,
class IndexStorage_,
class Po
interStorage_>
500class SecondaryMyopicIndexSparse final :
public MyopicSparseExtractor<Value_, Index_> {
502 SecondaryMyopicIndexSparse(
503 const ValueStorage_& values,
504 const IndexStorage_& indices,
505 const PointerStorage_& pointers,
506 const Index_ secondary,
507 VectorPtr<Index_> sub_ptr,
511 my_cache(make_ServeIndices<Index_>(indices, pointers), secondary, std::move(sub_ptr)),
512 my_needs_value(opt.sparse_extract_value),
513 my_needs_index(opt.sparse_extract_index)
516 SparseRange<Value_, Index_> fetch(
const Index_ i, Value_*
const value_buffer, Index_*
const index_buffer) {
520 [&](Index_ primary, Index_, ElementType<PointerStorage_> ptr) ->
void {
521 if (my_needs_value) {
522 value_buffer[count] = my_values[ptr];
524 if (my_needs_index) {
525 index_buffer[count] = primary;
530 return SparseRange<Value_, Index_>(count, my_needs_value ? value_buffer : NULL, my_needs_index ? index_buffer : NULL);
534 const ValueStorage_& my_values;
535 sparse_utils::IndexSecondaryExtractionCache<Index_, ServeIndices<Index_, IndexStorage_, PointerStorage_> > my_cache;
536 bool my_needs_value, my_needs_index;
579template<
typename Value_,
typename Index_,
class ValueStorage_,
class IndexStorage_,
class Po
interStorage_>
594 ValueStorage_ values,
595 IndexStorage_ indices,
596 PointerStorage_ pointers,
602 my_values(std::move(values)),
603 my_indices(std::move(indices)),
604 my_pointers(std::move(pointers)),
608 const auto nnzero = my_values.size();
609 if (!safe_non_negative_equal(nnzero, my_indices.size())) {
610 throw std::runtime_error(
"'my_values' and 'my_indices' should be of the same length");
615 sanisizer::can_ptrdiff<I<
decltype(my_indices.begin())> >(nnzero);
617 const auto npointers = my_pointers.size();
618 const auto check_pointers = [&](
const auto dim) {
620 return npointers >= 1 && safe_non_negative_equal(npointers - 1, dim);
623 if (!check_pointers(my_nrow)) {
624 throw std::runtime_error(
"length of 'pointers' should be equal to 'nrow + 1'");
627 if (!check_pointers(my_ncol)){
628 throw std::runtime_error(
"length of 'pointers' should be equal to 'ncols + 1'");
632 if (my_pointers[0] != 0) {
633 throw std::runtime_error(
"first element of 'pointers' should be zero");
635 const auto last = my_pointers[npointers - 1];
636 if (!safe_non_negative_equal(nnzero, last)) {
637 throw std::runtime_error(
"last element of 'pointers' should be equal to length of 'indices'");
641 for (I<
decltype(npointers)> i = 1; i < npointers; ++i) {
642 const auto start = my_pointers[i - 1], end = my_pointers[i];
643 if (end < start || end > last) {
644 throw std::runtime_error(
"'pointers' should be in non-decreasing order");
647 for (
auto x = start; x < end; ++x) {
648 if (my_indices[x] < 0 || my_indices[x] >= max_index) {
649 throw std::runtime_error(
"'indices' should contain non-negative integers less than the number of " + (my_csr ? std::string(
"columns") : std::string(
"rows")));
653 for (I<
decltype(start)> j = start + 1; j < end; ++j) {
654 if (my_indices[j] <= my_indices[j - 1]) {
655 throw std::runtime_error(
"'indices' should be strictly increasing within each " + (my_csr ? std::string(
"row") : std::string(
"column")));
666 CompressedSparseMatrix(Index_ nrow, Index_ ncol, ValueStorage_ values, IndexStorage_ indices, PointerStorage_ pointers,
bool csr,
bool check =
true) :
667 CompressedSparseMatrix(
675 CompressedSparseMatrixOptions options;
676 options.check = check;
686 Index_ my_nrow, my_ncol;
687 ValueStorage_ my_values;
688 IndexStorage_ my_indices;
689 PointerStorage_ my_pointers;
693 Index_
nrow()
const {
return my_nrow; }
695 Index_
ncol()
const {
return my_ncol; }
707 using Matrix<Value_, Index_>::dense_row;
709 using Matrix<Value_, Index_>::dense_column;
711 using Matrix<Value_, Index_>::sparse_row;
713 using Matrix<Value_, Index_>::sparse_column;
716 Index_ secondary()
const {
728 std::unique_ptr<MyopicDenseExtractor<Value_, Index_> >
dense(
733 return std::make_unique<CompressedSparseMatrix_internal::PrimaryMyopicFullDense<Value_, Index_, ValueStorage_, IndexStorage_, PointerStorage_> >(
734 my_values, my_indices, my_pointers, secondary()
737 return std::make_unique<CompressedSparseMatrix_internal::SecondaryMyopicFullDense<Value_, Index_, ValueStorage_, IndexStorage_, PointerStorage_> >(
738 my_values, my_indices, my_pointers, secondary()
743 std::unique_ptr<MyopicDenseExtractor<Value_, Index_> >
dense(
745 const Index_ block_start,
746 const Index_ block_end,
750 return std::make_unique<CompressedSparseMatrix_internal::PrimaryMyopicBlockDense<Value_, Index_, ValueStorage_, IndexStorage_, PointerStorage_> >(
751 my_values, my_indices, my_pointers, secondary(), block_start, block_end
754 return std::make_unique<CompressedSparseMatrix_internal::SecondaryMyopicBlockDense<Value_, Index_, ValueStorage_, IndexStorage_, PointerStorage_> >(
755 my_values, my_indices, my_pointers, secondary(), block_start, block_end
760 std::unique_ptr<MyopicDenseExtractor<Value_, Index_> >
dense(
766 return std::make_unique<CompressedSparseMatrix_internal::PrimaryMyopicIndexDense<Value_, Index_, ValueStorage_, IndexStorage_, PointerStorage_> >(
767 my_values, my_indices, my_pointers, secondary(), std::move(indices_ptr)
770 return std::make_unique<CompressedSparseMatrix_internal::SecondaryMyopicIndexDense<Value_, Index_, ValueStorage_, IndexStorage_, PointerStorage_> >(
771 my_values, my_indices, my_pointers, secondary(), std::move(indices_ptr)
780 std::unique_ptr<MyopicSparseExtractor<Value_, Index_> >
sparse(
785 return std::make_unique<CompressedSparseMatrix_internal::PrimaryMyopicFullSparse<Value_, Index_, ValueStorage_, IndexStorage_, PointerStorage_> >(
786 my_values, my_indices, my_pointers, secondary(), opt
789 return std::make_unique<CompressedSparseMatrix_internal::SecondaryMyopicFullSparse<Value_, Index_, ValueStorage_, IndexStorage_, PointerStorage_> >(
790 my_values, my_indices, my_pointers, secondary(), opt
795 std::unique_ptr<MyopicSparseExtractor<Value_, Index_> >
sparse(
797 const Index_ block_start,
798 const Index_ block_end,
802 return std::make_unique<CompressedSparseMatrix_internal::PrimaryMyopicBlockSparse<Value_, Index_, ValueStorage_, IndexStorage_, PointerStorage_> >(
803 my_values, my_indices, my_pointers, secondary(), block_start, block_end, opt
806 return std::make_unique<CompressedSparseMatrix_internal::SecondaryMyopicBlockSparse<Value_, Index_, ValueStorage_, IndexStorage_, PointerStorage_> >(
807 my_values, my_indices, my_pointers, secondary(), block_start, block_end, opt
812 std::unique_ptr<MyopicSparseExtractor<Value_, Index_> >
sparse(
818 return std::make_unique<CompressedSparseMatrix_internal::PrimaryMyopicIndexSparse<Value_, Index_, ValueStorage_, IndexStorage_, PointerStorage_> >(
819 my_values, my_indices, my_pointers, secondary(), std::move(indices_ptr), opt
822 return std::make_unique<CompressedSparseMatrix_internal::SecondaryMyopicIndexSparse<Value_, Index_, ValueStorage_, IndexStorage_, PointerStorage_> >(
823 my_values, my_indices, my_pointers, secondary(), std::move(indices_ptr), opt
832 std::unique_ptr<OracularDenseExtractor<Value_, Index_> >
dense(
837 return std::make_unique<PseudoOracularDenseExtractor<Value_, Index_> >(std::move(oracle), dense(row, opt));
840 std::unique_ptr<OracularDenseExtractor<Value_, Index_> >
dense(
843 const Index_ block_start,
844 const Index_ block_end,
847 return std::make_unique<PseudoOracularDenseExtractor<Value_, Index_> >(std::move(oracle), dense(row, block_start, block_end, opt));
850 std::unique_ptr<OracularDenseExtractor<Value_, Index_> >
dense(
856 return std::make_unique<PseudoOracularDenseExtractor<Value_, Index_> >(std::move(oracle), dense(row, std::move(my_indices_ptr), opt));
863 std::unique_ptr<OracularSparseExtractor<Value_, Index_> >
sparse(
868 return std::make_unique<PseudoOracularSparseExtractor<Value_, Index_> >(std::move(oracle), sparse(row, opt));
871 std::unique_ptr<OracularSparseExtractor<Value_, Index_> >
sparse(
874 const Index_ block_start,
875 const Index_ block_end,
878 return std::make_unique<PseudoOracularSparseExtractor<Value_, Index_> >(std::move(oracle), sparse(row, block_start, block_end, opt));
881 std::unique_ptr<OracularSparseExtractor<Value_, Index_> >
sparse(
887 return std::make_unique<PseudoOracularSparseExtractor<Value_, Index_> >(std::move(oracle), sparse(row, std::move(my_indices_ptr), opt));
896template<
typename Value_,
typename Index_,
class ValueStorage_ = std::vector<Value_>,
class IndexStorage_ = std::vector<Index_>,
class Po
interStorage_ = std::vector<std::
size_t> >
908 CompressedSparseMatrix<Value_, Index_, ValueStorage_, IndexStorage_, PointerStorage_>(nrow, ncol, std::move(values), std::move(indices), std::move(pointers), false, check) {}
916template<
typename Value_,
typename Index_,
class ValueStorage_ = std::vector<Value_>,
class IndexStorage_ = std::vector<Index_>,
class Po
interStorage_ = std::vector<std::
size_t> >
927 CompressedSparseRowMatrix(Index_ nrow, Index_ ncol, ValueStorage_ values, IndexStorage_ indices, PointerStorage_ pointers,
bool check =
true) :
928 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:897
CompressedSparseColumnMatrix(Index_ nrow, Index_ ncol, ValueStorage_ values, IndexStorage_ indices, PointerStorage_ pointers, bool check=true)
Definition CompressedSparseMatrix.hpp:907
Compressed sparse matrix representation.
Definition CompressedSparseMatrix.hpp:580
std::unique_ptr< OracularSparseExtractor< Value_, Index_ > > sparse(const bool row, std::shared_ptr< const Oracle< Index_ > > oracle, VectorPtr< Index_ > my_indices_ptr, const Options &opt) const
Definition CompressedSparseMatrix.hpp:881
std::unique_ptr< OracularSparseExtractor< Value_, Index_ > > sparse(const bool row, std::shared_ptr< const Oracle< Index_ > > oracle, const Options &opt) const
Definition CompressedSparseMatrix.hpp:863
std::unique_ptr< OracularDenseExtractor< Value_, Index_ > > dense(const bool row, std::shared_ptr< const Oracle< Index_ > > oracle, const Index_ block_start, const Index_ block_end, const Options &opt) const
Definition CompressedSparseMatrix.hpp:840
std::unique_ptr< OracularSparseExtractor< Value_, Index_ > > sparse(const bool row, std::shared_ptr< const Oracle< Index_ > > oracle, const Index_ block_start, const Index_ block_end, const Options &opt) const
Definition CompressedSparseMatrix.hpp:871
Index_ nrow() const
Definition CompressedSparseMatrix.hpp:693
bool prefer_rows() const
Definition CompressedSparseMatrix.hpp:701
std::unique_ptr< MyopicDenseExtractor< Value_, Index_ > > dense(const bool row, const Index_ block_start, const Index_ block_end, const Options &) const
Definition CompressedSparseMatrix.hpp:743
double prefer_rows_proportion() const
Definition CompressedSparseMatrix.hpp:703
CompressedSparseMatrix(const Index_ nrow, const Index_ ncol, ValueStorage_ values, IndexStorage_ indices, PointerStorage_ pointers, const bool csr, const CompressedSparseMatrixOptions &options)
Definition CompressedSparseMatrix.hpp:591
std::unique_ptr< OracularDenseExtractor< Value_, Index_ > > dense(const bool row, std::shared_ptr< const Oracle< Index_ > > oracle, VectorPtr< Index_ > my_indices_ptr, const Options &opt) const
Definition CompressedSparseMatrix.hpp:850
bool uses_oracle(const bool) const
Definition CompressedSparseMatrix.hpp:705
std::unique_ptr< MyopicSparseExtractor< Value_, Index_ > > sparse(const bool row, const Options &opt) const
Definition CompressedSparseMatrix.hpp:780
double is_sparse_proportion() const
Definition CompressedSparseMatrix.hpp:699
std::unique_ptr< MyopicSparseExtractor< Value_, Index_ > > sparse(const bool row, VectorPtr< Index_ > indices_ptr, const Options &opt) const
Definition CompressedSparseMatrix.hpp:812
std::unique_ptr< MyopicDenseExtractor< Value_, Index_ > > dense(const bool row, VectorPtr< Index_ > indices_ptr, const Options &) const
Definition CompressedSparseMatrix.hpp:760
std::unique_ptr< MyopicSparseExtractor< Value_, Index_ > > sparse(const bool row, const Index_ block_start, const Index_ block_end, const Options &opt) const
Definition CompressedSparseMatrix.hpp:795
std::unique_ptr< OracularDenseExtractor< Value_, Index_ > > dense(const bool row, std::shared_ptr< const Oracle< Index_ > > oracle, const Options &opt) const
Definition CompressedSparseMatrix.hpp:832
bool is_sparse() const
Definition CompressedSparseMatrix.hpp:697
Index_ ncol() const
Definition CompressedSparseMatrix.hpp:695
std::unique_ptr< MyopicDenseExtractor< Value_, Index_ > > dense(const bool row, const Options &) const
Definition CompressedSparseMatrix.hpp:728
Compressed sparse row matrix.
Definition CompressedSparseMatrix.hpp:917
CompressedSparseRowMatrix(Index_ nrow, Index_ ncol, ValueStorage_ values, IndexStorage_ indices, PointerStorage_ pointers, bool check=true)
Definition CompressedSparseMatrix.hpp:927
Virtual class for a matrix.
Definition Matrix.hpp:59
Predict future access requests on the target dimension.
Definition Oracle.hpp:29
Copy data from one buffer to another.
Flexible representations for matrix data.
Definition Extractor.hpp:15
std::shared_ptr< const std::vector< Index_ > > VectorPtr
Definition Matrix.hpp:26
I< decltype(std::declval< Array_ >()[0])> ElementType
Definition ElementType.hpp:19
Options for the CompressedSparseMatrix.
Definition CompressedSparseMatrix.hpp:547
bool check
Definition CompressedSparseMatrix.hpp:560
Options for accessing data from a Matrix instance.
Definition Options.hpp:30