1#ifndef TATAMI_COMPRESSED_SPARSE_MATRIX_H
2#define TATAMI_COMPRESSED_SPARSE_MATRIX_H
11#include "sanisizer/sanisizer.hpp"
17#include "primary_extraction.hpp"
18#include "secondary_extraction.hpp"
31namespace CompressedSparseMatrix_internal {
37template<
typename Value_,
typename Index_,
class ValueStorage_,
class IndexStorage_,
class Po
interStorage_>
38class PrimaryMyopicFullDense final :
public MyopicDenseExtractor<Value_, Index_> {
40 PrimaryMyopicFullDense(
const ValueStorage_& values,
const IndexStorage_& indices,
const PointerStorage_& pointers,
const Index_ secondary) :
43 my_pointers(pointers),
44 my_secondary(secondary)
47 const Value_* fetch(
const Index_ i, Value_*
const buffer) {
48 const auto start_pos = my_pointers[i], end_pos = my_pointers[i+1];
49 std::fill_n(buffer, my_secondary,
static_cast<Value_
>(0));
50 for (
auto x = start_pos; x < end_pos; ++x) {
51 buffer[my_indices[x]] = my_values[x];
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 final :
public MyopicSparseExtractor<Value_, Index_> {
66 PrimaryMyopicFullSparse(
67 const ValueStorage_& values,
68 const IndexStorage_& indices,
69 const PointerStorage_& pointers,
70 [[maybe_unused]]
const Index_ secondary,
75 my_pointers(pointers),
76#ifdef TATAMI_DEBUG_FORCE_COPY
77 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);
95#ifdef TATAMI_DEBUG_FORCE_COPY
96 sparse_utils::forcibly_populate_buffers(output, my_secondary, value_buffer, index_buffer);
102 const ValueStorage_& my_values;
103 const IndexStorage_& my_indices;
104 const PointerStorage_& my_pointers;
105#ifdef TATAMI_DEBUG_FORCE_COPY
108 bool my_needs_value, my_needs_index;
115template<
typename Value_,
typename Index_,
class ValueStorage_,
class IndexStorage_,
class Po
interStorage_>
116class PrimaryMyopicBlockDense final :
public MyopicDenseExtractor<Value_, Index_> {
118 PrimaryMyopicBlockDense(
119 const ValueStorage_& values,
120 const IndexStorage_& indices,
121 const PointerStorage_& pointers,
122 const Index_ secondary,
123 const Index_ block_start,
124 const Index_ block_length
128 my_pointers(pointers),
129 my_block_start(block_start),
130 my_block_length(block_length),
131 my_block_end(block_start + block_length),
132 my_search_block_end(my_block_end < secondary)
135 const Value_* fetch(
const Index_ i, Value_*
const buffer) {
136 auto iStart = my_indices.begin() + my_pointers[i];
137 auto iEnd = my_indices.begin() + my_pointers[i + 1];
138 sparse_utils::refine_primary_limits(iStart, iEnd, my_block_start, my_search_block_end, my_block_end);
139 const auto start_pos = (iStart - my_indices.begin());
140 const auto end_pos = (iEnd - my_indices.begin());
142 std::fill_n(buffer, my_block_length,
static_cast<Value_
>(0));
143 for (
auto x = start_pos; x < end_pos; ++x) {
144 buffer[my_indices[x] - my_block_start] = my_values[x];
150 const ValueStorage_& my_values;
151 const IndexStorage_& my_indices;
152 const PointerStorage_& my_pointers;
153 Index_ my_block_start, my_block_length, my_block_end;
154 bool my_search_block_end;
157template<
typename Value_,
typename Index_,
class ValueStorage_,
class IndexStorage_,
class Po
interStorage_>
158class PrimaryMyopicBlockSparse final :
public MyopicSparseExtractor<Value_, Index_> {
160 PrimaryMyopicBlockSparse(
161 const ValueStorage_& values,
162 const IndexStorage_& indices,
163 const PointerStorage_& pointers,
164 const Index_ secondary,
165 const Index_ block_start,
166 const Index_ block_length,
171 my_pointers(pointers),
172 my_block_start(block_start),
173 my_block_end(block_start + block_length),
174#ifdef TATAMI_DEBUG_FORCE_COPY
175 my_block_length(block_length),
177 my_search_block_end(my_block_end < secondary),
178 my_needs_value(opt.sparse_extract_value),
179 my_needs_index(opt.sparse_extract_index)
182 SparseRange<Value_, Index_> fetch(
const Index_ i, Value_*
const value_buffer, Index_*
const index_buffer) {
183 auto iStart = my_indices.begin() + my_pointers[i];
184 auto iEnd = my_indices.begin() + my_pointers[i + 1];
185 sparse_utils::refine_primary_limits(iStart, iEnd, my_block_start, my_search_block_end, my_block_end);
186 const auto offset = iStart - my_indices.begin();
187 const auto delta = iEnd - iStart;
189 SparseRange<Value_, Index_> output(delta, NULL, NULL);
190 if (my_needs_value) {
191 output.value = sparse_utils::extract_primary_vector(my_values, offset, delta, value_buffer);
193 if (my_needs_index) {
194 output.index = sparse_utils::extract_primary_vector(my_indices, offset, delta, index_buffer);
197#ifdef TATAMI_DEBUG_FORCE_COPY
198 sparse_utils::forcibly_populate_buffers(output, my_block_length, value_buffer, index_buffer);
204 const ValueStorage_& my_values;
205 const IndexStorage_& my_indices;
206 const PointerStorage_& my_pointers;
207 Index_ my_block_start, my_block_end;
208#ifdef TATAMI_DEBUG_FORCE_COPY
209 Index_ my_block_length;
211 bool my_search_block_end;
212 bool my_needs_value, my_needs_index;
219template<
typename Value_,
typename Index_,
class ValueStorage_,
class IndexStorage_,
class Po
interStorage_>
220class PrimaryMyopicIndexDense final :
public MyopicDenseExtractor<Value_, Index_> {
222 PrimaryMyopicIndexDense(
223 const ValueStorage_& values,
224 const IndexStorage_& indices,
225 const PointerStorage_& pointers,
226 const Index_ secondary,
227 const VectorPtr<Index_>& indices_ptr
231 my_pointers(pointers),
232 my_retriever(*indices_ptr, secondary),
233 my_num_indices(indices_ptr->size())
236 const Value_* fetch(
const Index_ i, Value_*
const buffer) {
237 std::fill_n(buffer, my_num_indices,
static_cast<Value_
>(0));
238 const auto vIt = my_values.begin() + my_pointers[i];
239 my_retriever.populate(
240 my_indices.begin() + my_pointers[i],
241 my_indices.begin() + my_pointers[i+1],
242 [&](
const auto s,
const auto offset) ->
void {
243 buffer[s] = *(vIt + offset);
250 const ValueStorage_& my_values;
251 const IndexStorage_& my_indices;
252 const PointerStorage_& my_pointers;
253 sparse_utils::RetrievePrimarySubsetDense<Index_> my_retriever;
254 std::size_t my_num_indices;
257template<
typename Value_,
typename Index_,
class ValueStorage_,
class IndexStorage_,
class Po
interStorage_>
258class PrimaryMyopicIndexSparse final :
public MyopicSparseExtractor<Value_, Index_> {
260 PrimaryMyopicIndexSparse(
261 const ValueStorage_& values,
262 const IndexStorage_& indices,
263 const PointerStorage_& pointers,
264 const Index_ secondary,
265 const VectorPtr<Index_>& indices_ptr,
270 my_pointers(pointers),
271 my_retriever(*indices_ptr, secondary),
272#ifdef TATAMI_DEBUG_FORCE_COPY
273 my_length(indices_ptr->size()),
275 my_needs_value(opt.sparse_extract_value),
276 my_needs_index(opt.sparse_extract_index)
279 SparseRange<Value_, Index_> fetch(
const Index_ i, Value_*
const value_buffer, Index_*
const index_buffer) {
281 auto vcopy = value_buffer;
282 auto icopy = index_buffer;
284 auto vIt = my_values.begin() + my_pointers[i];
285 my_retriever.populate(
286 my_indices.begin() + my_pointers[i],
287 my_indices.begin() + my_pointers[i+1],
288 [&](
const auto offset,
const auto ix) ->
void {
290 if (my_needs_value) {
291 *vcopy = *(vIt + offset);
294 if (my_needs_index) {
301 SparseRange<Value_, Index_> output(count, my_needs_value ? value_buffer : NULL, my_needs_index ? index_buffer : NULL);
302#ifdef TATAMI_DEBUG_FORCE_COPY
303 sparse_utils::forcibly_populate_buffers(output, my_length, value_buffer, index_buffer);
309 const ValueStorage_& my_values;
310 const IndexStorage_& my_indices;
311 const PointerStorage_& my_pointers;
312 sparse_utils::RetrievePrimarySubsetSparse<Index_> my_retriever;
313#ifdef TATAMI_DEBUG_FORCE_COPY
316 bool my_needs_value, my_needs_index;
323template<
class Po
interStorage_>
324using Element = I<decltype(std::declval<PointerStorage_>()[0])>;
326template<
typename Index_,
class IndexStorage_,
class Po
interStorage_>
329 ServeIndices(
const IndexStorage_& i,
const PointerStorage_& p) : my_indices(i), my_pointers(p) {}
332 const IndexStorage_& my_indices;
333 const PointerStorage_& my_pointers;
336 typedef Element<PointerStorage_> Pointer;
338 Pointer start_offset(
const Index_ primary)
const {
339 return my_pointers[primary];
342 Pointer end_offset(
const Index_ primary)
const {
343 return my_pointers[primary + 1];
346 auto raw(
const Index_)
const {
347 return my_indices.begin();
351template<
typename Index_,
class IndexStorage_,
class Po
interStorage_>
352auto make_ServeIndices(
const IndexStorage_& i,
const PointerStorage_& p) {
353 return ServeIndices<Index_, IndexStorage_, PointerStorage_>(i, p);
356template<
typename Value_,
typename Index_,
class ValueStorage_,
class IndexStorage_,
class Po
interStorage_>
357class SecondaryMyopicFullDense final :
public MyopicDenseExtractor<Value_, Index_> {
359 SecondaryMyopicFullDense(
360 const ValueStorage_& values,
361 const IndexStorage_& indices,
362 const PointerStorage_& pointers,
363 const Index_ secondary
366 my_cache(make_ServeIndices<Index_>(indices, pointers), secondary, pointers.size() - 1)
369 const Value_* fetch(
const Index_ i, Value_*
const buffer) {
370 std::fill_n(buffer, my_cache.size(),
static_cast<Value_
>(0));
373 [&](
const Index_,
const Index_ index_primary,
const auto ptr) ->
void {
374 buffer[index_primary] = my_values[ptr];
381 const ValueStorage_& my_values;
382 sparse_utils::FullSecondaryExtractionCache<Index_, ServeIndices<Index_, IndexStorage_, PointerStorage_> > my_cache;
385template<
typename Value_,
typename Index_,
class ValueStorage_,
class IndexStorage_,
class Po
interStorage_>
386class SecondaryMyopicFullSparse final :
public MyopicSparseExtractor<Value_, Index_> {
388 SecondaryMyopicFullSparse(
389 const ValueStorage_& values,
390 const IndexStorage_& indices,
391 const PointerStorage_& pointers,
392 const Index_ secondary,
396 my_cache(make_ServeIndices<Index_>(indices, pointers), secondary, pointers.size() - 1),
397#ifdef TATAMI_DEBUG_FORCE_COPY
398 my_length(pointers.size() - 1),
400 my_needs_value(opt.sparse_extract_value),
401 my_needs_index(opt.sparse_extract_index)
404 SparseRange<Value_, Index_> fetch(
const Index_ i, Value_*
const value_buffer, Index_*
const index_buffer) {
406 my_cache.search(i, [&](
const Index_ primary, Index_,
const Element<PointerStorage_> ptr) ->
void {
407 if (my_needs_value) {
408 value_buffer[count] = my_values[ptr];
410 if (my_needs_index) {
411 index_buffer[count] = primary;
416 SparseRange<Value_, Index_> output(count, my_needs_value ? value_buffer : NULL, my_needs_index ? index_buffer : NULL);
417#ifdef TATAMI_DEBUG_FORCE_COPY
418 sparse_utils::forcibly_populate_buffers(output, my_length, value_buffer, index_buffer);
424 const ValueStorage_& my_values;
425 sparse_utils::FullSecondaryExtractionCache<Index_, ServeIndices<Index_, IndexStorage_, PointerStorage_> > my_cache;
426#ifdef TATAMI_DEBUG_FORCE_COPY
429 bool my_needs_value, my_needs_index;
436template<
typename Value_,
typename Index_,
class ValueStorage_,
class IndexStorage_,
class Po
interStorage_>
437class SecondaryMyopicBlockDense final :
public MyopicDenseExtractor<Value_, Index_> {
439 SecondaryMyopicBlockDense(
440 const ValueStorage_& values,
441 const IndexStorage_& indices,
442 const PointerStorage_& pointers,
443 const Index_ secondary,
444 const Index_ block_start,
445 const Index_ block_length
448 my_cache(make_ServeIndices<Index_>(indices, pointers), secondary, block_start, block_length)
451 const Value_* fetch(
const Index_ i, Value_*
const buffer) {
452 std::fill_n(buffer, my_cache.size(),
static_cast<Value_
>(0));
455 [&](
const Index_,
const Index_ index_primary,
const auto ptr) ->
void {
456 buffer[index_primary] = my_values[ptr];
463 const ValueStorage_& my_values;
464 sparse_utils::BlockSecondaryExtractionCache<Index_, ServeIndices<Index_, IndexStorage_, PointerStorage_> > my_cache;
467template<
typename Value_,
typename Index_,
class ValueStorage_,
class IndexStorage_,
class Po
interStorage_>
468class SecondaryMyopicBlockSparse final :
public MyopicSparseExtractor<Value_, Index_> {
470 SecondaryMyopicBlockSparse(
471 const ValueStorage_& values,
472 const IndexStorage_& indices,
473 const PointerStorage_& pointers,
474 const Index_ secondary,
475 const Index_ block_start,
476 const Index_ block_length,
480 my_cache(make_ServeIndices<Index_>(indices, pointers), secondary, block_start, block_length),
481#ifdef TATAMI_DEBUG_FORCE_COPY
482 my_length(block_length),
484 my_needs_value(opt.sparse_extract_value),
485 my_needs_index(opt.sparse_extract_index)
488 SparseRange<Value_, Index_> fetch(
const Index_ i, Value_*
const value_buffer, Index_*
const index_buffer) {
492 [&](Index_ primary, Index_,
auto ptr) ->
void {
493 if (my_needs_value) {
494 value_buffer[count] = my_values[ptr];
496 if (my_needs_index) {
497 index_buffer[count] = primary;
503 SparseRange<Value_, Index_> output(count, my_needs_value ? value_buffer : NULL, my_needs_index ? index_buffer : NULL);
504#ifdef TATAMI_DEBUG_FORCE_COPY
505 sparse_utils::forcibly_populate_buffers(output, my_length, value_buffer, index_buffer);
511 const ValueStorage_& my_values;
512 sparse_utils::BlockSecondaryExtractionCache<Index_, ServeIndices<Index_, IndexStorage_, PointerStorage_> > my_cache;
513#ifdef TATAMI_DEBUG_FORCE_COPY
516 bool my_needs_value, my_needs_index;
523template<
typename Value_,
typename Index_,
class ValueStorage_,
class IndexStorage_,
class Po
interStorage_>
524class SecondaryMyopicIndexDense final :
public MyopicDenseExtractor<Value_, Index_> {
526 SecondaryMyopicIndexDense(
527 const ValueStorage_& values,
528 const IndexStorage_& indices,
529 const PointerStorage_& pointers,
530 const Index_ secondary,
531 VectorPtr<Index_> sub_ptr
534 my_cache(make_ServeIndices<Index_>(indices, pointers), secondary, std::move(sub_ptr))
537 const Value_* fetch(
const Index_ i, Value_*
const buffer) {
538 std::fill_n(buffer, my_cache.size(),
static_cast<Value_
>(0));
541 [&](
const Index_,
const Index_ index_primary,
const Element<PointerStorage_> ptr) ->
void {
542 buffer[index_primary] = my_values[ptr];
549 const ValueStorage_& my_values;
550 sparse_utils::IndexSecondaryExtractionCache<Index_, ServeIndices<Index_, IndexStorage_, PointerStorage_> > my_cache;
553template<
typename Value_,
typename Index_,
class ValueStorage_,
class IndexStorage_,
class Po
interStorage_>
554class SecondaryMyopicIndexSparse final :
public MyopicSparseExtractor<Value_, Index_> {
556 SecondaryMyopicIndexSparse(
557 const ValueStorage_& values,
558 const IndexStorage_& indices,
559 const PointerStorage_& pointers,
560 const Index_ secondary,
561 VectorPtr<Index_> indices_ptr,
565#ifdef TATAMI_DEBUG_FORCE_COPY
566 my_length(indices_ptr->size()),
568 my_cache(make_ServeIndices<Index_>(indices, pointers), secondary, std::move(indices_ptr)),
569 my_needs_value(opt.sparse_extract_value),
570 my_needs_index(opt.sparse_extract_index)
573 SparseRange<Value_, Index_> fetch(
const Index_ i, Value_*
const value_buffer, Index_*
const index_buffer) {
577 [&](Index_ primary, Index_, Element<PointerStorage_> ptr) ->
void {
578 if (my_needs_value) {
579 value_buffer[count] = my_values[ptr];
581 if (my_needs_index) {
582 index_buffer[count] = primary;
588 SparseRange<Value_, Index_> output(count, my_needs_value ? value_buffer : NULL, my_needs_index ? index_buffer : NULL);
589#ifdef TATAMI_DEBUG_FORCE_COPY
590 sparse_utils::forcibly_populate_buffers(output, my_length, value_buffer, index_buffer);
596 const ValueStorage_& my_values;
597#ifdef TATAMI_DEBUG_FORCE_COPY
600 sparse_utils::IndexSecondaryExtractionCache<Index_, ServeIndices<Index_, IndexStorage_, PointerStorage_> > my_cache;
601 bool my_needs_value, my_needs_index;
644template<
typename Value_,
typename Index_,
class ValueStorage_,
class IndexStorage_,
class Po
interStorage_>
659 ValueStorage_ values,
660 IndexStorage_ indices,
661 PointerStorage_ pointers,
667 my_values(std::move(values)),
668 my_indices(std::move(indices)),
669 my_pointers(std::move(pointers)),
673 const auto nnzero = my_values.size();
674 if (!sanisizer::is_equal(nnzero, my_indices.size())) {
675 throw std::runtime_error(
"'my_values' and 'my_indices' should be of the same length");
678 const auto npointers = my_pointers.size();
679 const auto check_pointers = [&](
const auto dim) {
681 return npointers >= 1 && sanisizer::is_equal(npointers - 1, dim);
684 if (!check_pointers(my_nrow)) {
685 throw std::runtime_error(
"length of 'pointers' should be equal to 'nrow + 1'");
688 if (!check_pointers(my_ncol)){
689 throw std::runtime_error(
"length of 'pointers' should be equal to 'ncols + 1'");
693 if (my_pointers[0] != 0) {
694 throw std::runtime_error(
"first element of 'pointers' should be zero");
696 const auto last = my_pointers[npointers - 1];
697 if (!sanisizer::is_equal(nnzero, last)) {
698 throw std::runtime_error(
"last element of 'pointers' should be equal to length of 'indices'");
701 const auto max_index = (my_csr ? my_ncol : my_nrow);
702 for (I<
decltype(npointers)> i = 1; i < npointers; ++i) {
703 const auto start = my_pointers[i - 1], end = my_pointers[i];
706 }
else if (end < start) {
707 throw std::runtime_error(
"'pointers' should be in non-decreasing order");
710 for (
auto x = start; x < end; ++x) {
711 if (my_indices[x] < 0 || sanisizer::is_greater_than_or_equal(my_indices[x], max_index)) {
712 throw std::runtime_error(
"'indices' should contain non-negative integers less than the number of " + (my_csr ? std::string(
"columns") : std::string(
"rows")));
716 for (I<
decltype(start)> j = start + 1; j < end; ++j) {
717 if (my_indices[j] <= my_indices[j - 1]) {
718 throw std::runtime_error(
"'indices' should be strictly increasing within each " + (my_csr ? std::string(
"row") : std::string(
"column")));
729 CompressedSparseMatrix(Index_ nrow, Index_ ncol, ValueStorage_ values, IndexStorage_ indices, PointerStorage_ pointers,
bool csr,
bool check =
true) :
730 CompressedSparseMatrix(
738 CompressedSparseMatrixOptions options;
739 options.check = check;
749 Index_ my_nrow, my_ncol;
750 ValueStorage_ my_values;
751 IndexStorage_ my_indices;
752 PointerStorage_ my_pointers;
759 Index_
nrow()
const {
return my_nrow; }
764 Index_
ncol()
const {
return my_ncol; }
791 using Matrix<Value_, Index_>::dense_row;
793 using Matrix<Value_, Index_>::dense_column;
795 using Matrix<Value_, Index_>::sparse_row;
797 using Matrix<Value_, Index_>::sparse_column;
800 Index_ secondary()
const {
815 std::unique_ptr<MyopicDenseExtractor<Value_, Index_> >
dense(
820 return std::make_unique<CompressedSparseMatrix_internal::PrimaryMyopicFullDense<Value_, Index_, ValueStorage_, IndexStorage_, PointerStorage_> >(
821 my_values, my_indices, my_pointers, secondary()
824 return std::make_unique<CompressedSparseMatrix_internal::SecondaryMyopicFullDense<Value_, Index_, ValueStorage_, IndexStorage_, PointerStorage_> >(
825 my_values, my_indices, my_pointers, secondary()
833 std::unique_ptr<MyopicDenseExtractor<Value_, Index_> >
dense(
835 const Index_ block_start,
836 const Index_ block_length,
840 return std::make_unique<CompressedSparseMatrix_internal::PrimaryMyopicBlockDense<Value_, Index_, ValueStorage_, IndexStorage_, PointerStorage_> >(
841 my_values, my_indices, my_pointers, secondary(), block_start, block_length
844 return std::make_unique<CompressedSparseMatrix_internal::SecondaryMyopicBlockDense<Value_, Index_, ValueStorage_, IndexStorage_, PointerStorage_> >(
845 my_values, my_indices, my_pointers, secondary(), block_start, block_length
853 std::unique_ptr<MyopicDenseExtractor<Value_, Index_> >
dense(
859 return std::make_unique<CompressedSparseMatrix_internal::PrimaryMyopicIndexDense<Value_, Index_, ValueStorage_, IndexStorage_, PointerStorage_> >(
860 my_values, my_indices, my_pointers, secondary(), std::move(indices_ptr)
863 return std::make_unique<CompressedSparseMatrix_internal::SecondaryMyopicIndexDense<Value_, Index_, ValueStorage_, IndexStorage_, PointerStorage_> >(
864 my_values, my_indices, my_pointers, secondary(), std::move(indices_ptr)
876 std::unique_ptr<MyopicSparseExtractor<Value_, Index_> >
sparse(
881 return std::make_unique<CompressedSparseMatrix_internal::PrimaryMyopicFullSparse<Value_, Index_, ValueStorage_, IndexStorage_, PointerStorage_> >(
882 my_values, my_indices, my_pointers, secondary(), opt
885 return std::make_unique<CompressedSparseMatrix_internal::SecondaryMyopicFullSparse<Value_, Index_, ValueStorage_, IndexStorage_, PointerStorage_> >(
886 my_values, my_indices, my_pointers, secondary(), opt
894 std::unique_ptr<MyopicSparseExtractor<Value_, Index_> >
sparse(
896 const Index_ block_start,
897 const Index_ block_length,
901 return std::make_unique<CompressedSparseMatrix_internal::PrimaryMyopicBlockSparse<Value_, Index_, ValueStorage_, IndexStorage_, PointerStorage_> >(
902 my_values, my_indices, my_pointers, secondary(), block_start, block_length, opt
905 return std::make_unique<CompressedSparseMatrix_internal::SecondaryMyopicBlockSparse<Value_, Index_, ValueStorage_, IndexStorage_, PointerStorage_> >(
906 my_values, my_indices, my_pointers, secondary(), block_start, block_length, opt
914 std::unique_ptr<MyopicSparseExtractor<Value_, Index_> >
sparse(
920 return std::make_unique<CompressedSparseMatrix_internal::PrimaryMyopicIndexSparse<Value_, Index_, ValueStorage_, IndexStorage_, PointerStorage_> >(
921 my_values, my_indices, my_pointers, secondary(), std::move(indices_ptr), opt
924 return std::make_unique<CompressedSparseMatrix_internal::SecondaryMyopicIndexSparse<Value_, Index_, ValueStorage_, IndexStorage_, PointerStorage_> >(
925 my_values, my_indices, my_pointers, secondary(), std::move(indices_ptr), opt
937 std::unique_ptr<OracularDenseExtractor<Value_, Index_> >
dense(
942 return std::make_unique<PseudoOracularDenseExtractor<Value_, Index_> >(std::move(oracle), dense(row, opt));
948 std::unique_ptr<OracularDenseExtractor<Value_, Index_> >
dense(
951 const Index_ block_start,
952 const Index_ block_length,
955 return std::make_unique<PseudoOracularDenseExtractor<Value_, Index_> >(std::move(oracle), dense(row, block_start, block_length, opt));
961 std::unique_ptr<OracularDenseExtractor<Value_, Index_> >
dense(
967 return std::make_unique<PseudoOracularDenseExtractor<Value_, Index_> >(std::move(oracle), dense(row, std::move(indices_ptr), opt));
977 std::unique_ptr<OracularSparseExtractor<Value_, Index_> >
sparse(
982 return std::make_unique<PseudoOracularSparseExtractor<Value_, Index_> >(std::move(oracle), sparse(row, opt));
988 std::unique_ptr<OracularSparseExtractor<Value_, Index_> >
sparse(
991 const Index_ block_start,
992 const Index_ block_length,
995 return std::make_unique<PseudoOracularSparseExtractor<Value_, Index_> >(std::move(oracle), sparse(row, block_start, block_length, opt));
1001 std::unique_ptr<OracularSparseExtractor<Value_, Index_> >
sparse(
1007 return std::make_unique<PseudoOracularSparseExtractor<Value_, Index_> >(std::move(oracle), sparse(row, std::move(indices_ptr), opt));
1016template<
typename Value_,
typename Index_,
class ValueStorage_ = std::vector<Value_>,
class IndexStorage_ = std::vector<Index_>,
class Po
interStorage_ = std::vector<std::
size_t> >
1028 CompressedSparseMatrix<Value_, Index_, ValueStorage_, IndexStorage_, PointerStorage_>(nrow, ncol, std::move(values), std::move(indices), std::move(pointers), false, check) {}
1036template<
typename Value_,
typename Index_,
class ValueStorage_ = std::vector<Value_>,
class IndexStorage_ = std::vector<Index_>,
class Po
interStorage_ = std::vector<std::
size_t> >
1047 CompressedSparseRowMatrix(Index_ nrow, Index_ ncol, ValueStorage_ values, IndexStorage_ indices, PointerStorage_ pointers,
bool check =
true) :
1048 CompressedSparseMatrix<Value_, Index_, ValueStorage_, IndexStorage_, PointerStorage_>(nrow, ncol, std::move(values), std::move(indices), std::move(pointers), true, check) {}
Virtual class for a matrix of some numeric type.
Compressed sparse column matrix.
Definition CompressedSparseMatrix.hpp:1017
CompressedSparseColumnMatrix(Index_ nrow, Index_ ncol, ValueStorage_ values, IndexStorage_ indices, PointerStorage_ pointers, bool check=true)
Definition CompressedSparseMatrix.hpp:1027
Compressed sparse matrix representation.
Definition CompressedSparseMatrix.hpp:645
std::unique_ptr< OracularSparseExtractor< Value_, Index_ > > sparse(const bool row, std::shared_ptr< const Oracle< Index_ > > oracle, const Options &opt) const
Definition CompressedSparseMatrix.hpp:977
Index_ nrow() const
Definition CompressedSparseMatrix.hpp:759
std::unique_ptr< MyopicSparseExtractor< Value_, Index_ > > sparse(const bool row, const Index_ block_start, const Index_ block_length, const Options &opt) const
Definition CompressedSparseMatrix.hpp:894
bool prefer_rows() const
Definition CompressedSparseMatrix.hpp:779
double prefer_rows_proportion() const
Definition CompressedSparseMatrix.hpp:784
std::unique_ptr< OracularDenseExtractor< Value_, Index_ > > dense(const bool row, std::shared_ptr< const Oracle< Index_ > > oracle, const Index_ block_start, const Index_ block_length, const Options &opt) const
Definition CompressedSparseMatrix.hpp:948
CompressedSparseMatrix(const Index_ nrow, const Index_ ncol, ValueStorage_ values, IndexStorage_ indices, PointerStorage_ pointers, const bool csr, const CompressedSparseMatrixOptions &options)
Definition CompressedSparseMatrix.hpp:656
std::unique_ptr< OracularDenseExtractor< Value_, Index_ > > dense(const bool row, std::shared_ptr< const Oracle< Index_ > > oracle, VectorPtr< Index_ > indices_ptr, const Options &opt) const
Definition CompressedSparseMatrix.hpp:961
bool uses_oracle(const bool) const
Definition CompressedSparseMatrix.hpp:789
std::unique_ptr< MyopicSparseExtractor< Value_, Index_ > > sparse(const bool row, const Options &opt) const
Definition CompressedSparseMatrix.hpp:876
std::unique_ptr< OracularSparseExtractor< Value_, Index_ > > sparse(const bool row, std::shared_ptr< const Oracle< Index_ > > oracle, const Index_ block_start, const Index_ block_length, const Options &opt) const
Definition CompressedSparseMatrix.hpp:988
std::unique_ptr< OracularSparseExtractor< Value_, Index_ > > sparse(const bool row, std::shared_ptr< const Oracle< Index_ > > oracle, VectorPtr< Index_ > indices_ptr, const Options &opt) const
Definition CompressedSparseMatrix.hpp:1001
double is_sparse_proportion() const
Definition CompressedSparseMatrix.hpp:774
std::unique_ptr< MyopicSparseExtractor< Value_, Index_ > > sparse(const bool row, VectorPtr< Index_ > indices_ptr, const Options &opt) const
Definition CompressedSparseMatrix.hpp:914
std::unique_ptr< MyopicDenseExtractor< Value_, Index_ > > dense(const bool row, VectorPtr< Index_ > indices_ptr, const Options &) const
Definition CompressedSparseMatrix.hpp:853
std::unique_ptr< OracularDenseExtractor< Value_, Index_ > > dense(const bool row, std::shared_ptr< const Oracle< Index_ > > oracle, const Options &opt) const
Definition CompressedSparseMatrix.hpp:937
bool is_sparse() const
Definition CompressedSparseMatrix.hpp:769
Index_ ncol() const
Definition CompressedSparseMatrix.hpp:764
std::unique_ptr< MyopicDenseExtractor< Value_, Index_ > > dense(const bool row, const Options &) const
Definition CompressedSparseMatrix.hpp:815
std::unique_ptr< MyopicDenseExtractor< Value_, Index_ > > dense(const bool row, const Index_ block_start, const Index_ block_length, const Options &) const
Definition CompressedSparseMatrix.hpp:833
Compressed sparse row matrix.
Definition CompressedSparseMatrix.hpp:1037
CompressedSparseRowMatrix(Index_ nrow, Index_ ncol, ValueStorage_ values, IndexStorage_ indices, PointerStorage_ pointers, bool check=true)
Definition CompressedSparseMatrix.hpp:1047
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
Options for the CompressedSparseMatrix.
Definition CompressedSparseMatrix.hpp:612
bool check
Definition CompressedSparseMatrix.hpp:625
Options for accessing data from a Matrix instance.
Definition Options.hpp:30