1#ifndef TATAMI_FRAGMENTED_SPARSE_MATRIX_H
2#define TATAMI_FRAGMENTED_SPARSE_MATRIX_H
9#include "primary_extraction.hpp"
10#include "secondary_extraction.hpp"
19#include "sanisizer/sanisizer.hpp"
32namespace FragmentedSparseMatrix_internal {
38template<
typename Value_,
typename Index_,
class ValueVectorStorage_,
class IndexVectorStorage_>
39class PrimaryMyopicFullDense final :
public MyopicDenseExtractor<Value_, Index_> {
41 PrimaryMyopicFullDense(
const ValueVectorStorage_& values,
const IndexVectorStorage_& indices,
const Index_ secondary) :
42 my_values(values), my_indices(indices), my_secondary(secondary) {}
44 const Value_* fetch(
const Index_ i, Value_*
const buffer) {
45 const auto& curv = my_values[i];
46 const auto& curi = my_indices[i];
48 std::fill_n(buffer, my_secondary,
static_cast<Value_
>(0));
49 const auto curnnz = curv.size();
50 for (I<
decltype(curnnz)> x = 0; x < curnnz; ++x) {
51 buffer[curi[x]] = curv[x];
57 const ValueVectorStorage_& my_values;
58 const IndexVectorStorage_& my_indices;
62template<
typename Value_,
typename Index_,
class ValueVectorStorage_,
class IndexVectorStorage_>
63class PrimaryMyopicFullSparse final :
public MyopicSparseExtractor<Value_, Index_> {
65 PrimaryMyopicFullSparse(
66 const ValueVectorStorage_& values,
67 const IndexVectorStorage_& indices,
68 [[maybe_unused]]
const Index_ secondary,
73#ifdef TATAMI_DEBUG_FORCE_COPY
74 my_secondary(secondary),
76 my_needs_value(opt.sparse_extract_value),
77 my_needs_index(opt.sparse_extract_index)
80 SparseRange<Value_, Index_> fetch(
const Index_ i, Value_*
const value_buffer, Index_*
const index_buffer) {
81 const auto& curv = my_values[i];
82 const auto& curi = my_indices[i];
84 SparseRange<Value_, Index_> output(curv.size(), NULL, NULL);
86 const auto curnnz = curv.size();
87 output.value = sparse_utils::extract_primary_vector(curv,
static_cast<I<decltype(curnnz)
> >(0), curnnz, value_buffer);
90 const auto curnnz = curi.size();
91 output.index = sparse_utils::extract_primary_vector(curi,
static_cast<I<decltype(curnnz)
> >(0), curnnz, index_buffer);
94#ifdef TATAMI_DEBUG_FORCE_COPY
95 sparse_utils::forcibly_populate_buffers(output, my_secondary, value_buffer, index_buffer);
101 const ValueVectorStorage_& my_values;
102 const IndexVectorStorage_& my_indices;
103#ifdef TATAMI_DEBUG_FORCE_COPY
106 bool my_needs_value, my_needs_index;
113template<
typename Value_,
typename Index_,
class ValueVectorStorage_,
class IndexVectorStorage_>
114class PrimaryMyopicBlockDense final :
public MyopicDenseExtractor<Value_, Index_> {
116 PrimaryMyopicBlockDense(
117 const ValueVectorStorage_& values,
118 const IndexVectorStorage_& indices,
119 const Index_ secondary,
120 const Index_ block_start,
121 const Index_ block_length
125 my_block_start(block_start),
126 my_block_length(block_length),
127 my_block_end(block_start + block_length),
128 my_search_block_end(my_block_end < secondary)
131 const Value_* fetch(
const Index_ i, Value_*
const buffer) {
132 const auto& curi = my_indices[i];
133 const auto& curv = my_values[i];
135 auto iStart = curi.begin();
136 auto iEnd = curi.end();
137 sparse_utils::refine_primary_limits(iStart, iEnd, my_block_start, my_search_block_end, my_block_end);
138 const auto start_pos = (iStart - curi.begin());
139 const auto end_pos = (iEnd - curi.begin());
141 std::fill_n(buffer, my_block_length,
static_cast<Value_
>(0));
142 for (
auto x = start_pos; x < end_pos; ++x) {
143 buffer[curi[x] - my_block_start] = curv[x];
149 const ValueVectorStorage_& my_values;
150 const IndexVectorStorage_& my_indices;
151 Index_ my_block_start, my_block_length, my_block_end;
152 bool my_search_block_end;
155template<
typename Value_,
typename Index_,
class ValueVectorStorage_,
class IndexVectorStorage_>
156class PrimaryMyopicBlockSparse final :
public MyopicSparseExtractor<Value_, Index_> {
158 PrimaryMyopicBlockSparse(
159 const ValueVectorStorage_& values,
160 const IndexVectorStorage_& indices,
161 const Index_ secondary,
162 const Index_ block_start,
163 const Index_ block_length,
168 my_block_start(block_start),
169 my_block_end(block_start + block_length),
170#ifdef TATAMI_DEBUG_FORCE_COPY
171 my_block_length(block_length),
173 my_search_block_end(my_block_end < secondary),
174 my_needs_value(opt.sparse_extract_value),
175 my_needs_index(opt.sparse_extract_index)
178 SparseRange<Value_, Index_> fetch(
const Index_ i, Value_*
const value_buffer, Index_*
const index_buffer) {
179 const auto& curi = my_indices[i];
180 auto iStart = curi.begin();
181 auto iEnd = curi.end();
182 sparse_utils::refine_primary_limits(iStart, iEnd, my_block_start, my_search_block_end, my_block_end);
183 const auto offset = iStart - curi.begin();
184 const auto delta = iEnd - iStart;
186 SparseRange<Value_, Index_> output(delta, NULL, NULL);
187 if (my_needs_value) {
188 output.value = sparse_utils::extract_primary_vector(my_values[i], offset, delta, value_buffer);
190 if (my_needs_index) {
191 output.index = sparse_utils::extract_primary_vector(curi, offset, delta, index_buffer);
194#ifdef TATAMI_DEBUG_FORCE_COPY
195 sparse_utils::forcibly_populate_buffers(output, my_block_length, value_buffer, index_buffer);
201 const ValueVectorStorage_& my_values;
202 const IndexVectorStorage_& my_indices;
203 Index_ my_block_start, my_block_end;
204#ifdef TATAMI_DEBUG_FORCE_COPY
205 Index_ my_block_length;
207 bool my_search_block_end;
208 bool my_needs_value, my_needs_index;
215template<
typename Value_,
typename Index_,
class ValueVectorStorage_,
class IndexVectorStorage_>
216class PrimaryMyopicIndexDense final :
public MyopicDenseExtractor<Value_, Index_> {
218 PrimaryMyopicIndexDense(
219 const ValueVectorStorage_& values,
220 const IndexVectorStorage_& indices,
221 const Index_ secondary,
222 VectorPtr<Index_> indices_ptr
226 my_retriever(*indices_ptr, secondary),
227 my_num_indices(indices_ptr->size())
230 const Value_* fetch(
const Index_ i, Value_*
const buffer) {
231 const auto& curi = my_indices[i];
232 const auto& curv = my_values[i];
233 std::fill_n(buffer, my_num_indices,
static_cast<Value_
>(0));
234 my_retriever.populate(
237 [&](
const auto s,
const auto offset) ->
void {
238 buffer[s] = curv[offset];
245 const ValueVectorStorage_& my_values;
246 const IndexVectorStorage_& my_indices;
247 sparse_utils::RetrievePrimarySubsetDense<Index_> my_retriever;
248 std::size_t my_num_indices;
251template<
typename Value_,
typename Index_,
class ValueVectorStorage_,
class IndexVectorStorage_>
252class PrimaryMyopicIndexSparse final :
public MyopicSparseExtractor<Value_, Index_> {
254 PrimaryMyopicIndexSparse(
255 const ValueVectorStorage_& values,
256 const IndexVectorStorage_& indices,
257 const Index_ secondary,
258 VectorPtr<Index_> indices_ptr,
263 my_retriever(*indices_ptr, secondary),
264#ifdef TATAMI_DEBUG_FORCE_COPY
265 my_length(indices_ptr->size()),
267 my_needs_value(opt.sparse_extract_value),
268 my_needs_index(opt.sparse_extract_index)
271 SparseRange<Value_, Index_> fetch(
const Index_ i, Value_*
const value_buffer, Index_*
const index_buffer) {
272 const auto& curi = my_indices[i];
273 const auto& curv = my_values[i];
275 auto vcopy = value_buffer;
276 auto icopy = index_buffer;
278 my_retriever.populate(
281 [&](
const auto offset,
const auto ix) ->
void {
283 if (my_needs_value) {
284 *vcopy = curv[offset];
287 if (my_needs_index) {
294 SparseRange<Value_, Index_> output(count, my_needs_value ? value_buffer : NULL, my_needs_index ? index_buffer : NULL);
295#ifdef TATAMI_DEBUG_FORCE_COPY
296 sparse_utils::forcibly_populate_buffers(output, my_length, value_buffer, index_buffer);
302 const ValueVectorStorage_& my_values;
303 const IndexVectorStorage_& my_indices;
304 sparse_utils::RetrievePrimarySubsetSparse<Index_> my_retriever;
305#ifdef TATAMI_DEBUG_FORCE_COPY
308 bool my_needs_value, my_needs_index;
315template<
typename Index_,
class IndexVectorStorage_>
318 ServeIndices(
const IndexVectorStorage_& indices) : my_indices(indices) {}
321 const IndexVectorStorage_& my_indices;
324 typedef I<decltype(std::declval<IndexVectorStorage_>()[0].size())> Pointer;
326 Pointer start_offset(
const Index_)
const {
330 Pointer end_offset(
const Index_ primary)
const {
331 return my_indices[primary].size();
334 auto raw(
const Index_ primary)
const {
335 return my_indices[primary].begin();
339template<
typename Index_,
class IndexVectorStorage_>
340auto make_ServeIndices(
const IndexVectorStorage_& i) {
341 return ServeIndices<Index_, IndexVectorStorage_>(i);
344template<
typename Value_,
typename Index_,
class ValueVectorStorage_,
class IndexVectorStorage_>
345class SecondaryMyopicFullDense final :
public MyopicDenseExtractor<Value_, Index_> {
347 SecondaryMyopicFullDense(
348 const ValueVectorStorage_& values,
349 const IndexVectorStorage_& indices,
353 my_cache(make_ServeIndices<Index_>(indices), secondary, indices.size())
356 const Value_* fetch(
const Index_ i, Value_*
const buffer) {
357 std::fill_n(buffer, my_cache.size(),
static_cast<Value_
>(0));
360 [&](Index_ primary, Index_ index_primary,
auto ptr) ->
void {
361 buffer[index_primary] = my_values[primary][ptr];
368 const ValueVectorStorage_& my_values;
369 sparse_utils::FullSecondaryExtractionCache<Index_, ServeIndices<Index_, IndexVectorStorage_> > my_cache;
372template<
typename Value_,
typename Index_,
class ValueVectorStorage_,
class IndexVectorStorage_>
373class SecondaryMyopicFullSparse final :
public MyopicSparseExtractor<Value_, Index_> {
375 SecondaryMyopicFullSparse(
376 const ValueVectorStorage_& values,
377 const IndexVectorStorage_& indices,
378 const Index_ secondary,
382 my_cache(make_ServeIndices<Index_>(indices), secondary, indices.size()),
383 my_needs_value(opt.sparse_extract_value),
384 my_needs_index(opt.sparse_extract_index)
387 SparseRange<Value_, Index_> fetch(
const Index_ i, Value_*
const value_buffer, Index_*
const index_buffer) {
391 [&](
const Index_ primary,
const Index_,
const auto ptr) ->
void {
392 if (my_needs_value) {
393 value_buffer[count] = my_values[primary][ptr];
395 if (my_needs_index) {
396 index_buffer[count] = primary;
402 SparseRange<Value_, Index_> output(count, my_needs_value ? value_buffer : NULL, my_needs_index ? index_buffer : NULL);
403#ifdef TATAMI_DEBUG_FORCE_COPY
404 sparse_utils::forcibly_populate_buffers(output,
static_cast<Index_
>(my_values.size()), value_buffer, index_buffer);
410 const ValueVectorStorage_& my_values;
411 sparse_utils::FullSecondaryExtractionCache<Index_, ServeIndices<Index_, IndexVectorStorage_> > my_cache;
412 bool my_needs_value, my_needs_index;
419template<
typename Value_,
typename Index_,
class ValueVectorStorage_,
class IndexVectorStorage_>
420class SecondaryMyopicBlockDense final :
public MyopicDenseExtractor<Value_, Index_> {
422 SecondaryMyopicBlockDense(
423 const ValueVectorStorage_& values,
424 const IndexVectorStorage_& indices,
425 const Index_ secondary,
426 const Index_ block_start,
427 const Index_ block_length
430 my_cache(make_ServeIndices<Index_>(indices), secondary, block_start, block_length)
433 const Value_* fetch(
const Index_ i, Value_*
const buffer) {
434 std::fill_n(buffer, my_cache.size(),
static_cast<Value_
>(0));
437 [&](
const Index_ primary,
const Index_ index_primary,
const auto ptr) ->
void {
438 buffer[index_primary] = my_values[primary][ptr];
445 const ValueVectorStorage_& my_values;
446 sparse_utils::BlockSecondaryExtractionCache<Index_, ServeIndices<Index_, IndexVectorStorage_> > my_cache;
449template<
typename Value_,
typename Index_,
class ValueVectorStorage_,
class IndexVectorStorage_>
450class SecondaryMyopicBlockSparse final :
public MyopicSparseExtractor<Value_, Index_> {
452 SecondaryMyopicBlockSparse(
453 const ValueVectorStorage_& values,
454 const IndexVectorStorage_& indices,
455 const Index_ secondary,
456 const Index_ block_start,
457 const Index_ block_length,
461 my_cache(make_ServeIndices<Index_>(indices), secondary, block_start, block_length),
462#ifdef TATAMI_DEBUG_FORCE_COPY
463 my_length(block_length),
465 my_needs_value(opt.sparse_extract_value),
466 my_needs_index(opt.sparse_extract_index)
469 SparseRange<Value_, Index_> fetch(
const Index_ i, Value_*
const value_buffer, Index_*
const index_buffer) {
473 [&](
const Index_ primary,
const Index_,
const auto ptr) ->
void {
474 if (my_needs_value) {
475 value_buffer[count] = my_values[primary][ptr];
477 if (my_needs_index) {
478 index_buffer[count] = primary;
484 SparseRange<Value_, Index_> output(count, my_needs_value ? value_buffer : NULL, my_needs_index ? index_buffer : NULL);
485#ifdef TATAMI_DEBUG_FORCE_COPY
486 sparse_utils::forcibly_populate_buffers(output, my_length, value_buffer, index_buffer);
492 const ValueVectorStorage_& my_values;
493 sparse_utils::BlockSecondaryExtractionCache<Index_, ServeIndices<Index_, IndexVectorStorage_> > my_cache;
494#ifdef TATAMI_DEBUG_FORCE_COPY
497 bool my_needs_value, my_needs_index;
504template<
typename Value_,
typename Index_,
class ValueVectorStorage_,
class IndexVectorStorage_>
505class SecondaryMyopicIndexDense final :
public MyopicDenseExtractor<Value_, Index_> {
507 SecondaryMyopicIndexDense(
508 const ValueVectorStorage_& values,
509 const IndexVectorStorage_& indices,
510 const Index_ secondary,
511 VectorPtr<Index_> indices_ptr
514 my_cache(make_ServeIndices<Index_>(indices), secondary, std::move(indices_ptr))
517 const Value_* fetch(
const Index_ i, Value_*
const buffer) {
518 std::fill_n(buffer, my_cache.size(),
static_cast<Value_
>(0));
521 [&](Index_ primary, Index_ index_primary,
auto ptr) ->
void {
522 buffer[index_primary] = my_values[primary][ptr];
529 const ValueVectorStorage_& my_values;
530 sparse_utils::IndexSecondaryExtractionCache<Index_, ServeIndices<Index_, IndexVectorStorage_> > my_cache;
533template<
typename Value_,
typename Index_,
class ValueVectorStorage_,
class IndexVectorStorage_>
534class SecondaryMyopicIndexSparse final :
public MyopicSparseExtractor<Value_, Index_> {
536 SecondaryMyopicIndexSparse(
537 const ValueVectorStorage_& values,
538 const IndexVectorStorage_& indices,
539 const Index_ secondary,
540 VectorPtr<Index_> indices_ptr,
544#ifdef TATAMI_DEBUG_FORCE_COPY
545 my_length(indices_ptr->size()),
547 my_cache(make_ServeIndices<Index_>(indices), secondary, std::move(indices_ptr)),
548 my_needs_value(opt.sparse_extract_value),
549 my_needs_index(opt.sparse_extract_index)
552 SparseRange<Value_, Index_> fetch(
const Index_ i, Value_*
const value_buffer, Index_*
const index_buffer) {
556 [&](
const Index_ primary,
const Index_,
const auto ptr) ->
void {
557 if (my_needs_value) {
558 value_buffer[count] = my_values[primary][ptr];
560 if (my_needs_index) {
561 index_buffer[count] = primary;
567 SparseRange<Value_, Index_> output(count, my_needs_value ? value_buffer : NULL, my_needs_index ? index_buffer : NULL);
568#ifdef TATAMI_DEBUG_FORCE_COPY
569 sparse_utils::forcibly_populate_buffers(output, my_length, value_buffer, index_buffer);
575 const ValueVectorStorage_& my_values;
576#ifdef TATAMI_DEBUG_FORCE_COPY
579 sparse_utils::IndexSecondaryExtractionCache<Index_, ServeIndices<Index_, IndexVectorStorage_> > my_cache;
580 bool my_needs_value, my_needs_index;
626template<
typename Value_,
typename Index_,
class ValueVectorStorage_,
class IndexVectorStorage_>
641 ValueVectorStorage_ values,
642 IndexVectorStorage_ indices,
643 const bool row_sparse,
648 my_values(std::move(values)),
649 my_indices(std::move(indices)),
650 my_row_sparse(row_sparse)
653 if (my_values.size() != my_indices.size()) {
654 throw std::runtime_error(
"'values' and 'indices' should be of the same length");
658 if (!sanisizer::is_equal(my_indices.size(), my_nrow)) {
659 throw std::runtime_error(
"length of 'indices' should be equal to number of rows'");
662 if (!sanisizer::is_equal(my_indices.size(), my_ncol)) {
663 throw std::runtime_error(
"length of 'indices' should be equal to number of columns");
667 const auto max_index = (my_row_sparse ? my_ncol : my_nrow);
668 const auto num_indices = my_indices.size();
669 for (I<
decltype(num_indices)> i = 0; i < num_indices; ++i) {
670 const auto& curv = my_values[i];
671 const auto& curi = my_indices[i];
672 if (!sanisizer::is_equal(curv.size(), curi.size())) {
673 throw std::runtime_error(
"corresponding elements of 'values' and 'indices' should have the same length");
676 for (
const auto x : curi) {
677 if (x < 0 || sanisizer::is_greater_than_or_equal(x, max_index)) {
678 throw std::runtime_error(
"'indices' should contain non-negative integers less than the number of " + (my_row_sparse ? std::string(
"columns") : std::string(
"rows")));
682 const auto curnnz = curi.size();
683 for (I<
decltype(curnnz)> j = 1; j < curnnz; ++j) {
684 if (curi[j] <= curi[j - 1]) {
685 throw std::runtime_error(
"my_indices should be strictly increasing within each element of 'indices'");
696 FragmentedSparseMatrix(Index_ nrow, Index_ ncol, ValueVectorStorage_ values, IndexVectorStorage_ indices,
bool row_sparse,
bool check =
true) :
697 FragmentedSparseMatrix(
704 FragmentedSparseMatrixOptions fopt;
715 Index_ my_nrow, my_ncol;
716 ValueVectorStorage_ my_values;
717 IndexVectorStorage_ my_indices;
724 Index_
nrow()
const {
return my_nrow; }
729 Index_
ncol()
const {
return my_ncol; }
756 using Matrix<Value_, Index_>::dense;
758 using Matrix<Value_, Index_>::sparse;
761 Index_ secondary()
const {
776 std::unique_ptr<MyopicDenseExtractor<Value_, Index_> > dense(
780 if (my_row_sparse == row) {
781 return std::make_unique<FragmentedSparseMatrix_internal::PrimaryMyopicFullDense<Value_, Index_, ValueVectorStorage_, IndexVectorStorage_> >(
782 my_values, my_indices, secondary()
785 return std::make_unique<FragmentedSparseMatrix_internal::SecondaryMyopicFullDense<Value_, Index_, ValueVectorStorage_, IndexVectorStorage_> >(
786 my_values, my_indices, secondary()
794 std::unique_ptr<MyopicDenseExtractor<Value_, Index_> > dense(
796 const Index_ block_start,
797 const Index_ block_length,
800 if (my_row_sparse == row) {
801 return std::make_unique<FragmentedSparseMatrix_internal::PrimaryMyopicBlockDense<Value_, Index_, ValueVectorStorage_, IndexVectorStorage_> >(
802 my_values, my_indices, secondary(), block_start, block_length
805 return std::make_unique<FragmentedSparseMatrix_internal::SecondaryMyopicBlockDense<Value_, Index_, ValueVectorStorage_, IndexVectorStorage_> >(
806 my_values, my_indices, secondary(), block_start, block_length
814 std::unique_ptr<MyopicDenseExtractor<Value_, Index_> > dense(
816 VectorPtr<Index_> indices_ptr,
819 if (my_row_sparse == row) {
820 return std::make_unique<FragmentedSparseMatrix_internal::PrimaryMyopicIndexDense<Value_, Index_, ValueVectorStorage_, IndexVectorStorage_> >(
821 my_values, my_indices, secondary(), std::move(indices_ptr)
824 return std::make_unique<FragmentedSparseMatrix_internal::SecondaryMyopicIndexDense<Value_, Index_, ValueVectorStorage_, IndexVectorStorage_> >(
825 my_values, my_indices, secondary(), std::move(indices_ptr)
837 std::unique_ptr<MyopicSparseExtractor<Value_, Index_> > sparse(
841 if (my_row_sparse == row) {
842 return std::make_unique<FragmentedSparseMatrix_internal::PrimaryMyopicFullSparse<Value_, Index_, ValueVectorStorage_, IndexVectorStorage_> >(
843 my_values, my_indices, secondary(), opt
846 return std::make_unique<FragmentedSparseMatrix_internal::SecondaryMyopicFullSparse<Value_, Index_, ValueVectorStorage_, IndexVectorStorage_> >(
847 my_values, my_indices, secondary(), opt
855 std::unique_ptr<MyopicSparseExtractor<Value_, Index_> > sparse(
857 const Index_ block_start,
858 const Index_ block_length,
861 if (my_row_sparse == row) {
862 return std::make_unique<FragmentedSparseMatrix_internal::PrimaryMyopicBlockSparse<Value_, Index_, ValueVectorStorage_, IndexVectorStorage_> >(
863 my_values, my_indices, secondary(), block_start, block_length, opt
866 return std::make_unique<FragmentedSparseMatrix_internal::SecondaryMyopicBlockSparse<Value_, Index_, ValueVectorStorage_, IndexVectorStorage_> >(
867 my_values, my_indices, secondary(), block_start, block_length, opt
875 std::unique_ptr<MyopicSparseExtractor<Value_, Index_> > sparse(
877 VectorPtr<Index_> indices_ptr,
880 if (my_row_sparse == row) {
881 return std::make_unique<FragmentedSparseMatrix_internal::PrimaryMyopicIndexSparse<Value_, Index_, ValueVectorStorage_, IndexVectorStorage_> >(
882 my_values, my_indices, secondary(), std::move(indices_ptr), opt
885 return std::make_unique<FragmentedSparseMatrix_internal::SecondaryMyopicIndexSparse<Value_, Index_, ValueVectorStorage_, IndexVectorStorage_> >(
886 my_values, my_indices, secondary(), std::move(indices_ptr), opt
898 std::unique_ptr<OracularDenseExtractor<Value_, Index_> >
dense(
903 return std::make_unique<PseudoOracularDenseExtractor<Value_, Index_> >(std::move(oracle), dense(row, opt));
909 std::unique_ptr<OracularDenseExtractor<Value_, Index_> >
dense(
912 const Index_ block_start,
913 const Index_ block_length,
916 return std::make_unique<PseudoOracularDenseExtractor<Value_, Index_> >(std::move(oracle), dense(row, block_start, block_length, opt));
922 std::unique_ptr<OracularDenseExtractor<Value_, Index_> >
dense(
928 return std::make_unique<PseudoOracularDenseExtractor<Value_, Index_> >(std::move(oracle), dense(row, std::move(indices_ptr), opt));
938 std::unique_ptr<OracularSparseExtractor<Value_, Index_> >
sparse(
943 return std::make_unique<PseudoOracularSparseExtractor<Value_, Index_> >(std::move(oracle), sparse(row, opt));
949 std::unique_ptr<OracularSparseExtractor<Value_, Index_> >
sparse(
952 const Index_ block_start,
953 const Index_ block_length,
956 return std::make_unique<PseudoOracularSparseExtractor<Value_, Index_> >(std::move(oracle), sparse(row, block_start, block_length, opt));
962 std::unique_ptr<OracularSparseExtractor<Value_, Index_> >
sparse(
968 return std::make_unique<PseudoOracularSparseExtractor<Value_, Index_> >(std::move(oracle), sparse(row, std::move(indices_ptr), opt));
977template<
typename Value_,
typename Index_,
class ValueVectorStorage_ = std::vector<std::vector<Value_> >,
class IndexVectorStorage_ = std::vector<std::vector<Index_> > >
988 FragmentedSparseMatrix<Value_, Index_, ValueVectorStorage_, IndexVectorStorage_>(nrow, ncol, std::move(values), std::move(indices), false, check) {}
996template<
typename Value_,
typename Index_,
class ValueVectorStorage_ = std::vector<std::vector<Value_> >,
class IndexVectorStorage_ = std::vector<std::vector<Index_> > >
1007 FragmentedSparseMatrix<Value_, Index_, ValueVectorStorage_, IndexVectorStorage_>(nrow, ncol, std::move(values), std::move(indices), true, check) {}
Convert index type to container size.
Virtual class for a matrix of some numeric type.
Fragmented sparse column matrix.
Definition FragmentedSparseMatrix.hpp:978
FragmentedSparseColumnMatrix(Index_ nrow, Index_ ncol, ValueVectorStorage_ values, IndexVectorStorage_ indices, bool check=true)
Definition FragmentedSparseMatrix.hpp:987
Fragmented sparse matrix representation.
Definition FragmentedSparseMatrix.hpp:627
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 FragmentedSparseMatrix.hpp:962
std::unique_ptr< OracularSparseExtractor< Value_, Index_ > > sparse(const bool row, std::shared_ptr< const Oracle< Index_ > > oracle, const Options &opt) const
Definition FragmentedSparseMatrix.hpp:938
FragmentedSparseMatrix(const Index_ nrow, const Index_ ncol, ValueVectorStorage_ values, IndexVectorStorage_ indices, const bool row_sparse, const FragmentedSparseMatrixOptions &options)
Definition FragmentedSparseMatrix.hpp:638
Index_ ncol() const
Definition FragmentedSparseMatrix.hpp:729
double prefer_rows_proportion() const
Definition FragmentedSparseMatrix.hpp:749
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 FragmentedSparseMatrix.hpp:922
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 FragmentedSparseMatrix.hpp:949
double is_sparse_proportion() const
Definition FragmentedSparseMatrix.hpp:739
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 FragmentedSparseMatrix.hpp:909
Index_ nrow() const
Definition FragmentedSparseMatrix.hpp:724
bool is_sparse() const
Definition FragmentedSparseMatrix.hpp:734
std::unique_ptr< OracularDenseExtractor< Value_, Index_ > > dense(const bool row, std::shared_ptr< const Oracle< Index_ > > oracle, const Options &opt) const
Definition FragmentedSparseMatrix.hpp:898
bool prefer_rows() const
Definition FragmentedSparseMatrix.hpp:744
bool uses_oracle(const bool) const
Definition FragmentedSparseMatrix.hpp:754
Fragmented sparse row matrix.
Definition FragmentedSparseMatrix.hpp:997
FragmentedSparseRowMatrix(Index_ nrow, Index_ ncol, ValueVectorStorage_ values, IndexVectorStorage_ indices, bool check=true)
Definition FragmentedSparseMatrix.hpp:1006
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 FragmentedSparseMatrix().
Definition FragmentedSparseMatrix.hpp:591
bool check
Definition FragmentedSparseMatrix.hpp:602
Options for accessing data from a Matrix instance.
Definition Options.hpp:30