1#ifndef TATAMI_COMPRESSED_SPARSE_MATRIX_H
2#define TATAMI_COMPRESSED_SPARSE_MATRIX_H
11#include "sanisizer/sanisizer.hpp"
19#include "primary_extraction.hpp"
20#include "secondary_extraction.hpp"
33namespace CompressedSparseMatrix_internal {
39template<
typename Value_,
typename Index_,
class ValueStorage_,
class IndexStorage_,
class Po
interStorage_>
40class PrimaryMyopicFullDense final :
public MyopicDenseExtractor<Value_, Index_> {
42 PrimaryMyopicFullDense(
const ValueStorage_& values,
const IndexStorage_& indices,
const PointerStorage_& pointers,
const Index_ secondary) :
45 my_pointers(pointers),
46 my_secondary(secondary)
49 const Value_* fetch(
const Index_ i, Value_*
const buffer) {
50 const auto start_pos = my_pointers[i], end_pos = my_pointers[i+1];
51 std::fill_n(buffer, my_secondary,
static_cast<Value_
>(0));
52 for (
auto x = start_pos; x < end_pos; ++x) {
53 buffer[my_indices[x]] = my_values[x];
59 const ValueStorage_& my_values;
60 const IndexStorage_& my_indices;
61 const PointerStorage_& my_pointers;
65template<
typename Value_,
typename Index_,
class ValueStorage_,
class IndexStorage_,
class Po
interStorage_>
66class PrimaryMyopicFullSparse final :
public MyopicSparseExtractor<Value_, Index_> {
68 PrimaryMyopicFullSparse(
69 const ValueStorage_& values,
70 const IndexStorage_& indices,
71 const PointerStorage_& pointers,
72 const Index_ secondary,
77 my_pointers(pointers),
78 my_secondary(secondary),
79 my_needs_value(opt.sparse_extract_value),
80 my_needs_index(opt.sparse_extract_index)
83 SparseRange<Value_, Index_> fetch(
const Index_ i, Value_*
const value_buffer, Index_*
const index_buffer) {
84 const auto offset = my_pointers[i];
85 I<
decltype(offset)> delta = my_pointers[i+1] - offset;
87 SparseRange<Value_, Index_> output(delta, NULL, NULL);
89 output.value = sparse_utils::extract_primary_vector(my_values, offset, delta, value_buffer);
92 output.index = sparse_utils::extract_primary_vector(my_indices, offset, delta, index_buffer);
98 const ValueStorage_& my_values;
99 const IndexStorage_& my_indices;
100 const PointerStorage_& my_pointers;
102 bool my_needs_value, my_needs_index;
109template<
typename Value_,
typename Index_,
class ValueStorage_,
class IndexStorage_,
class Po
interStorage_>
110class PrimaryMyopicBlockDense final :
public MyopicDenseExtractor<Value_, Index_> {
112 PrimaryMyopicBlockDense(
113 const ValueStorage_& values,
114 const IndexStorage_& indices,
115 const PointerStorage_& pointers,
116 const Index_ secondary,
117 const Index_ block_start,
118 const Index_ block_length
122 my_pointers(pointers),
123 my_secondary(secondary),
124 my_block_start(block_start),
125 my_block_length(block_length)
128 const Value_* fetch(
const Index_ i, Value_*
const buffer) {
129 auto iStart = my_indices.begin() + my_pointers[i];
130 auto iEnd = my_indices.begin() + my_pointers[i + 1];
131 sparse_utils::refine_primary_block_limits(iStart, iEnd, my_secondary, my_block_start, my_block_length);
132 const auto start_pos = (iStart - my_indices.begin());
133 const auto end_pos = (iEnd - my_indices.begin());
135 std::fill_n(buffer, my_block_length,
static_cast<Value_
>(0));
136 for (
auto x = start_pos; x < end_pos; ++x) {
137 buffer[my_indices[x] - my_block_start] = my_values[x];
143 const ValueStorage_& my_values;
144 const IndexStorage_& my_indices;
145 const PointerStorage_& my_pointers;
147 Index_ my_block_start, my_block_length;
150template<
typename Value_,
typename Index_,
class ValueStorage_,
class IndexStorage_,
class Po
interStorage_>
151class PrimaryMyopicBlockSparse final :
public MyopicSparseExtractor<Value_, Index_> {
153 PrimaryMyopicBlockSparse(
154 const ValueStorage_& values,
155 const IndexStorage_& indices,
156 const PointerStorage_& pointers,
157 const Index_ secondary,
158 const Index_ block_start,
159 const Index_ block_length,
164 my_pointers(pointers),
165 my_secondary(secondary),
166 my_block_start(block_start),
167 my_block_length(block_length),
168 my_needs_value(opt.sparse_extract_value),
169 my_needs_index(opt.sparse_extract_index)
172 SparseRange<Value_, Index_> fetch(
const Index_ i, Value_*
const value_buffer, Index_*
const index_buffer) {
173 auto iStart = my_indices.begin() + my_pointers[i];
174 auto iEnd = my_indices.begin() + my_pointers[i + 1];
175 sparse_utils::refine_primary_block_limits(iStart, iEnd, my_secondary, my_block_start, my_block_length);
176 const auto offset = iStart - my_indices.begin();
177 const auto delta = iEnd - iStart;
179 SparseRange<Value_, Index_> output(delta, NULL, NULL);
180 if (my_needs_value) {
181 output.value = sparse_utils::extract_primary_vector(my_values, offset, delta, value_buffer);
183 if (my_needs_index) {
184 output.index = sparse_utils::extract_primary_vector(my_indices, offset, delta, index_buffer);
190 const ValueStorage_& my_values;
191 const IndexStorage_& my_indices;
192 const PointerStorage_& my_pointers;
194 Index_ my_block_start, my_block_length;
195 bool my_needs_value, my_needs_index;
202template<
typename Value_,
typename Index_,
class ValueStorage_,
class IndexStorage_,
class Po
interStorage_>
203class PrimaryMyopicIndexDense final :
public MyopicDenseExtractor<Value_, Index_> {
205 PrimaryMyopicIndexDense(
206 const ValueStorage_& values,
207 const IndexStorage_& indices,
208 const PointerStorage_& pointers,
209 const Index_ secondary,
210 const VectorPtr<Index_>& indices_ptr
214 my_pointers(pointers),
215 my_retriever(*indices_ptr, secondary),
216 my_num_indices(indices_ptr->size())
219 const Value_* fetch(
const Index_ i, Value_*
const buffer) {
220 std::fill_n(buffer, my_num_indices,
static_cast<Value_
>(0));
221 const auto vIt = my_values.begin() + my_pointers[i];
222 my_retriever.populate(
223 my_indices.begin() + my_pointers[i],
224 my_indices.begin() + my_pointers[i+1],
225 [&](
const auto s,
const auto offset) ->
void {
226 buffer[s] = *(vIt + offset);
233 const ValueStorage_& my_values;
234 const IndexStorage_& my_indices;
235 const PointerStorage_& my_pointers;
236 sparse_utils::RetrievePrimarySubsetDense<Index_> my_retriever;
237 std::size_t my_num_indices;
240template<
typename Value_,
typename Index_,
class ValueStorage_,
class IndexStorage_,
class Po
interStorage_>
241class PrimaryMyopicIndexSparse final :
public MyopicSparseExtractor<Value_, Index_> {
243 PrimaryMyopicIndexSparse(
244 const ValueStorage_& values,
245 const IndexStorage_& indices,
246 const PointerStorage_& pointers,
247 const Index_ secondary,
248 const VectorPtr<Index_>& indices_ptr,
253 my_pointers(pointers),
254 my_retriever(*indices_ptr, secondary),
255 my_needs_value(opt.sparse_extract_value),
256 my_needs_index(opt.sparse_extract_index) {}
258 SparseRange<Value_, Index_> fetch(
const Index_ i, Value_*
const value_buffer, Index_*
const index_buffer) {
260 auto vcopy = value_buffer;
261 auto icopy = index_buffer;
263 auto vIt = my_values.begin() + my_pointers[i];
264 my_retriever.populate(
265 my_indices.begin() + my_pointers[i],
266 my_indices.begin() + my_pointers[i+1],
267 [&](
const auto offset,
const auto ix) ->
void {
269 if (my_needs_value) {
270 *vcopy = *(vIt + offset);
273 if (my_needs_index) {
280 return SparseRange<Value_, Index_>(count, my_needs_value ? value_buffer : NULL, my_needs_index ? index_buffer : NULL);
284 const ValueStorage_& my_values;
285 const IndexStorage_& my_indices;
286 const PointerStorage_& my_pointers;
287 sparse_utils::RetrievePrimarySubsetSparse<Index_> my_retriever;
288 bool my_needs_value, my_needs_index;
295template<
typename Index_,
class IndexStorage_,
class Po
interStorage_>
298 ServeIndices(
const IndexStorage_& i,
const PointerStorage_& p) : my_indices(i), my_pointers(p) {}
301 const IndexStorage_& my_indices;
302 const PointerStorage_& my_pointers;
305 typedef ElementType<PointerStorage_> Pointer;
307 Pointer start_offset(
const Index_ primary)
const {
308 return my_pointers[primary];
311 Pointer end_offset(
const Index_ primary)
const {
312 return my_pointers[primary + 1];
315 auto raw(
const Index_)
const {
316 return my_indices.begin();
320template<
typename Index_,
class IndexStorage_,
class Po
interStorage_>
321auto make_ServeIndices(
const IndexStorage_& i,
const PointerStorage_& p) {
322 return ServeIndices<Index_, IndexStorage_, PointerStorage_>(i, p);
325template<
typename Value_,
typename Index_,
class ValueStorage_,
class IndexStorage_,
class Po
interStorage_>
326class SecondaryMyopicFullDense final :
public MyopicDenseExtractor<Value_, Index_> {
328 SecondaryMyopicFullDense(
329 const ValueStorage_& values,
330 const IndexStorage_& indices,
331 const PointerStorage_& pointers,
332 const Index_ secondary
335 my_cache(make_ServeIndices<Index_>(indices, pointers), secondary, pointers.size() - 1)
338 const Value_* fetch(
const Index_ i, Value_*
const buffer) {
339 std::fill_n(buffer, my_cache.size(),
static_cast<Value_
>(0));
342 [&](
const Index_,
const Index_ index_primary,
const auto ptr) ->
void {
343 buffer[index_primary] = my_values[ptr];
350 const ValueStorage_& my_values;
351 sparse_utils::FullSecondaryExtractionCache<Index_, ServeIndices<Index_, IndexStorage_, PointerStorage_> > my_cache;
354template<
typename Value_,
typename Index_,
class ValueStorage_,
class IndexStorage_,
class Po
interStorage_>
355class SecondaryMyopicFullSparse final :
public MyopicSparseExtractor<Value_, Index_> {
357 SecondaryMyopicFullSparse(
358 const ValueStorage_& values,
359 const IndexStorage_& indices,
360 const PointerStorage_& pointers,
361 const Index_ secondary,
365 my_cache(make_ServeIndices<Index_>(indices, pointers), secondary, pointers.size() - 1),
366 my_needs_value(opt.sparse_extract_value),
367 my_needs_index(opt.sparse_extract_index)
370 SparseRange<Value_, Index_> fetch(
const Index_ i, Value_*
const value_buffer, Index_*
const index_buffer) {
372 my_cache.search(i, [&](
const Index_ primary, Index_,
const ElementType<PointerStorage_> ptr) ->
void {
373 if (my_needs_value) {
374 value_buffer[count] = my_values[ptr];
376 if (my_needs_index) {
377 index_buffer[count] = primary;
381 return SparseRange<Value_, Index_>(count, my_needs_value ? value_buffer : NULL, my_needs_index ? index_buffer : NULL);
385 const ValueStorage_& my_values;
386 sparse_utils::FullSecondaryExtractionCache<Index_, ServeIndices<Index_, IndexStorage_, PointerStorage_> > my_cache;
387 bool my_needs_value, my_needs_index;
394template<
typename Value_,
typename Index_,
class ValueStorage_,
class IndexStorage_,
class Po
interStorage_>
395class SecondaryMyopicBlockDense final :
public MyopicDenseExtractor<Value_, Index_> {
397 SecondaryMyopicBlockDense(
398 const ValueStorage_& values,
399 const IndexStorage_& indices,
400 const PointerStorage_& pointers,
401 const Index_ secondary,
402 const Index_ block_start,
403 const Index_ block_length
406 my_cache(make_ServeIndices<Index_>(indices, pointers), secondary, block_start, block_length)
409 const Value_* fetch(
const Index_ i, Value_*
const buffer) {
410 std::fill_n(buffer, my_cache.size(),
static_cast<Value_
>(0));
413 [&](
const Index_,
const Index_ index_primary,
const auto ptr) ->
void {
414 buffer[index_primary] = my_values[ptr];
421 const ValueStorage_& my_values;
422 sparse_utils::BlockSecondaryExtractionCache<Index_, ServeIndices<Index_, IndexStorage_, PointerStorage_> > my_cache;
425template<
typename Value_,
typename Index_,
class ValueStorage_,
class IndexStorage_,
class Po
interStorage_>
426class SecondaryMyopicBlockSparse final :
public MyopicSparseExtractor<Value_, Index_> {
428 SecondaryMyopicBlockSparse(
429 const ValueStorage_& values,
430 const IndexStorage_& indices,
431 const PointerStorage_& pointers,
432 const Index_ secondary,
433 const Index_ block_start,
434 const Index_ block_length,
438 my_cache(make_ServeIndices<Index_>(indices, pointers), secondary, block_start, block_length),
439 my_needs_value(opt.sparse_extract_value),
440 my_needs_index(opt.sparse_extract_index)
443 SparseRange<Value_, Index_> fetch(
const Index_ i, Value_*
const value_buffer, Index_*
const index_buffer) {
447 [&](Index_ primary, Index_,
auto ptr) ->
void {
448 if (my_needs_value) {
449 value_buffer[count] = my_values[ptr];
451 if (my_needs_index) {
452 index_buffer[count] = primary;
457 return SparseRange<Value_, Index_>(count, my_needs_value ? value_buffer : NULL, my_needs_index ? index_buffer : NULL);
461 const ValueStorage_& my_values;
462 sparse_utils::BlockSecondaryExtractionCache<Index_, ServeIndices<Index_, IndexStorage_, PointerStorage_> > my_cache;
463 bool my_needs_value, my_needs_index;
470template<
typename Value_,
typename Index_,
class ValueStorage_,
class IndexStorage_,
class Po
interStorage_>
471class SecondaryMyopicIndexDense final :
public MyopicDenseExtractor<Value_, Index_> {
473 SecondaryMyopicIndexDense(
474 const ValueStorage_& values,
475 const IndexStorage_& indices,
476 const PointerStorage_& pointers,
477 const Index_ secondary,
478 VectorPtr<Index_> sub_ptr
481 my_cache(make_ServeIndices<Index_>(indices, pointers), secondary, std::move(sub_ptr))
484 const Value_* fetch(
const Index_ i, Value_*
const buffer) {
485 std::fill_n(buffer, my_cache.size(),
static_cast<Value_
>(0));
488 [&](
const Index_,
const Index_ index_primary,
const ElementType<PointerStorage_> ptr) ->
void {
489 buffer[index_primary] = my_values[ptr];
496 const ValueStorage_& my_values;
497 sparse_utils::IndexSecondaryExtractionCache<Index_, ServeIndices<Index_, IndexStorage_, PointerStorage_> > my_cache;
500template<
typename Value_,
typename Index_,
class ValueStorage_,
class IndexStorage_,
class Po
interStorage_>
501class SecondaryMyopicIndexSparse final :
public MyopicSparseExtractor<Value_, Index_> {
503 SecondaryMyopicIndexSparse(
504 const ValueStorage_& values,
505 const IndexStorage_& indices,
506 const PointerStorage_& pointers,
507 const Index_ secondary,
508 VectorPtr<Index_> sub_ptr,
512 my_cache(make_ServeIndices<Index_>(indices, pointers), secondary, std::move(sub_ptr)),
513 my_needs_value(opt.sparse_extract_value),
514 my_needs_index(opt.sparse_extract_index)
517 SparseRange<Value_, Index_> fetch(
const Index_ i, Value_*
const value_buffer, Index_*
const index_buffer) {
521 [&](Index_ primary, Index_, ElementType<PointerStorage_> ptr) ->
void {
522 if (my_needs_value) {
523 value_buffer[count] = my_values[ptr];
525 if (my_needs_index) {
526 index_buffer[count] = primary;
531 return SparseRange<Value_, Index_>(count, my_needs_value ? value_buffer : NULL, my_needs_index ? index_buffer : NULL);
535 const ValueStorage_& my_values;
536 sparse_utils::IndexSecondaryExtractionCache<Index_, ServeIndices<Index_, IndexStorage_, PointerStorage_> > my_cache;
537 bool my_needs_value, my_needs_index;
580template<
typename Value_,
typename Index_,
class ValueStorage_,
class IndexStorage_,
class Po
interStorage_>
595 ValueStorage_ values,
596 IndexStorage_ indices,
597 PointerStorage_ pointers,
603 my_values(std::move(values)),
604 my_indices(std::move(indices)),
605 my_pointers(std::move(pointers)),
609 const auto nnzero = my_values.size();
610 if (!safe_non_negative_equal(nnzero, my_indices.size())) {
611 throw std::runtime_error(
"'my_values' and 'my_indices' should be of the same length");
616 sanisizer::can_ptrdiff<I<
decltype(my_indices.begin())> >(nnzero);
618 const auto npointers = my_pointers.size();
619 const auto check_pointers = [&](
const auto dim) {
621 return npointers >= 1 && safe_non_negative_equal(npointers - 1, dim);
624 if (!check_pointers(my_nrow)) {
625 throw std::runtime_error(
"length of 'pointers' should be equal to 'nrow + 1'");
628 if (!check_pointers(my_ncol)){
629 throw std::runtime_error(
"length of 'pointers' should be equal to 'ncols + 1'");
633 if (my_pointers[0] != 0) {
634 throw std::runtime_error(
"first element of 'pointers' should be zero");
636 const auto last = my_pointers[npointers - 1];
637 if (!safe_non_negative_equal(nnzero, last)) {
638 throw std::runtime_error(
"last element of 'pointers' should be equal to length of 'indices'");
642 for (I<
decltype(npointers)> i = 1; i < npointers; ++i) {
643 const auto start = my_pointers[i - 1], end = my_pointers[i];
644 if (end < start || end > last) {
645 throw std::runtime_error(
"'pointers' should be in non-decreasing order");
648 for (
auto x = start; x < end; ++x) {
649 if (my_indices[x] < 0 || my_indices[x] >= max_index) {
650 throw std::runtime_error(
"'indices' should contain non-negative integers less than the number of " + (my_csr ? std::string(
"columns") : std::string(
"rows")));
654 for (I<
decltype(start)> j = start + 1; j < end; ++j) {
655 if (my_indices[j] <= my_indices[j - 1]) {
656 throw std::runtime_error(
"'indices' should be strictly increasing within each " + (my_csr ? std::string(
"row") : std::string(
"column")));
667 CompressedSparseMatrix(Index_ nrow, Index_ ncol, ValueStorage_ values, IndexStorage_ indices, PointerStorage_ pointers,
bool csr,
bool check =
true) :
668 CompressedSparseMatrix(
676 CompressedSparseMatrixOptions options;
677 options.check = check;
687 Index_ my_nrow, my_ncol;
688 ValueStorage_ my_values;
689 IndexStorage_ my_indices;
690 PointerStorage_ my_pointers;
694 Index_
nrow()
const {
return my_nrow; }
696 Index_
ncol()
const {
return my_ncol; }
708 using Matrix<Value_, Index_>::dense_row;
710 using Matrix<Value_, Index_>::dense_column;
712 using Matrix<Value_, Index_>::sparse_row;
714 using Matrix<Value_, Index_>::sparse_column;
717 Index_ secondary()
const {
729 std::unique_ptr<MyopicDenseExtractor<Value_, Index_> >
dense(
734 return std::make_unique<CompressedSparseMatrix_internal::PrimaryMyopicFullDense<Value_, Index_, ValueStorage_, IndexStorage_, PointerStorage_> >(
735 my_values, my_indices, my_pointers, secondary()
738 return std::make_unique<CompressedSparseMatrix_internal::SecondaryMyopicFullDense<Value_, Index_, ValueStorage_, IndexStorage_, PointerStorage_> >(
739 my_values, my_indices, my_pointers, secondary()
744 std::unique_ptr<MyopicDenseExtractor<Value_, Index_> >
dense(
746 const Index_ block_start,
747 const Index_ block_end,
751 return std::make_unique<CompressedSparseMatrix_internal::PrimaryMyopicBlockDense<Value_, Index_, ValueStorage_, IndexStorage_, PointerStorage_> >(
752 my_values, my_indices, my_pointers, secondary(), block_start, block_end
755 return std::make_unique<CompressedSparseMatrix_internal::SecondaryMyopicBlockDense<Value_, Index_, ValueStorage_, IndexStorage_, PointerStorage_> >(
756 my_values, my_indices, my_pointers, secondary(), block_start, block_end
761 std::unique_ptr<MyopicDenseExtractor<Value_, Index_> >
dense(
767 return std::make_unique<CompressedSparseMatrix_internal::PrimaryMyopicIndexDense<Value_, Index_, ValueStorage_, IndexStorage_, PointerStorage_> >(
768 my_values, my_indices, my_pointers, secondary(), std::move(indices_ptr)
771 return std::make_unique<CompressedSparseMatrix_internal::SecondaryMyopicIndexDense<Value_, Index_, ValueStorage_, IndexStorage_, PointerStorage_> >(
772 my_values, my_indices, my_pointers, secondary(), std::move(indices_ptr)
781 std::unique_ptr<MyopicSparseExtractor<Value_, Index_> >
sparse(
786 return std::make_unique<CompressedSparseMatrix_internal::PrimaryMyopicFullSparse<Value_, Index_, ValueStorage_, IndexStorage_, PointerStorage_> >(
787 my_values, my_indices, my_pointers, secondary(), opt
790 return std::make_unique<CompressedSparseMatrix_internal::SecondaryMyopicFullSparse<Value_, Index_, ValueStorage_, IndexStorage_, PointerStorage_> >(
791 my_values, my_indices, my_pointers, secondary(), opt
796 std::unique_ptr<MyopicSparseExtractor<Value_, Index_> >
sparse(
798 const Index_ block_start,
799 const Index_ block_end,
803 return std::make_unique<CompressedSparseMatrix_internal::PrimaryMyopicBlockSparse<Value_, Index_, ValueStorage_, IndexStorage_, PointerStorage_> >(
804 my_values, my_indices, my_pointers, secondary(), block_start, block_end, opt
807 return std::make_unique<CompressedSparseMatrix_internal::SecondaryMyopicBlockSparse<Value_, Index_, ValueStorage_, IndexStorage_, PointerStorage_> >(
808 my_values, my_indices, my_pointers, secondary(), block_start, block_end, opt
813 std::unique_ptr<MyopicSparseExtractor<Value_, Index_> >
sparse(
819 return std::make_unique<CompressedSparseMatrix_internal::PrimaryMyopicIndexSparse<Value_, Index_, ValueStorage_, IndexStorage_, PointerStorage_> >(
820 my_values, my_indices, my_pointers, secondary(), std::move(indices_ptr), opt
823 return std::make_unique<CompressedSparseMatrix_internal::SecondaryMyopicIndexSparse<Value_, Index_, ValueStorage_, IndexStorage_, PointerStorage_> >(
824 my_values, my_indices, my_pointers, secondary(), std::move(indices_ptr), opt
833 std::unique_ptr<OracularDenseExtractor<Value_, Index_> >
dense(
838 return std::make_unique<PseudoOracularDenseExtractor<Value_, Index_> >(std::move(oracle), dense(row, opt));
841 std::unique_ptr<OracularDenseExtractor<Value_, Index_> >
dense(
844 const Index_ block_start,
845 const Index_ block_end,
848 return std::make_unique<PseudoOracularDenseExtractor<Value_, Index_> >(std::move(oracle), dense(row, block_start, block_end, opt));
851 std::unique_ptr<OracularDenseExtractor<Value_, Index_> >
dense(
857 return std::make_unique<PseudoOracularDenseExtractor<Value_, Index_> >(std::move(oracle), dense(row, std::move(my_indices_ptr), opt));
864 std::unique_ptr<OracularSparseExtractor<Value_, Index_> >
sparse(
869 return std::make_unique<PseudoOracularSparseExtractor<Value_, Index_> >(std::move(oracle), sparse(row, opt));
872 std::unique_ptr<OracularSparseExtractor<Value_, Index_> >
sparse(
875 const Index_ block_start,
876 const Index_ block_end,
879 return std::make_unique<PseudoOracularSparseExtractor<Value_, Index_> >(std::move(oracle), sparse(row, block_start, block_end, opt));
882 std::unique_ptr<OracularSparseExtractor<Value_, Index_> >
sparse(
888 return std::make_unique<PseudoOracularSparseExtractor<Value_, Index_> >(std::move(oracle), sparse(row, std::move(my_indices_ptr), opt));
897template<
typename Value_,
typename Index_,
class ValueStorage_ = std::vector<Value_>,
class IndexStorage_ = std::vector<Index_>,
class Po
interStorage_ = std::vector<std::
size_t> >
909 CompressedSparseMatrix<Value_, Index_, ValueStorage_, IndexStorage_, PointerStorage_>(nrow, ncol, std::move(values), std::move(indices), std::move(pointers), false, check) {}
917template<
typename Value_,
typename Index_,
class ValueStorage_ = std::vector<Value_>,
class IndexStorage_ = std::vector<Index_>,
class Po
interStorage_ = std::vector<std::
size_t> >
928 CompressedSparseRowMatrix(Index_ nrow, Index_ ncol, ValueStorage_ values, IndexStorage_ indices, PointerStorage_ pointers,
bool check =
true) :
929 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:898
CompressedSparseColumnMatrix(Index_ nrow, Index_ ncol, ValueStorage_ values, IndexStorage_ indices, PointerStorage_ pointers, bool check=true)
Definition CompressedSparseMatrix.hpp:908
Compressed sparse matrix representation.
Definition CompressedSparseMatrix.hpp:581
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:882
std::unique_ptr< OracularSparseExtractor< Value_, Index_ > > sparse(const bool row, std::shared_ptr< const Oracle< Index_ > > oracle, const Options &opt) const
Definition CompressedSparseMatrix.hpp:864
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:841
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:872
Index_ nrow() const
Definition CompressedSparseMatrix.hpp:694
bool prefer_rows() const
Definition CompressedSparseMatrix.hpp:702
std::unique_ptr< MyopicDenseExtractor< Value_, Index_ > > dense(const bool row, const Index_ block_start, const Index_ block_end, const Options &) const
Definition CompressedSparseMatrix.hpp:744
double prefer_rows_proportion() const
Definition CompressedSparseMatrix.hpp:704
CompressedSparseMatrix(const Index_ nrow, const Index_ ncol, ValueStorage_ values, IndexStorage_ indices, PointerStorage_ pointers, const bool csr, const CompressedSparseMatrixOptions &options)
Definition CompressedSparseMatrix.hpp:592
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:851
bool uses_oracle(const bool) const
Definition CompressedSparseMatrix.hpp:706
std::unique_ptr< MyopicSparseExtractor< Value_, Index_ > > sparse(const bool row, const Options &opt) const
Definition CompressedSparseMatrix.hpp:781
double is_sparse_proportion() const
Definition CompressedSparseMatrix.hpp:700
std::unique_ptr< MyopicSparseExtractor< Value_, Index_ > > sparse(const bool row, VectorPtr< Index_ > indices_ptr, const Options &opt) const
Definition CompressedSparseMatrix.hpp:813
std::unique_ptr< MyopicDenseExtractor< Value_, Index_ > > dense(const bool row, VectorPtr< Index_ > indices_ptr, const Options &) const
Definition CompressedSparseMatrix.hpp:761
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:796
std::unique_ptr< OracularDenseExtractor< Value_, Index_ > > dense(const bool row, std::shared_ptr< const Oracle< Index_ > > oracle, const Options &opt) const
Definition CompressedSparseMatrix.hpp:833
bool is_sparse() const
Definition CompressedSparseMatrix.hpp:698
Index_ ncol() const
Definition CompressedSparseMatrix.hpp:696
std::unique_ptr< MyopicDenseExtractor< Value_, Index_ > > dense(const bool row, const Options &) const
Definition CompressedSparseMatrix.hpp:729
Compressed sparse row matrix.
Definition CompressedSparseMatrix.hpp:918
CompressedSparseRowMatrix(Index_ nrow, Index_ ncol, ValueStorage_ values, IndexStorage_ indices, PointerStorage_ pointers, bool check=true)
Definition CompressedSparseMatrix.hpp:928
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.
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
I< decltype(std::declval< Array_ >()[0])> ElementType
Definition ElementType.hpp:19
Options for the CompressedSparseMatrix.
Definition CompressedSparseMatrix.hpp:548
bool check
Definition CompressedSparseMatrix.hpp:561
Options for accessing data from a Matrix instance.
Definition Options.hpp:30