tatami
C++ API for different matrix representations
Loading...
Searching...
No Matches
DelayedSubsetSorted.hpp
Go to the documentation of this file.
1#ifndef TATAMI_DELAYED_SUBSET_SORTED_HPP
2#define TATAMI_DELAYED_SUBSET_SORTED_HPP
3
4#include "utils.hpp"
5#include "../base/Matrix.hpp"
8
9#include <algorithm>
10#include <numeric>
11#include <memory>
12
13#include "sanisizer/sanisizer.hpp"
14
23namespace tatami {
24
28namespace DelayedSubsetSorted_internal {
29
30template<typename Index_>
31struct DenseParallelResults {
32 std::vector<Index_> collapsed;
33 std::vector<Index_> expansion;
34};
35
36template<typename Index_, class SubsetStorage_, class ToIndex_>
37DenseParallelResults<Index_> format_dense_parallel(const SubsetStorage_& indices, const Index_ len, const ToIndex_ to_index) {
38 DenseParallelResults<Index_> output;
39 output.expansion.reserve(len);
40 output.collapsed.reserve(len);
41
42 if (len) {
43 auto last = indices[to_index(0)];
44 output.expansion.push_back(1);
45 output.collapsed.push_back(last);
46
47 for (Index_ i = 1; i < len; ++i) {
48 const auto current = indices[to_index(i)];
49 if (current == last) {
50 ++(output.expansion.back());
51 } else {
52 last = current;
53 output.expansion.push_back(1);
54 output.collapsed.push_back(last);
55 }
56 }
57 }
58
59 return output;
60}
61
62template<bool oracle_, typename Value_, typename Index_>
63class ParallelDense final : public DenseExtractor<oracle_, Value_, Index_> {
64public:
65 template<class SubsetStorage_>
66 ParallelDense(
67 const Matrix<Value_, Index_>& matrix,
68 const SubsetStorage_& subset,
69 const bool row,
70 MaybeOracle<oracle_, Index_> oracle,
71 const Options& opt
72 ) {
73 auto processed = format_dense_parallel<Index_>(subset, subset.size(), [&](const Index_ i) -> Index_ { return i; });
74 initialize(matrix, std::move(processed), subset.size(), row, std::move(oracle), opt);
75 }
76
77 template<class SubsetStorage_>
78 ParallelDense(
79 const Matrix<Value_, Index_>& matrix,
80 const SubsetStorage_& subset,
81 const bool row,
82 MaybeOracle<oracle_, Index_> oracle,
83 const Index_ block_start,
84 const Index_ block_length,
85 const Options& opt
86 ) {
87 auto processed = format_dense_parallel<Index_>(subset, block_length, [&](const Index_ i) -> Index_ { return i + block_start; });
88 initialize(matrix, std::move(processed), block_length, row, std::move(oracle), opt);
89 }
90
91 template<class SubsetStorage_>
92 ParallelDense(
93 const Matrix<Value_, Index_>& matrix,
94 const SubsetStorage_& subset,
95 const bool row,
96 MaybeOracle<oracle_, Index_> oracle,
97 VectorPtr<Index_> indices_ptr,
98 const Options& opt
99 ) {
100 const auto& indices = *indices_ptr;
101 auto processed = format_dense_parallel<Index_>(subset, indices.size(), [&](const Index_ i) -> Index_ { return indices[i]; });
102 initialize(matrix, std::move(processed), indices.size(), row, std::move(oracle), opt);
103 }
104
105private:
106 void initialize(
107 const Matrix<Value_, Index_>& mat,
108 DenseParallelResults<Index_> processed,
109 const Index_ extent,
110 const bool row,
111 MaybeOracle<oracle_, Index_> oracle,
112 const Options& opt
113 ) {
114 my_shift = extent - processed.collapsed.size();
115 my_ext = make_Extractor<false, oracle_>(mat, row, std::move(oracle), subset_utils::as_VectorPtr(std::move(processed.collapsed)), opt);
116 my_expansion = std::move(processed.expansion);
117 }
118
119public:
120 const Value_* fetch(const Index_ i, Value_* const buffer) {
121 auto input = my_ext->fetch(i, buffer + my_shift);
122
123 // 'input' and 'buffer' may optionally point to overlapping arrays as long
124 // as 'buffer' precedes 'input'. The idea is that the expansion of values
125 // into 'buffer' will cause it to "catch up" to 'input' without clobbering
126 // any values in the latter. This assumes that 'input' has been shifted
127 // enough to make space for expansion; the required shift depends on the
128 // number of duplicates in 'expansion'.
129
130 auto copy = buffer;
131 for (const auto e : my_expansion) {
132 // Once we've caught up, everything else must be a non-duplicate,
133 // otherwise we'd be clobbering as-yet-unread values from the input.
134 // So we might as well just quit at this point.
135 if (input == copy) {
136 break;
137 }
138
139 std::fill_n(copy, e, *input);
140 ++input;
141 copy += e;
142 }
143
144 return buffer;
145 }
146
147private:
148 std::unique_ptr<DenseExtractor<oracle_, Value_, Index_> > my_ext;
149 std::vector<Index_> my_expansion;
150 Index_ my_shift;
151};
152
153template<typename Index_>
154struct SparseParallelExpansion {
155 // This is a bit complicated to explain.
156 // Let 'x = start[i - offset]'.
157 // Let 'y = lengths[i - offset]'.
158 // Let 'z' denote any integer in '[x, x + y)'.
159 // Let 'f' be the selection-specific function such that 'f(a)' is the a-th element of the selection
160 // (i.e., 'a' for full selection, 'a + start' for block selection and 'subset[a]' for indexed selection).
161 // In which case, 'indices[f(z)]' is equal to 'i'.
162 // The general idea is that 'f(z)' can be used to fill the 'SparseRange::index' on output.
163 std::vector<Index_> start;
164 std::vector<Index_> length;
165
166 Index_ offset = 0;
167};
168
169template<typename Index_>
170struct SparseParallelResults {
171 std::vector<Index_> collapsed;
172 SparseParallelExpansion<Index_> expansion;
173};
174
175template<typename Index_, class SubsetStorage_, class ToIndex_>
176SparseParallelResults<Index_> format_sparse_parallel(const SubsetStorage_& indices, const Index_ len, const ToIndex_ to_index) {
177 SparseParallelResults<Index_> output;
178
179 if (len) {
180 output.collapsed.reserve(len);
181 const auto first = indices[to_index(0)];
182
183 // 'start' and 'length' are vectors that enable look-up according to the indices of the underlying array.
184 // To avoid the need to allocate a vector of length equal to the underlying array's dimension, we only consider the extremes of 'indices'.
185 // We allocate both start/length vectors to have length equal to the range of 'indices'.
186 // The 'offset' defines the lower bound that must be subtracted from the array indices to get an index into 'start' or 'length'.
187 output.expansion.offset = first;
188 const Index_ allocation = indices[to_index(len - 1)] - output.expansion.offset + 1; // fits in an Index_ as it should be no greater than the input matrix's dimension extent.
189 resize_container_to_Index_size(output.expansion.start, allocation);
190 output.expansion.length.resize(output.expansion.start.size());
191
192 Index_ lookup = 0;
193 output.expansion.start[0] = 0;
194 output.expansion.length[0] = 1;
195 output.collapsed.push_back(first);
196 auto last = first;
197
198 for (Index_ i = 1; i < len; ++i) {
199 const auto current = indices[to_index(i)];
200 if (current == last) {
201 ++(output.expansion.length[lookup]);
202 continue;
203 }
204
205 lookup = current - output.expansion.offset;
206 output.expansion.start[lookup] = i;
207 output.expansion.length[lookup] = 1;
208 output.collapsed.push_back(current);
209 last = current;
210 }
211 }
212
213 return output;
214}
215
216template<bool oracle_, typename Value_, typename Index_>
217class ParallelSparseCore {
218public:
219 template<class SubsetStorage_, class ToIndex_>
220 ParallelSparseCore(
221 const Matrix<Value_, Index_>& matrix,
222 const SubsetStorage_& subset,
223 const Index_ extent,
224 const bool row,
225 MaybeOracle<oracle_, Index_> oracle,
226 Options opt,
227 ToIndex_&& to_index
228 ) {
229 auto processed = format_sparse_parallel<Index_>(subset, extent, std::forward<ToIndex_>(to_index));
230 my_shift = extent - processed.collapsed.size();
231
232 my_needs_value = opt.sparse_extract_value;
233 my_needs_index = opt.sparse_extract_index;
234 opt.sparse_extract_index = true; // must extract the indices for proper my_expansion.
235 if (!my_needs_index) {
236 // Need a holding space for indices if 'ibuffer' is not supplied.
237 resize_container_to_Index_size(my_holding_ibuffer, processed.collapsed.size()); // processed.collapsed.size() should fit in an Index_, hence the cast is safe.
238 }
239
240 my_ext = make_Extractor<true, oracle_>(matrix, row, std::move(oracle), subset_utils::as_VectorPtr(std::move(processed.collapsed)), opt);
241 my_expansion = std::move(processed.expansion);
242 }
243
244 template<class ToIndex_>
245 SparseRange<Value_, Index_> fetch(const Index_ i, Value_* const value_buffer, Index_* const index_buffer, const ToIndex_ to_index) {
246 // Shifting so that there's enough space for my_expansion, but only doing
247 // so if these pointers are guaranteed to be non-NULL.
248 const auto vinit = (my_needs_value ? value_buffer + my_shift : NULL);
249 const auto iinit = (my_needs_index ? index_buffer + my_shift : my_holding_ibuffer.data());
250 const auto input = my_ext->fetch(i, vinit, iinit);
251
252 auto vcopy = value_buffer;
253 auto icopy = index_buffer;
254 Index_ count = 0;
255
256 auto vsrc = input.value;
257 bool replace_value = my_needs_value && vsrc != vcopy;
258
259 // Pointers in 'input' and the two 'buffer' pointers may optionally point
260 // to overlapping arrays as long as each 'buffer' pointer precede its
261 // corresponding pointer in 'input'. The idea is that the expansion of
262 // values into 'buffer' will cause it to "catch up" to 'input' without
263 // clobbering any values in the latter. This assumes that 'input' has been
264 // shift enough to make space for expansion; the required shift depends
265 // on the number of duplicates.
266 for (Index_ i = 0; i < input.number; ++i) {
267 const auto eindex = input.index[i] - my_expansion.offset;
268 const auto nexpand = my_expansion.length[eindex];
269 count += nexpand;
270
271 if (replace_value) {
272 const auto v = *vsrc; // make a copy just in case 'vcopy' and 'input.value' overlap.
273 std::fill_n(vcopy, nexpand, v);
274 vcopy += nexpand;
275 ++vsrc;
276 replace_value = (vcopy != vsrc); // if we've caught up, there no need to do this replacement.
277 }
278
279 if (my_needs_index) {
280 const auto sexpand = my_expansion.start[eindex];
281 for (Index_ e = 0; e < nexpand; ++e, ++icopy) {
282 *icopy = to_index(sexpand + e);
283 }
284 }
285 }
286
287 return SparseRange<Value_, Index_>(
288 count,
289 (my_needs_value ? value_buffer : NULL),
290 (my_needs_index ? index_buffer : NULL)
291 );
292 }
293
294private:
295 bool my_needs_value, my_needs_index;
296 std::unique_ptr<SparseExtractor<oracle_, Value_, Index_> > my_ext;
297 std::vector<Index_> my_holding_ibuffer;
298 SparseParallelExpansion<Index_> my_expansion;
299 Index_ my_shift;
300};
301
302template<bool oracle_, typename Value_, typename Index_>
303class ParallelFullSparse final : public SparseExtractor<oracle_, Value_, Index_> {
304public:
305 template<class SubsetStorage_>
306 ParallelFullSparse(
307 const Matrix<Value_, Index_>& matrix,
308 const SubsetStorage_& subset,
309 const bool row,
310 MaybeOracle<oracle_, Index_> oracle,
311 const Options& opt
312 ) :
313 my_core(matrix, subset, subset.size(), row, std::move(oracle), opt, Helper())
314 {}
315
316 SparseRange<Value_, Index_> fetch(const Index_ i, Value_* const value_buffer, Index_* const index_buffer) {
317 return my_core.fetch(i, value_buffer, index_buffer, Helper());
318 }
319
320private:
321 ParallelSparseCore<oracle_, Value_, Index_> my_core;
322
323 struct Helper {
324 Index_ operator()(const Index_ i) const {
325 return i;
326 }
327 };
328};
329
330template<bool oracle_, typename Value_, typename Index_>
331class ParallelBlockSparse final : public SparseExtractor<oracle_, Value_, Index_> {
332public:
333 template<class SubsetStorage_>
334 ParallelBlockSparse(
335 const Matrix<Value_, Index_>& matrix,
336 const SubsetStorage_& subset,
337 const bool row,
338 MaybeOracle<oracle_, Index_> oracle,
339 const Index_ block_start,
340 const Index_ block_length,
341 const Options& opt
342 ) :
343 my_core(matrix, subset, block_length, row, std::move(oracle), opt, Helper(block_start)),
344 my_block_start(block_start)
345 {}
346
347 SparseRange<Value_, Index_> fetch(const Index_ i, Value_* const value_buffer, Index_* const index_buffer) {
348 return my_core.fetch(i, value_buffer, index_buffer, Helper(my_block_start));
349 }
350
351private:
352 ParallelSparseCore<oracle_, Value_, Index_> my_core;
353 Index_ my_block_start;
354
355 struct Helper {
356 Helper(Index_ block_start) : block_start(block_start) {}
357 Index_ block_start;
358 Index_ operator()(const Index_ i) const {
359 return i + block_start;
360 }
361 };
362};
363
364template<bool oracle_, typename Value_, typename Index_>
365class ParallelIndexSparse final : public SparseExtractor<oracle_, Value_, Index_> {
366public:
367 template<class SubsetStorage_>
368 ParallelIndexSparse(
369 const Matrix<Value_, Index_>& matrix,
370 const SubsetStorage_& subset,
371 const bool row,
372 MaybeOracle<oracle_, Index_> oracle,
373 VectorPtr<Index_> indices_ptr,
374 const Options& opt
375 ) :
376 my_core(matrix, subset, indices_ptr->size(), row, std::move(oracle), opt, Helper(*indices_ptr)),
377 my_indices_ptr(std::move(indices_ptr))
378 {}
379
380 SparseRange<Value_, Index_> fetch(Index_ i, Value_* value_buffer, Index_* index_buffer) {
381 return my_core.fetch(i, value_buffer, index_buffer, Helper(*my_indices_ptr));
382 }
383
384private:
385 ParallelSparseCore<oracle_, Value_, Index_> my_core;
386 VectorPtr<Index_> my_indices_ptr;
387
388 struct Helper {
389 Helper(const std::vector<Index_>& indices) : indices(indices) {}
390 const std::vector<Index_>& indices;
391 Index_ operator()(const Index_ i) const {
392 return indices[i];
393 }
394 };
395};
396
397}
413template<typename Value_, typename Index_, class SubsetStorage_>
414class DelayedSubsetSorted final : public Matrix<Value_, Index_> {
415public:
425 std::shared_ptr<const Matrix<Value_, Index_> > matrix,
426 SubsetStorage_ subset,
427 const bool by_row,
428 const bool check = true
429 ) :
430 my_matrix(std::move(matrix)),
431 my_subset(std::move(subset)),
432 my_by_row(by_row)
433 {
434 // Check that we can still report the dimension extents of the subsetted matrix.
435 sanisizer::can_cast<Index_>(my_subset.size());
436
437 if (check) {
438 const Index_ nsub = my_subset.size();
439 for (Index_ i = 1; i < nsub; ++i) {
440 if (my_subset[i] < my_subset[i-1]) {
441 throw std::runtime_error("subset should be sorted");
442 }
443 }
444 }
445 }
446
447private:
448 std::shared_ptr<const Matrix<Value_, Index_> > my_matrix;
449 SubsetStorage_ my_subset;
450 bool my_by_row;
451
452 Index_ get_mapping_dim() const {
453 if (my_by_row) {
454 return my_matrix->nrow();
455 } else {
456 return my_matrix->ncol();
457 }
458 }
459
460public:
461 Index_ nrow() const {
462 if (my_by_row) {
463 return my_subset.size();
464 } else {
465 return my_matrix->nrow();
466 }
467 }
468
469 Index_ ncol() const {
470 if (my_by_row) {
471 return my_matrix->ncol();
472 } else {
473 return my_subset.size();
474 }
475 }
476
477 bool is_sparse() const {
478 return my_matrix->is_sparse();
479 }
480
481 double is_sparse_proportion() const {
482 return my_matrix->is_sparse_proportion();
483 }
484
485 bool prefer_rows() const {
486 return my_matrix->prefer_rows();
487 }
488
489 double prefer_rows_proportion() const {
490 return my_matrix->prefer_rows_proportion();
491 }
492
493 bool uses_oracle(const bool row) const {
494 return my_matrix->uses_oracle(row);
495 }
496
497 using Matrix<Value_, Index_>::dense_column;
498
499 using Matrix<Value_, Index_>::dense_row;
500
501 using Matrix<Value_, Index_>::sparse_column;
502
503 using Matrix<Value_, Index_>::sparse_row;
504
505 /********************
506 *** Myopic dense ***
507 ********************/
508private:
509 template<typename ... Args_>
510 std::unique_ptr<MyopicDenseExtractor<Value_, Index_> > populate_myopic_dense(
511 const bool row,
512 Args_&& ... args
513 ) const {
514 if (row == my_by_row) {
515 return std::make_unique<subset_utils::MyopicPerpendicularDense<Value_, Index_, SubsetStorage_> >(
516 *my_matrix,
517 my_subset,
518 row,
519 std::forward<Args_>(args)...
520 );
521 } else {
522 return std::make_unique<DelayedSubsetSorted_internal::ParallelDense<false, Value_, Index_> >(
523 *my_matrix,
524 my_subset,
525 row,
526 false,
527 std::forward<Args_>(args)...
528 );
529 }
530 }
531
532public:
533 std::unique_ptr<MyopicDenseExtractor<Value_, Index_> > dense(
534 const bool row,
535 const Options& opt
536 ) const {
537 return populate_myopic_dense(row, opt);
538 }
539
540 std::unique_ptr<MyopicDenseExtractor<Value_, Index_> > dense(
541 const bool row,
542 const Index_ block_start,
543 const Index_ block_length,
544 const Options& opt
545 ) const {
546 return populate_myopic_dense(row, block_start, block_length, opt);
547 }
548
549 std::unique_ptr<MyopicDenseExtractor<Value_, Index_> > dense(
550 const bool row,
551 VectorPtr<Index_> indices_ptr,
552 const Options& opt
553 ) const {
554 return populate_myopic_dense(row, std::move(indices_ptr), opt);
555 }
556
557 /*********************
558 *** Myopic sparse ***
559 *********************/
560private:
561 template<DimensionSelectionType selection_, bool oracle_, typename ... Args_>
562 std::unique_ptr<SparseExtractor<oracle_, Value_, Index_> > populate_sparse(
563 bool row,
565 Args_&& ... args
566 ) const {
567 if constexpr(selection_ == DimensionSelectionType::FULL) {
568 return std::make_unique<DelayedSubsetSorted_internal::ParallelFullSparse<oracle_, Value_, Index_> >(
569 *my_matrix,
570 my_subset,
571 row,
572 std::move(oracle),
573 std::forward<Args_>(args)...
574 );
575 } else if constexpr(selection_ == DimensionSelectionType::BLOCK) {
576 return std::make_unique<DelayedSubsetSorted_internal::ParallelBlockSparse<oracle_, Value_, Index_> >(
577 *my_matrix,
578 my_subset,
579 row,
580 std::move(oracle),
581 std::forward<Args_>(args)...
582 );
583 } else {
584 return std::make_unique<DelayedSubsetSorted_internal::ParallelIndexSparse<oracle_, Value_, Index_> >(
585 *my_matrix,
586 my_subset,
587 row,
588 std::move(oracle),
589 std::forward<Args_>(args)...
590 );
591 }
592 }
593
594 template<DimensionSelectionType selection_, typename ... Args_>
595 std::unique_ptr<MyopicSparseExtractor<Value_, Index_> > populate_myopic_sparse(
596 const bool row,
597 Args_&& ... args
598 ) const {
599 if (row == my_by_row) {
600 return std::make_unique<subset_utils::MyopicPerpendicularSparse<Value_, Index_, SubsetStorage_> >(
601 *my_matrix,
602 my_subset,
603 row,
604 std::forward<Args_>(args)...
605 );
606 } else {
607 return populate_sparse<selection_, false>(row, false, std::forward<Args_>(args)...);
608 }
609 }
610
611public:
612 std::unique_ptr<MyopicSparseExtractor<Value_, Index_> > sparse(
613 const bool row,
614 const Options& opt
615 ) const {
616 return populate_myopic_sparse<DimensionSelectionType::FULL>(row, opt);
617 }
618
619 std::unique_ptr<MyopicSparseExtractor<Value_, Index_> > sparse(
620 const bool row,
621 const Index_ block_start,
622 const Index_ block_length,
623 const Options& opt
624 ) const {
625 return populate_myopic_sparse<DimensionSelectionType::BLOCK>(row, block_start, block_length, opt);
626 }
627
628 std::unique_ptr<MyopicSparseExtractor<Value_, Index_> > sparse(
629 const bool row,
630 VectorPtr<Index_> indices_ptr,
631 const Options& opt
632 ) const {
633 return populate_myopic_sparse<DimensionSelectionType::INDEX>(row, std::move(indices_ptr), opt);
634 }
635
636 /**********************
637 *** Oracular dense ***
638 **********************/
639private:
640 template<typename ... Args_>
641 std::unique_ptr<OracularDenseExtractor<Value_, Index_> > populate_oracular_dense(
642 const bool row,
643 std::shared_ptr<const Oracle<Index_> > oracle,
644 Args_&& ... args
645 ) const {
646 if (row == my_by_row) {
647 return std::make_unique<subset_utils::OracularPerpendicularDense<Value_, Index_> >(
648 *my_matrix,
649 my_subset,
650 row,
651 std::move(oracle),
652 std::forward<Args_>(args)...
653 );
654 } else {
655 return std::make_unique<DelayedSubsetSorted_internal::ParallelDense<true, Value_, Index_> >(
656 *my_matrix,
657 my_subset,
658 row,
659 std::move(oracle),
660 std::forward<Args_>(args)...
661 );
662 }
663 }
664
665public:
666 std::unique_ptr<OracularDenseExtractor<Value_, Index_> > dense(
667 const bool row,
668 std::shared_ptr<const Oracle<Index_> > oracle,
669 const Options& opt
670 ) const {
671 return populate_oracular_dense(row, std::move(oracle), opt);
672 }
673
674 std::unique_ptr<OracularDenseExtractor<Value_, Index_> > dense(
675 const bool row,
676 std::shared_ptr<const Oracle<Index_> > oracle,
677 const Index_ block_start,
678 const Index_ block_length,
679 const Options& opt
680 ) const {
681 return populate_oracular_dense(row, std::move(oracle), block_start, block_length, opt);
682 }
683
684 std::unique_ptr<OracularDenseExtractor<Value_, Index_> > dense(
685 const bool row,
686 std::shared_ptr<const Oracle<Index_> > oracle,
687 VectorPtr<Index_> indices_ptr,
688 const Options& opt
689 ) const {
690 return populate_oracular_dense(row, std::move(oracle), std::move(indices_ptr), opt);
691 }
692
693 /***********************
694 *** Oracular sparse ***
695 ***********************/
696private:
697 template<DimensionSelectionType selection_, typename ... Args_>
698 std::unique_ptr<OracularSparseExtractor<Value_, Index_> > populate_oracular_sparse(
699 const bool row,
700 std::shared_ptr<const Oracle<Index_> > oracle,
701 Args_&& ... args
702 ) const {
703 if (row == my_by_row) {
704 return std::make_unique<subset_utils::OracularPerpendicularSparse<Value_, Index_> >(
705 *my_matrix,
706 my_subset,
707 row,
708 std::move(oracle),
709 std::forward<Args_>(args)...
710 );
711 } else {
712 return populate_sparse<selection_, true>(row, std::move(oracle), std::forward<Args_>(args)...);
713 }
714 }
715
716public:
717 std::unique_ptr<OracularSparseExtractor<Value_, Index_> > sparse(
718 const bool row,
719 std::shared_ptr<const Oracle<Index_> > oracle,
720 const Options& opt
721 ) const {
722 return populate_oracular_sparse<DimensionSelectionType::FULL>(row, std::move(oracle), opt);
723 }
724
725 std::unique_ptr<OracularSparseExtractor<Value_, Index_> > sparse(
726 const bool row,
727 std::shared_ptr<const Oracle<Index_> > oracle,
728 const Index_ block_start,
729 const Index_ block_length,
730 const Options& opt
731 ) const {
732 return populate_oracular_sparse<DimensionSelectionType::BLOCK>(row, std::move(oracle), block_start, block_length, opt);
733 }
734
735 std::unique_ptr<OracularSparseExtractor<Value_, Index_> > sparse(
736 const bool row,
737 std::shared_ptr<const Oracle<Index_> > oracle,
738 VectorPtr<Index_> indices_ptr,
739 const Options& opt
740 ) const {
741 return populate_oracular_sparse<DimensionSelectionType::INDEX>(row, std::move(oracle), std::move(indices_ptr), opt);
742 }
743};
744
745}
746
747#endif
Convert index type to container size.
Virtual class for a matrix of some numeric type.
Delayed subsetting of a matrix with sorted indices.
Definition DelayedSubsetSorted.hpp:414
std::unique_ptr< OracularSparseExtractor< Value_, Index_ > > sparse(const bool row, std::shared_ptr< const Oracle< Index_ > > oracle, const Options &opt) const
Definition DelayedSubsetSorted.hpp:717
double prefer_rows_proportion() const
Definition DelayedSubsetSorted.hpp:489
std::unique_ptr< MyopicSparseExtractor< Value_, Index_ > > sparse(const bool row, const Options &opt) const
Definition DelayedSubsetSorted.hpp:612
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 DelayedSubsetSorted.hpp:725
Index_ nrow() const
Definition DelayedSubsetSorted.hpp:461
bool prefer_rows() const
Definition DelayedSubsetSorted.hpp:485
std::unique_ptr< MyopicDenseExtractor< Value_, Index_ > > dense(const bool row, const Index_ block_start, const Index_ block_length, const Options &opt) const
Definition DelayedSubsetSorted.hpp:540
double is_sparse_proportion() const
Definition DelayedSubsetSorted.hpp:481
bool is_sparse() const
Definition DelayedSubsetSorted.hpp:477
DelayedSubsetSorted(std::shared_ptr< const Matrix< Value_, Index_ > > matrix, SubsetStorage_ subset, const bool by_row, const bool check=true)
Definition DelayedSubsetSorted.hpp:424
std::unique_ptr< MyopicDenseExtractor< Value_, Index_ > > dense(const bool row, VectorPtr< Index_ > indices_ptr, const Options &opt) const
Definition DelayedSubsetSorted.hpp:549
std::unique_ptr< OracularDenseExtractor< Value_, Index_ > > dense(const bool row, std::shared_ptr< const Oracle< Index_ > > oracle, const Options &opt) const
Definition DelayedSubsetSorted.hpp:666
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 DelayedSubsetSorted.hpp:674
std::unique_ptr< MyopicDenseExtractor< Value_, Index_ > > dense(const bool row, const Options &opt) const
Definition DelayedSubsetSorted.hpp:533
bool uses_oracle(const bool row) const
Definition DelayedSubsetSorted.hpp:493
std::unique_ptr< MyopicSparseExtractor< Value_, Index_ > > sparse(const bool row, const Index_ block_start, const Index_ block_length, const Options &opt) const
Definition DelayedSubsetSorted.hpp:619
std::unique_ptr< MyopicSparseExtractor< Value_, Index_ > > sparse(const bool row, VectorPtr< Index_ > indices_ptr, const Options &opt) const
Definition DelayedSubsetSorted.hpp:628
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 DelayedSubsetSorted.hpp:735
Index_ ncol() const
Definition DelayedSubsetSorted.hpp:469
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 DelayedSubsetSorted.hpp:684
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
DimensionSelectionType
Definition Options.hpp:25
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_, std::shared_ptr< const Oracle< Index_ > >, bool >::type MaybeOracle
Definition make_Extractor.hpp:23
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