tatami
C++ API for different matrix representations
Loading...
Searching...
No Matches
DelayedSubset.hpp
Go to the documentation of this file.
1#ifndef TATAMI_DELAYED_SUBSET_HPP
2#define TATAMI_DELAYED_SUBSET_HPP
3
4#include "utils.hpp"
7
8#include <algorithm>
9#include <memory>
10
11#include "sanisizer/sanisizer.hpp"
12
21namespace tatami {
22
26namespace DelayedSubset_internal {
27
28template<typename Index_>
29struct DenseParallelResults {
30 std::vector<Index_> collapsed;
31 std::vector<Index_> reindex;
32};
33
34template<typename Index_, class SubsetStorage_, class ToIndex_>
35DenseParallelResults<Index_> format_dense_parallel_base(const SubsetStorage_& subset, const Index_ len, const ToIndex_ to_index) {
36 std::vector<std::pair<Index_, Index_> > collected;
37 collected.reserve(len);
38 for (Index_ i = 0; i < len; ++i) {
39 collected.emplace_back(subset[to_index(i)], i);
40 }
41 std::sort(collected.begin(), collected.end());
42
43 DenseParallelResults<Index_> output;
44 if (collected.size()) {
45 output.collapsed.reserve(len);
46 resize_container_to_Index_size(output.reindex, len);
47
48 Index_ last = collected.front().first;
49 output.collapsed.push_back(last);
50 output.reindex[collected.front().second] = 0;
51
52 Index_ counter = 0;
53 for (Index_ i = 1; i < len; ++i) {
54 const auto& pp = collected[i];
55 if (pp.first != last) {
56 last = pp.first;
57 output.collapsed.push_back(last);
58 ++counter;
59 }
60 output.reindex[pp.second] = counter;
61 }
62 }
63
64 return output;
65}
66
67template<bool oracle_, typename Value_, typename Index_>
68class ParallelDense final : public DenseExtractor<oracle_, Value_, Index_> {
69public:
70 template<class SubsetStorage_>
71 ParallelDense(
72 const Matrix<Value_, Index_>& matrix,
73 const SubsetStorage_& subset,
74 const bool row,
75 MaybeOracle<oracle_, Index_> oracle,
76 const Options& opt
77 ) {
78 auto processed = format_dense_parallel_base<Index_>(subset, subset.size(), [&](const Index_ i) -> Index_ { return i; });
79 initialize(matrix, std::move(processed), row, std::move(oracle), opt);
80 }
81
82 template<class SubsetStorage_>
83 ParallelDense(
84 const Matrix<Value_, Index_>& matrix,
85 const SubsetStorage_& subset,
86 const bool row,
87 MaybeOracle<oracle_, Index_> oracle,
88 const Index_ block_start,
89 const Index_ block_length,
90 const Options& opt
91 ) {
92 auto processed = format_dense_parallel_base<Index_>(subset, block_length, [&](const Index_ i) -> Index_ { return i + block_start; });
93 initialize(matrix, std::move(processed), row, std::move(oracle), opt);
94 }
95
96 template<class SubsetStorage_>
97 ParallelDense(
98 const Matrix<Value_, Index_>& matrix,
99 const SubsetStorage_& subset,
100 const bool row,
101 MaybeOracle<oracle_, Index_> oracle,
102 VectorPtr<Index_> indices_ptr,
103 const Options& opt
104 ) {
105 const auto& indices = *indices_ptr;
106 auto processed = format_dense_parallel_base<Index_>(subset, indices.size(), [&](const Index_ i) -> Index_ { return indices[i]; });
107 initialize(matrix, std::move(processed), row, std::move(oracle), opt);
108 }
109
110private:
111 void initialize(
112 const Matrix<Value_, Index_>& matrix,
113 DenseParallelResults<Index_> processed,
114 const bool row,
115 MaybeOracle<oracle_, Index_> oracle,
116 const Options& opt
117 ) {
118 resize_container_to_Index_size(my_holding_vbuffer, processed.collapsed.size()); // processed.collapsed.size() should fit in an Index_, so this cast is safe.
119 my_ext = make_Extractor<false, oracle_>(matrix, row, std::move(oracle), subset_utils::as_VectorPtr(std::move(processed.collapsed)), opt);
120 my_reindex.swap(processed.reindex);
121 }
122
123public:
124 const Value_* fetch(const Index_ i, Value_* const buffer) {
125 const auto src = my_ext->fetch(i, my_holding_vbuffer.data());
126
127 // 'src' and 'buffer' should not point to the same array.
128 auto copy = buffer;
129 for (auto p : my_reindex) {
130 *copy= src[p];
131 ++copy;
132 }
133
134 return buffer;
135 }
136
137private:
138 std::unique_ptr<DenseExtractor<oracle_, Value_, Index_> > my_ext;
139 std::vector<Value_> my_holding_vbuffer;
140 std::vector<Index_> my_reindex;
141};
142
143template<typename Index_>
144struct SparseParallelReindex {
145 // This is a bit complicated to explain.
146 // Let 'x = pool_ptrs[i - offset]'.
147 // Let 'y = pool_ptrs[i - offset + 1]'.
148 // Let 'z' denote any integer in '[x, y)'.
149 // In which case, 'indices[pool_indices[z]]' is equal to 'i'.
150 // The general idea is that 'pool_indices[z]' can be used to fill the 'SparseRange::index' on output.
151 std::vector<Index_> pool_ptrs; // this can be Index_ as the length of 'pool_indices' is no greater than the output dimension extent.
152 std::vector<Index_> pool_indices;
153 Index_ offset;
154};
155
156template<typename Index_>
157struct SparseParallelResults {
158 std::vector<Index_> collapsed;
159 SparseParallelReindex<Index_> reindex;
160};
161
162template<typename Index_, class SubsetStorage_, class ToIndex_>
163SparseParallelResults<Index_> format_sparse_parallel_base(const SubsetStorage_& indices, const Index_ len, const ToIndex_ to_index) {
164 std::vector<std::pair<Index_, Index_> > collected;
165 collected.reserve(len);
166 for (Index_ i = 0; i < len; ++i) {
167 const auto curdex = to_index(i);
168 collected.emplace_back(indices[curdex], curdex);
169 }
170 std::sort(collected.begin(), collected.end());
171
172 SparseParallelResults<Index_> output;
173
174 if (collected.size()) {
175 output.collapsed.reserve(len);
176 output.reindex.pool_indices.reserve(len);
177 const Index_ first = collected.front().first;
178
179 // 'pool_ptrs' is a vector that enables look-up according to the indices of the underlying array.
180 // To avoid the need to allocate a vector of length equal to the underlying array's dimension, we only consider the extremes of 'indices'.
181 // We allocate 'pool_ptrs' to have length equal to the range of 'indices'... plus 1, as we're storing cumulative pointers.
182 // 'offset' defines the lower bound that must be subtracted from the array indices to get an index into 'pool_ptrs'.
183 output.reindex.offset = first;
184 const Index_ allocation = collected.back().first - output.reindex.offset + 1;
185 output.reindex.pool_ptrs.resize(sanisizer::sum<I<decltype(output.reindex.pool_ptrs.size())> >(attest_for_Index(allocation), 1));
186
187 Index_ counter = 0; // this can never be larger than 'len', so using Index_ will not lead to overflows.
188 output.reindex.pool_ptrs[counter] = 0;
189 ++counter;
190 output.reindex.pool_indices.push_back(collected.front().second);
191 output.reindex.pool_ptrs[counter] = 1;
192 output.collapsed.push_back(first);
193 auto last = first;
194
195 for (Index_ i = 1; i < len; ++i) {
196 const auto& pp = collected[i];
197 const auto current = pp.first;
198 if (current == last) {
199 output.reindex.pool_indices.push_back(pp.second);
200 ++(output.reindex.pool_ptrs[counter]); // contents of pool_ptrs will never be greater than len, so this won't overflow.
201 continue;
202 }
203
204 const Index_ pool_size = output.reindex.pool_indices.size();
205 counter = current - output.reindex.offset;
206 output.reindex.pool_ptrs[counter] = pool_size; // any overwrite is safe as the value is unchanged.
207 ++counter;
208 output.reindex.pool_indices.push_back(pp.second);
209 output.reindex.pool_ptrs[counter] = pool_size + 1;
210 output.collapsed.push_back(current);
211 last = current;
212 }
213 }
214
215 return output;
216}
217
218template<bool oracle_, typename Value_, typename Index_>
219class ParallelSparse final : public SparseExtractor<oracle_, Value_, Index_> {
220public:
221 template<class SubsetStorage_>
222 ParallelSparse(
223 const Matrix<Value_, Index_>& mat,
224 const SubsetStorage_& subset,
225 const bool row,
226 MaybeOracle<oracle_, Index_> oracle,
227 const Options& opt
228 ) {
229 auto processed = format_sparse_parallel_base<Index_>(subset, subset.size(), [](const Index_ i) -> Index_ { return i; });
230 initialize(mat, std::move(processed), subset.size(), row, std::move(oracle), opt);
231 }
232
233 template<class SubsetStorage_>
234 ParallelSparse(
235 const Matrix<Value_, Index_>& mat,
236 const SubsetStorage_& subset,
237 const bool row,
238 MaybeOracle<oracle_, Index_> oracle,
239 const Index_ block_start,
240 const Index_ block_length,
241 const Options& opt
242 ) {
243 auto processed = format_sparse_parallel_base<Index_>(subset, block_length, [&](const Index_ i) -> Index_ { return i + block_start; });
244 initialize(mat, std::move(processed), block_length, row, std::move(oracle), opt);
245 }
246
247 template<class SubsetStorage_>
248 ParallelSparse(
249 const Matrix<Value_, Index_>& mat,
250 const SubsetStorage_& subset,
251 const bool row,
252 MaybeOracle<oracle_, Index_> oracle,
253 VectorPtr<Index_> indices_ptr,
254 const Options& opt
255 ) {
256 const auto& indices = *indices_ptr;
257 auto processed = format_sparse_parallel_base<Index_>(subset, indices.size(), [&](const Index_ i) -> Index_ { return indices[i]; });
258 initialize(mat, std::move(processed), indices.size(), row, std::move(oracle), opt);
259 }
260
261private:
262 void initialize(
263 const Matrix<Value_, Index_>& mat,
264 SparseParallelResults<Index_> processed,
265 const Index_ extent,
266 const bool row,
267 MaybeOracle<oracle_, Index_> oracle,
268 Options opt
269 ) {
270 const Index_ num_collapsed = processed.collapsed.size(); // number of unique subset indices should be no greater than the extent.
271 my_shift = extent - num_collapsed;
272
273 my_needs_value = opt.sparse_extract_value;
274 my_needs_index = opt.sparse_extract_index;
275 my_needs_sort = opt.sparse_ordered_index;
276
277 if (my_needs_sort && my_needs_value) {
278 my_sortspace.reserve(extent);
279 }
280
281 // We need to extract indices for sorting and expansion purposes, even if they weren't actually requested.
282 opt.sparse_extract_index = true;
283 if (!my_needs_index) {
284 resize_container_to_Index_size(my_holding_ibuffer, num_collapsed);
285 }
286
287 my_ext = make_Extractor<true, oracle_>(mat, row, std::move(oracle), subset_utils::as_VectorPtr(std::move(processed.collapsed)), opt);
288 my_reindex = std::move(processed.reindex);
289 }
290
291public:
292 SparseRange<Value_, Index_> fetch(const Index_ i, Value_* const vbuffer, Index_* const ibuffer) {
293 const auto vinit = (my_needs_value ? vbuffer + my_shift : NULL);
294 const auto iinit = (my_needs_index ? ibuffer + my_shift : my_holding_ibuffer.data());
295 auto input = my_ext->fetch(i, vinit, iinit);
296
297 if (!my_needs_sort) {
298 // Pointers in 'input' and the two 'buffer' pointers may optionally point
299 // to overlapping arrays as long as each 'buffer' pointer precedes its
300 // corresponding pointer in 'input'. The idea is that the expansion of
301 // values into, e.g., 'vbuffer' will cause it to catch up to 'input.value'
302 // without clobbering any values in the latter. This assumes that
303 // 'input.value' has been shifted enough to make space for expansion; the
304 // required shift depends on the number of duplicates.
305 Index_ count = 0;
306 auto vcopy = vbuffer;
307 auto icopy = ibuffer;
308
309 auto vsrc = input.value;
310 bool replace_value = my_needs_value && vsrc != vcopy;
311
312 for (Index_ i = 0; i < input.number; ++i) {
313 const auto lookup = input.index[i] - my_reindex.offset;
314 const auto start = my_reindex.pool_ptrs[lookup];
315 const auto num = my_reindex.pool_ptrs[lookup + 1] - start;
316 count += num;
317
318 if (replace_value) {
319 auto val = *vsrc; // make a copy just in case 'vcopy' and 'input.value' overlap.
320 std::fill_n(vcopy, num, val);
321 vcopy += num;
322 ++vsrc;
323 replace_value = (vcopy != vsrc); // if we've caught up, there no need to do this replacement.
324 }
325
326 if (my_needs_index) {
327 // Again, 'icopy' will eventually catch up to 'input.index' if
328 // they point to overlapping arrays. But we still need to
329 // replace values once we've managed to catch up, so we can't
330 // short-circuit like we did with 'replace_value'.
331 std::copy_n(my_reindex.pool_indices.begin() + start, num, icopy);
332 icopy += num;
333 }
334 }
335
336 input.number = count;
337 if (my_needs_value) {
338 input.value = vbuffer;
339 }
340 if (my_needs_index) {
341 input.index = ibuffer;
342 } else {
343 input.index = NULL;
344 }
345
346 } else if (my_needs_value) {
347 // This does not require any careful consideration of the overlaps
348 // between 'input' and 'buffers', as we're copying things into
349 // 'my_sortspace' anyway before copying them back into 'buffer'.
350 my_sortspace.clear();
351 for (Index_ i = 0; i < input.number; ++i) {
352 const auto val = input.value[i];
353 const auto lookup = input.index[i] - my_reindex.offset;
354 const auto start = my_reindex.pool_ptrs[lookup];
355 const auto end = my_reindex.pool_ptrs[lookup + 1];
356 for (Index_ j = start; j < end; ++j) {
357 my_sortspace.emplace_back(my_reindex.pool_indices[j], val);
358 }
359 }
360 std::sort(my_sortspace.begin(), my_sortspace.end());
361 input.number = my_sortspace.size();
362
363 auto vcopy = vbuffer;
364 for (const auto& ss : my_sortspace) {
365 *vcopy = ss.second;
366 ++vcopy;
367 }
368 input.value = vbuffer;
369
370 if (my_needs_index) {
371 auto icopy = ibuffer;
372 for (const auto& ss : my_sortspace) {
373 *icopy = ss.first;
374 ++icopy;
375 }
376 input.index = ibuffer;
377 } else {
378 input.index = NULL;
379 }
380
381 } else {
382 // Again, 'input.index' and 'ibuffer' may point to overlapping arrays,
383 // as long as the latter precedes the former; expansion into the latter
384 // will allow it to catch up to the former without clobbering, assuming
385 // that the latter was shifted back to provide enough space.
386 Index_ count = 0;
387 auto icopy = ibuffer;
388
389 for (Index_ i = 0; i < input.number; ++i) {
390 const auto lookup = input.index[i] - my_reindex.offset;
391 const auto start = my_reindex.pool_ptrs[lookup];
392 const auto num = my_reindex.pool_ptrs[lookup + 1] - start;
393 count += num;
394
395 if (my_needs_index) {
396 std::copy_n(my_reindex.pool_indices.begin() + start, num, icopy);
397 icopy += num;
398 }
399 }
400
401 input.number = count;
402 if (my_needs_index) {
403 std::sort(ibuffer, ibuffer + count);
404 input.index = ibuffer;
405 } else {
406 input.index = NULL;
407 }
408 }
409
410 return input;
411 }
412
413private:
414 std::unique_ptr<SparseExtractor<oracle_, Value_, Index_> > my_ext;
415 bool my_needs_value, my_needs_index, my_needs_sort;
416 SparseParallelReindex<Index_> my_reindex;
417 std::vector<std::pair<Index_, Value_> > my_sortspace;
418 std::vector<Index_> my_holding_ibuffer;
419 Index_ my_shift;
420};
421
422}
438template<typename Value_, typename Index_, class SubsetStorage_>
439class DelayedSubset final : public Matrix<Value_, Index_> {
440public:
449 std::shared_ptr<const Matrix<Value_, Index_> > matrix,
450 SubsetStorage_ subset,
451 const bool by_row
452 ) :
453 my_matrix(std::move(matrix)),
454 my_subset(std::move(subset)),
455 my_by_row(by_row)
456 {
457 // Check that we can still report the dimension extents of the subsetted matrix.
458 sanisizer::can_cast<Index_>(my_subset.size());
459 }
460
461private:
462 std::shared_ptr<const Matrix<Value_, Index_> > my_matrix;
463 SubsetStorage_ my_subset;
464 bool my_by_row;
465
466public:
467 Index_ nrow() const {
468 if (my_by_row) {
469 return my_subset.size();
470 } else {
471 return my_matrix->nrow();
472 }
473 }
474
475 Index_ ncol() const {
476 if (my_by_row) {
477 return my_matrix->ncol();
478 } else {
479 return my_subset.size();
480 }
481 }
482
483 bool is_sparse() const {
484 return my_matrix->is_sparse();
485 }
486
487 double is_sparse_proportion() const {
488 return my_matrix->is_sparse_proportion();
489 }
490
491 bool prefer_rows() const {
492 return my_matrix->prefer_rows();
493 }
494
495 double prefer_rows_proportion() const {
496 return my_matrix->prefer_rows_proportion();
497 }
498
499 bool uses_oracle(const bool row) const {
500 return my_matrix->uses_oracle(row);
501 }
502
503 using Matrix<Value_, Index_>::dense;
504
505 using Matrix<Value_, Index_>::sparse;
506
507 /********************
508 *** Myopic dense ***
509 ********************/
510private:
511 template<typename ... Args_>
512 std::unique_ptr<MyopicDenseExtractor<Value_, Index_> > populate_myopic_dense(
513 const bool row,
514 Args_&& ... args
515 ) const {
516 if (row == my_by_row) {
517 return std::make_unique<subset_utils::MyopicPerpendicularDense<Value_, Index_, SubsetStorage_> >(
518 *my_matrix,
519 my_subset,
520 row,
521 std::forward<Args_>(args)...
522 );
523 } else {
524 return std::make_unique<DelayedSubset_internal::ParallelDense<false, Value_, Index_> >(
525 *my_matrix,
526 my_subset,
527 row,
528 false,
529 std::forward<Args_>(args)...
530 );
531 }
532 }
533
534public:
535 std::unique_ptr<MyopicDenseExtractor<Value_, Index_> > dense(
536 const bool row,
537 const Options& opt
538 ) const {
539 return populate_myopic_dense(row, opt);
540 }
541
542 std::unique_ptr<MyopicDenseExtractor<Value_, Index_> > dense(
543 const bool row,
544 const Index_ block_start,
545 const Index_ block_length,
546 const Options& opt
547 ) const {
548 return populate_myopic_dense(row, block_start, block_length, opt);
549 }
550
551 std::unique_ptr<MyopicDenseExtractor<Value_, Index_> > dense(
552 const bool row,
553 VectorPtr<Index_> my_subset_ptr,
554 const Options& opt
555 ) const {
556 return populate_myopic_dense(row, std::move(my_subset_ptr), opt);
557 }
558
559 /*********************
560 *** Myopic sparse ***
561 *********************/
562private:
563 template<typename ... Args_>
564 std::unique_ptr<MyopicSparseExtractor<Value_, Index_> > populate_myopic_sparse(
565 const bool row,
566 Args_&& ... args
567 ) const {
568 if (row == my_by_row) {
569 return std::make_unique<subset_utils::MyopicPerpendicularSparse<Value_, Index_, SubsetStorage_> >(
570 *my_matrix,
571 my_subset,
572 row,
573 std::forward<Args_>(args)...
574 );
575 } else {
576 return std::make_unique<DelayedSubset_internal::ParallelSparse<false, Value_, Index_> >(
577 *my_matrix,
578 my_subset,
579 row,
580 false,
581 std::forward<Args_>(args)...
582 );
583 }
584 }
585
586public:
587 std::unique_ptr<MyopicSparseExtractor<Value_, Index_> > sparse(
588 const bool row,
589 const Options& opt
590 ) const {
591 return populate_myopic_sparse(row, opt);
592 }
593
594 std::unique_ptr<MyopicSparseExtractor<Value_, Index_> > sparse(
595 const bool row,
596 const Index_ block_start,
597 const Index_ block_length,
598 const Options& opt
599 ) const {
600 return populate_myopic_sparse(row, block_start, block_length, opt);
601 }
602
603 std::unique_ptr<MyopicSparseExtractor<Value_, Index_> > sparse(
604 const bool row,
605 VectorPtr<Index_> my_subset_ptr,
606 const Options& opt
607 ) const {
608 return populate_myopic_sparse(row, std::move(my_subset_ptr), opt);
609 }
610
611 /**********************
612 *** Oracular dense ***
613 **********************/
614private:
615 template<typename ... Args_>
616 std::unique_ptr<OracularDenseExtractor<Value_, Index_> > populate_oracular_dense(
617 const bool row,
618 std::shared_ptr<const Oracle<Index_> > oracle,
619 Args_&& ... args
620 ) const {
621 if (row == my_by_row) {
622 return std::make_unique<subset_utils::OracularPerpendicularDense<Value_, Index_> >(
623 *my_matrix,
624 my_subset,
625 row,
626 std::move(oracle),
627 std::forward<Args_>(args)...
628 );
629 } else {
630 return std::make_unique<DelayedSubset_internal::ParallelDense<true, Value_, Index_> >(
631 *my_matrix,
632 my_subset,
633 row,
634 std::move(oracle),
635 std::forward<Args_>(args)...
636 );
637 }
638 }
639
640public:
641 std::unique_ptr<OracularDenseExtractor<Value_, Index_> > dense(
642 const bool row,
643 std::shared_ptr<const Oracle<Index_> > oracle,
644 const Options& opt
645 ) const {
646 return populate_oracular_dense(row, std::move(oracle), opt);
647 }
648
649 std::unique_ptr<OracularDenseExtractor<Value_, Index_> > dense(
650 const bool row,
651 std::shared_ptr<const Oracle<Index_> > oracle,
652 const Index_ block_start,
653 const Index_ block_length,
654 const Options& opt
655 ) const {
656 return populate_oracular_dense(row, std::move(oracle), block_start, block_length, opt);
657 }
658
659 std::unique_ptr<OracularDenseExtractor<Value_, Index_> > dense(
660 const bool row,
661 std::shared_ptr<const Oracle<Index_> > oracle,
662 VectorPtr<Index_> my_subset_ptr,
663 const Options& opt
664 ) const {
665 return populate_oracular_dense(row, std::move(oracle), std::move(my_subset_ptr), opt);
666 }
667
668 /***********************
669 *** Oracular sparse ***
670 ***********************/
671private:
672 template<typename ... Args_>
673 std::unique_ptr<OracularSparseExtractor<Value_, Index_> > populate_oracular_sparse(
674 const bool row,
675 std::shared_ptr<const Oracle<Index_> > oracle,
676 Args_&& ... args
677 ) const {
678 if (row == my_by_row) {
679 return std::make_unique<subset_utils::OracularPerpendicularSparse<Value_, Index_> >(
680 *my_matrix,
681 my_subset,
682 row,
683 std::move(oracle),
684 std::forward<Args_>(args)...
685 );
686 } else {
687 return std::make_unique<DelayedSubset_internal::ParallelSparse<true, Value_, Index_> >(
688 *my_matrix,
689 my_subset,
690 row,
691 std::move(oracle),
692 std::forward<Args_>(args)...
693 );
694 }
695 }
696
697public:
698 std::unique_ptr<OracularSparseExtractor<Value_, Index_> > sparse(
699 const bool row,
700 std::shared_ptr<const Oracle<Index_> > oracle,
701 const Options& opt
702 ) const {
703 return populate_oracular_sparse(row, std::move(oracle), opt);
704 }
705
706 std::unique_ptr<OracularSparseExtractor<Value_, Index_> > sparse(
707 const bool row,
708 std::shared_ptr<const Oracle<Index_> > oracle,
709 const Index_ block_start,
710 const Index_ block_length,
711 const Options& opt
712 ) const {
713 return populate_oracular_sparse(row, std::move(oracle), block_start, block_length, opt);
714 }
715
716 std::unique_ptr<OracularSparseExtractor<Value_, Index_> > sparse(
717 const bool row,
718 std::shared_ptr<const Oracle<Index_> > oracle,
719 VectorPtr<Index_> my_subset_ptr,
720 const Options& opt
721 ) const {
722 return populate_oracular_sparse(row, std::move(oracle), std::move(my_subset_ptr), opt);
723 }
724};
725
726}
727
728#endif
Convert index type to container size.
Delayed subsetting of a matrix with general indices.
Definition DelayedSubset.hpp:439
bool uses_oracle(const bool row) const
Definition DelayedSubset.hpp:499
std::unique_ptr< MyopicSparseExtractor< Value_, Index_ > > sparse(const bool row, VectorPtr< Index_ > my_subset_ptr, const Options &opt) const
Definition DelayedSubset.hpp:603
std::unique_ptr< OracularDenseExtractor< Value_, Index_ > > dense(const bool row, std::shared_ptr< const Oracle< Index_ > > oracle, const Options &opt) const
Definition DelayedSubset.hpp:641
Index_ ncol() const
Definition DelayedSubset.hpp:475
bool prefer_rows() const
Definition DelayedSubset.hpp:491
DelayedSubset(std::shared_ptr< const Matrix< Value_, Index_ > > matrix, SubsetStorage_ subset, const bool by_row)
Definition DelayedSubset.hpp:448
std::unique_ptr< MyopicDenseExtractor< Value_, Index_ > > dense(const bool row, const Options &opt) const
Definition DelayedSubset.hpp:535
std::unique_ptr< MyopicSparseExtractor< Value_, Index_ > > sparse(const bool row, const Index_ block_start, const Index_ block_length, const Options &opt) const
Definition DelayedSubset.hpp:594
std::unique_ptr< OracularSparseExtractor< Value_, Index_ > > sparse(const bool row, std::shared_ptr< const Oracle< Index_ > > oracle, const Options &opt) const
Definition DelayedSubset.hpp:698
std::unique_ptr< OracularDenseExtractor< Value_, Index_ > > dense(const bool row, std::shared_ptr< const Oracle< Index_ > > oracle, VectorPtr< Index_ > my_subset_ptr, const Options &opt) const
Definition DelayedSubset.hpp:659
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 DelayedSubset.hpp:706
double prefer_rows_proportion() const
Definition DelayedSubset.hpp:495
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 DelayedSubset.hpp:649
std::unique_ptr< MyopicDenseExtractor< Value_, Index_ > > dense(const bool row, VectorPtr< Index_ > my_subset_ptr, const Options &opt) const
Definition DelayedSubset.hpp:551
std::unique_ptr< MyopicSparseExtractor< Value_, Index_ > > sparse(const bool row, const Options &opt) const
Definition DelayedSubset.hpp:587
std::unique_ptr< OracularSparseExtractor< Value_, Index_ > > sparse(const bool row, std::shared_ptr< const Oracle< Index_ > > oracle, VectorPtr< Index_ > my_subset_ptr, const Options &opt) const
Definition DelayedSubset.hpp:716
Index_ nrow() const
Definition DelayedSubset.hpp:467
bool is_sparse() const
Definition DelayedSubset.hpp:483
std::unique_ptr< MyopicDenseExtractor< Value_, Index_ > > dense(const bool row, const Index_ block_start, const Index_ block_length, const Options &opt) const
Definition DelayedSubset.hpp:542
double is_sparse_proportion() const
Definition DelayedSubset.hpp:487
Virtual class for a matrix.
Definition Matrix.hpp:59
Predict future access requests on the target dimension.
Definition Oracle.hpp:29
Templated construction of a new extractor.
Flexible representations for matrix data.
Definition Extractor.hpp:15
std::shared_ptr< const std::vector< Index_ > > VectorPtr
Definition Matrix.hpp:26
void resize_container_to_Index_size(Container_ &container, const Index_ x, Args_ &&... args)
Definition Index_to_container.hpp:85
typename std::conditional< oracle_, OracularDenseExtractor< Value_, Index_ >, MyopicDenseExtractor< Value_, Index_ > >::type DenseExtractor
Definition Extractor.hpp:284
Options for accessing data from a Matrix instance.
Definition Options.hpp:30