1#ifndef TATAMI_DELAYED_UNARY_ISOMETRIC_OPERATION_H
2#define TATAMI_DELAYED_UNARY_ISOMETRIC_OPERATION_H
7#include "../../utils/Index_to_container.hpp"
8#include "../depends_utils.hpp"
28namespace DelayedUnaryIsometricOperation_internal {
40template<
bool oracle_,
typename OutputValue_,
typename InputValue_,
typename Index_,
class Helper_>
41class DenseBasicFull final :
public DenseExtractor<oracle_, OutputValue_, Index_> {
44 const Matrix<InputValue_, Index_>& matrix,
45 const Helper_& helper,
47 MaybeOracle<oracle_, Index_> oracle,
51 my_oracle(oracle, my_helper, row),
52 my_extent(row ? matrix.ncol() : matrix.nrow()),
53 my_ext(
new_extractor<false, oracle_>(matrix, row, std::move(oracle), opt))
55 if constexpr(!same_value) {
61 const Helper_& my_helper;
64 DelayedIsometricOperation_internal::MaybeOracleDepends<oracle_, Helper_, Index_> my_oracle;
67 std::unique_ptr<DenseExtractor<oracle_, InputValue_, Index_> > my_ext;
69 static constexpr bool same_value = std::is_same<OutputValue_, InputValue_>::value;
70 typename std::conditional<!same_value, std::vector<InputValue_>,
bool>::type my_holding_buffer;
73 const OutputValue_* fetch(Index_ i, OutputValue_* buffer) {
74 if constexpr(same_value) {
75 auto ptr = my_ext->fetch(i, buffer);
76 copy_n(ptr, my_extent, buffer);
77 my_helper.dense(my_row, my_oracle.get(i),
static_cast<Index_
>(0), my_extent, buffer, buffer);
79 auto ptr = my_ext->fetch(i, my_holding_buffer.data());
80 my_helper.dense(my_row, my_oracle.get(i),
static_cast<Index_
>(0), my_extent, ptr, buffer);
86template<
bool oracle_,
typename OutputValue_,
typename InputValue_,
typename Index_,
class Helper_>
87class DenseBasicBlock final :
public DenseExtractor<oracle_, OutputValue_, Index_> {
90 const Matrix<InputValue_, Index_>& matrix,
91 const Helper_& helper,
93 MaybeOracle<oracle_, Index_> oracle,
99 my_oracle(oracle, my_helper, row),
100 my_block_start(block_start),
101 my_block_length(block_length),
102 my_ext(
new_extractor<false, oracle_>(matrix, row, std::move(oracle), block_start, block_length, opt))
104 if constexpr(!same_value) {
110 const Helper_& my_helper;
113 DelayedIsometricOperation_internal::MaybeOracleDepends<oracle_, Helper_, Index_> my_oracle;
114 Index_ my_block_start, my_block_length;
116 std::unique_ptr<DenseExtractor<oracle_, InputValue_, Index_> > my_ext;
118 static constexpr bool same_value = std::is_same<OutputValue_, InputValue_>::value;
119 typename std::conditional<!same_value, std::vector<InputValue_>,
bool>::type my_holding_buffer;
122 const OutputValue_* fetch(Index_ i, OutputValue_* buffer) {
123 if constexpr(same_value) {
124 auto ptr = my_ext->fetch(i, buffer);
125 copy_n(ptr, my_block_length, buffer);
126 my_helper.dense(my_row, my_oracle.get(i), my_block_start, my_block_length, buffer, buffer);
128 auto ptr = my_ext->fetch(i, my_holding_buffer.data());
129 my_helper.dense(my_row, my_oracle.get(i), my_block_start, my_block_length, ptr, buffer);
135template<
bool oracle_,
typename OutputValue_,
typename InputValue_,
typename Index_,
class Helper_>
136class DenseBasicIndex final :
public DenseExtractor<oracle_, OutputValue_, Index_> {
139 const Matrix<InputValue_, Index_>& matrix,
140 const Helper_& helper,
142 MaybeOracle<oracle_, Index_> oracle,
143 VectorPtr<Index_> indices_ptr,
144 const Options& opt) :
147 my_oracle(oracle, my_helper, row),
148 my_indices_ptr(indices_ptr),
149 my_ext(
new_extractor<false, oracle_>(matrix, row, std::move(oracle), std::move(indices_ptr), opt))
151 if constexpr(!same_value) {
157 const Helper_& my_helper;
160 DelayedIsometricOperation_internal::MaybeOracleDepends<oracle_, Helper_, Index_> my_oracle;
161 VectorPtr<Index_> my_indices_ptr;
163 std::unique_ptr<DenseExtractor<oracle_, InputValue_, Index_> > my_ext;
165 static constexpr bool same_value = std::is_same<OutputValue_, InputValue_>::value;
166 typename std::conditional<!same_value, std::vector<InputValue_>,
bool>::type my_holding_buffer;
169 const OutputValue_* fetch(Index_ i, OutputValue_* buffer) {
170 const auto& indices = *my_indices_ptr;
171 if constexpr(same_value) {
172 auto ptr = my_ext->fetch(i, buffer);
173 copy_n(ptr, indices.size(), buffer);
174 my_helper.dense(my_row, my_oracle.get(i), indices, buffer, buffer);
176 auto ptr = my_ext->fetch(i, my_holding_buffer.data());
177 my_helper.dense(my_row, my_oracle.get(i), indices, ptr, buffer);
194template<
bool oracle_,
typename OutputValue_,
typename InputValue_,
typename Index_,
class Helper_>
195class DenseExpandedFull final :
public DenseExtractor<oracle_, OutputValue_, Index_> {
198 const Matrix<InputValue_, Index_>& matrix,
199 const Helper_& helper,
201 MaybeOracle<oracle_, Index_> oracle,
205 my_oracle(oracle, my_helper, row),
206 my_extent(row ? matrix.ncol() : matrix.nrow()),
210 opt.sparse_extract_value =
true;
211 opt.sparse_extract_index =
true;
212 my_ext = new_extractor<true, oracle_>(matrix, my_row, std::move(oracle), opt);
214 if constexpr(!same_value) {
220 const Helper_& my_helper;
223 DelayedIsometricOperation_internal::MaybeOracleDepends<oracle_, Helper_, Index_> my_oracle;
226 std::vector<InputValue_> my_vbuffer;
227 std::vector<Index_> my_ibuffer;
228 std::unique_ptr<SparseExtractor<oracle_, InputValue_, Index_> > my_ext;
230 static constexpr bool same_value = std::is_same<OutputValue_, InputValue_>::value;
231 typename std::conditional<!same_value, std::vector<OutputValue_>,
bool>::type my_result_vbuffer;
234 const OutputValue_* fetch(Index_ i, OutputValue_* buffer) {
235 auto vbuffer = my_vbuffer.data();
236 auto range = my_ext->fetch(i, vbuffer, my_ibuffer.data());
238 i = my_oracle.get(i);
239 if constexpr(same_value) {
240 copy_n(range.value, range.number, vbuffer);
241 my_helper.sparse(my_row, i, range.number, vbuffer, range.index, vbuffer);
243 my_helper.sparse(my_row, i, range.number, range.value, range.index, my_result_vbuffer.data());
247 if (range.number < my_extent) {
248 std::fill_n(buffer, my_extent, my_helper.fill(my_row, i));
251 if constexpr(same_value) {
252 for (Index_ i = 0; i < range.number; ++i) {
253 buffer[range.index[i]] = vbuffer[i];
256 for (Index_ i = 0; i < range.number; ++i) {
257 buffer[range.index[i]] = my_result_vbuffer[i];
265template<
bool oracle_,
typename OutputValue_,
typename InputValue_,
typename Index_,
class Helper_>
266class DenseExpandedBlock final :
public DenseExtractor<oracle_, OutputValue_, Index_> {
269 const Matrix<InputValue_, Index_>& matrix,
270 const Helper_& helper,
272 MaybeOracle<oracle_, Index_> oracle,
278 my_oracle(oracle, my_helper, row),
279 my_block_start(block_start),
280 my_block_length(block_length),
284 opt.sparse_extract_value =
true;
285 opt.sparse_extract_index =
true;
286 my_ext = new_extractor<true, oracle_>(matrix, row, std::move(oracle), block_start, block_length, opt);
288 if constexpr(!same_value) {
294 const Helper_& my_helper;
297 DelayedIsometricOperation_internal::MaybeOracleDepends<oracle_, Helper_, Index_> my_oracle;
298 Index_ my_block_start, my_block_length;
300 std::vector<InputValue_> my_vbuffer;
301 std::vector<Index_> my_ibuffer;
302 std::unique_ptr<SparseExtractor<oracle_, InputValue_, Index_> > my_ext;
304 static constexpr bool same_value = std::is_same<OutputValue_, InputValue_>::value;
305 typename std::conditional<!same_value, std::vector<OutputValue_>,
bool>::type my_result_vbuffer;
308 const OutputValue_* fetch(Index_ i, OutputValue_* buffer) {
309 auto vbuffer = my_vbuffer.data();
310 auto range = my_ext->fetch(i, vbuffer, my_ibuffer.data());
312 i = my_oracle.get(i);
313 if constexpr(same_value) {
314 copy_n(range.value, range.number, vbuffer);
315 my_helper.sparse(my_row, i, range.number, vbuffer, range.index, vbuffer);
317 my_helper.sparse(my_row, i, range.number, range.value, range.index, my_result_vbuffer.data());
321 if (range.number < my_block_length) {
322 std::fill_n(buffer, my_block_length, my_helper.fill(my_row, i));
325 if constexpr(same_value) {
326 for (Index_ i = 0; i < range.number; ++i) {
327 buffer[range.index[i] - my_block_start] = vbuffer[i];
330 for (Index_ i = 0; i < range.number; ++i) {
331 buffer[range.index[i] - my_block_start] = my_result_vbuffer[i];
339template<
bool oracle_,
typename OutputValue_,
typename InputValue_,
typename Index_,
class Helper_>
340class DenseExpandedIndex final :
public DenseExtractor<oracle_, OutputValue_, Index_> {
343 const Matrix<InputValue_, Index_>& matrix,
344 const Helper_& helper,
346 MaybeOracle<oracle_, Index_> oracle,
347 VectorPtr<Index_> indices_ptr,
351 my_oracle(oracle, my_helper, row)
353 opt.sparse_extract_value =
true;
354 opt.sparse_extract_index =
true;
356 const auto& indices = *indices_ptr;
357 my_extent = indices.size();
365 my_remapping_offset = indices.front();
367 for (Index_ i = 0; i < my_extent; ++i) {
368 my_remapping[indices[i] - my_remapping_offset] = i;
372 my_ext = new_extractor<true, oracle_>(matrix, my_row, std::move(oracle), std::move(indices_ptr), opt);
374 if constexpr(!same_value) {
380 const Helper_& my_helper;
383 DelayedIsometricOperation_internal::MaybeOracleDepends<oracle_, Helper_, Index_> my_oracle;
386 std::vector<InputValue_> my_vbuffer;
387 std::vector<Index_> my_ibuffer;
389 std::vector<Index_> my_remapping;
390 Index_ my_remapping_offset = 0;
391 std::unique_ptr<SparseExtractor<oracle_, InputValue_, Index_> > my_ext;
393 static constexpr bool same_value = std::is_same<OutputValue_, InputValue_>::value;
394 typename std::conditional<!same_value, std::vector<OutputValue_>,
bool>::type my_result_vbuffer;
397 const OutputValue_* fetch(Index_ i, OutputValue_* buffer) {
398 auto vbuffer = my_vbuffer.data();
399 auto range = my_ext->fetch(i, vbuffer, my_ibuffer.data());
401 i = my_oracle.get(i);
402 if constexpr(same_value) {
403 copy_n(range.value, range.number, vbuffer);
404 my_helper.sparse(my_row, i, range.number, vbuffer, range.index, vbuffer);
406 my_helper.sparse(my_row, i, range.number, range.value, range.index, my_result_vbuffer.data());
410 if (range.number < my_extent) {
411 std::fill_n(buffer, my_extent, my_helper.fill(my_row, i));
414 if constexpr(same_value) {
415 for (Index_ i = 0; i < range.number; ++i) {
416 buffer[my_remapping[range.index[i] - my_remapping_offset]] = vbuffer[i];
419 for (Index_ i = 0; i < range.number; ++i) {
420 buffer[my_remapping[range.index[i] - my_remapping_offset]] = my_result_vbuffer[i];
435template<
bool oracle_,
typename OutputValue_,
typename InputValue_,
typename Index_,
class Helper_>
436class SparseSimple final :
public SparseExtractor<oracle_, OutputValue_, Index_> {
439 const Matrix<InputValue_, Index_>& matrix,
440 const Helper_& helper,
442 MaybeOracle<oracle_, Index_> oracle,
443 const Options& opt) :
446 my_oracle(oracle, my_helper, row),
447 my_ext(
new_extractor<true, oracle_>(matrix, row, std::move(oracle), opt))
449 initialize(opt, row ? matrix.ncol() : matrix.nrow());
453 const Matrix<InputValue_, Index_>& matrix,
454 const Helper_& helper,
456 MaybeOracle<oracle_, Index_> oracle,
459 const Options& opt) :
462 my_oracle(oracle, my_helper, row),
463 my_ext(
new_extractor<true, oracle_>(matrix, row, std::move(oracle), block_start, block_length, opt))
465 initialize(opt, block_length);
469 const Matrix<InputValue_, Index_>& matrix,
470 const Helper_& helper,
472 MaybeOracle<oracle_, Index_> oracle,
473 VectorPtr<Index_> indices_ptr,
474 const Options& opt) :
477 my_oracle(oracle, my_helper, row)
479 initialize(opt, indices_ptr->size());
482 my_ext = new_extractor<true, oracle_>(matrix, row, std::move(oracle), std::move(indices_ptr), opt);
486 const Helper_& my_helper;
489 DelayedIsometricOperation_internal::MaybeOracleDepends<oracle_, Helper_, Index_> my_oracle;
491 std::unique_ptr<SparseExtractor<oracle_, InputValue_, Index_> > my_ext;
493 static constexpr bool same_value = std::is_same<OutputValue_, InputValue_>::value;
494 typename std::conditional<!same_value, std::vector<InputValue_>,
bool>::type my_holding_vbuffer;
496 void initialize(
const Options& opt, Index_ extent) {
497 if constexpr(!same_value) {
498 if (opt.sparse_extract_value) {
505 SparseRange<OutputValue_, Index_> fetch(Index_ i, OutputValue_* value_buffer, Index_* index_buffer) {
506 if constexpr(same_value) {
507 auto raw = my_ext->fetch(i, value_buffer, index_buffer);
509 copy_n(raw.value, raw.number, value_buffer);
510 my_helper.sparse(my_row, my_oracle.get(i), raw.number, value_buffer, raw.index, value_buffer);
511 raw.value = value_buffer;
515 auto raw = my_ext->fetch(i, my_holding_vbuffer.data(), index_buffer);
517 SparseRange<OutputValue_, Index_> output(raw.number);
518 output.index = raw.index;
520 my_helper.sparse(my_row, my_oracle.get(i), raw.number, raw.value, raw.index, value_buffer);
521 output.value = value_buffer;
536template<
bool oracle_,
typename OutputValue_,
typename InputValue_,
typename Index_,
class Helper_>
537class SparseNeedsIndices final :
public SparseExtractor<oracle_, OutputValue_, Index_> {
540 const Matrix<InputValue_, Index_>& matrix,
541 const Helper_& helper,
543 MaybeOracle<oracle_, Index_> oracle,
547 my_oracle(oracle, my_helper, row)
549 initialize(opt, row ? matrix.ncol() : matrix.nrow());
550 my_ext = new_extractor<true, oracle_>(matrix, row, std::move(oracle), opt);
554 const Matrix<InputValue_, Index_>& matrix,
555 const Helper_& helper,
557 MaybeOracle<oracle_, Index_> oracle,
563 my_oracle(oracle, my_helper, row)
565 initialize(opt, block_length);
566 my_ext = new_extractor<true, oracle_>(matrix, row, std::move(oracle), block_start, block_length, opt);
570 const Matrix<InputValue_, Index_>& matrix,
571 const Helper_& helper,
573 MaybeOracle<oracle_, Index_> oracle,
574 VectorPtr<Index_> indices_ptr,
578 my_oracle(oracle, my_helper, row)
580 initialize(opt, indices_ptr->size());
581 my_ext = new_extractor<true, oracle_>(matrix, row, std::move(oracle), std::move(indices_ptr), opt);
585 void initialize(Options& opt, Index_ extent) {
586 my_report_value = opt.sparse_extract_value;
587 my_report_index = opt.sparse_extract_index;
591 if (my_report_value) {
592 opt.sparse_extract_index =
true;
597 if (!my_report_index) {
602 if constexpr(!same_value) {
603 if (my_report_value) {
610 const Helper_& my_helper;
613 DelayedIsometricOperation_internal::MaybeOracleDepends<oracle_, Helper_, Index_> my_oracle;
615 bool my_report_value, my_report_index;
616 std::vector<Index_> my_ibuffer;
618 std::unique_ptr<SparseExtractor<oracle_, InputValue_, Index_> > my_ext;
620 static constexpr bool same_value = std::is_same<OutputValue_, InputValue_>::value;
621 typename std::conditional<!same_value, std::vector<InputValue_>,
bool>::type my_holding_vbuffer;
624 SparseRange<OutputValue_, Index_> fetch(Index_ i, OutputValue_* value_buffer, Index_* index_buffer) {
625 auto iptr = my_report_index ? index_buffer : my_ibuffer.data();
627 if constexpr(same_value) {
628 auto raw = my_ext->fetch(i, value_buffer, iptr);
629 if (my_report_value) {
630 copy_n(raw.value, raw.number, value_buffer);
631 my_helper.sparse(my_row, my_oracle.get(i), raw.number, value_buffer, raw.index, value_buffer);
632 raw.value = value_buffer;
634 if (!my_report_index) {
640 auto raw = my_ext->fetch(i, my_holding_vbuffer.data(), iptr);
641 SparseRange<OutputValue_, Index_> output(raw.number, NULL, (my_report_index ? raw.index : NULL));
642 if (my_report_value) {
643 my_helper.sparse(my_row, my_oracle.get(i), raw.number, raw.value, raw.index, value_buffer);
644 output.value = value_buffer;
670template<
typename OutputValue_,
typename InputValue_,
typename Index_,
class Helper_ = DelayedUnaryIsometricOperationHelper<OutputValue_, InputValue_, Index_> >
679 std::shared_ptr<const Helper_> helper
681 my_matrix(std::move(matrix)),
682 my_helper(std::move(helper))
684 auto expected_rows = my_helper->nrow();
685 if (expected_rows.has_value() && *expected_rows != my_matrix->nrow()) {
686 throw std::runtime_error(
"number of rows in 'matrix' is not consistent with those expected by 'helper'");
688 auto expected_cols = my_helper->ncol();
689 if (expected_cols.has_value() && *expected_cols != my_matrix->ncol()) {
690 throw std::runtime_error(
"number of columns in 'matrix' is not consistent with those expected by 'helper'");
695 std::shared_ptr<const Matrix<InputValue_, Index_> > my_matrix;
696 std::shared_ptr<const Helper_> my_helper;
700 return my_matrix->nrow();
704 return my_matrix->ncol();
708 if (my_helper->is_sparse()) {
709 return my_matrix->is_sparse();
715 if (my_helper->is_sparse()) {
716 return my_matrix->is_sparse_proportion();
722 return my_matrix->prefer_rows();
726 return my_matrix->prefer_rows_proportion();
730 return my_matrix->uses_oracle(row);
741 template<
bool oracle_>
743 return std::make_unique<DelayedUnaryIsometricOperation_internal::DenseBasicFull<oracle_, OutputValue_, InputValue_, Index_, Helper_> >(
752 template<
bool oracle_>
753 std::unique_ptr<DenseExtractor<oracle_, OutputValue_, Index_> > dense_basic_internal(
bool row,
MaybeOracle<oracle_, Index_> oracle, Index_ block_start, Index_ block_length,
const Options& opt)
const {
754 return std::make_unique<DelayedUnaryIsometricOperation_internal::DenseBasicBlock<oracle_, OutputValue_, InputValue_, Index_, Helper_> >(
765 template<
bool oracle_>
767 return std::make_unique<DelayedUnaryIsometricOperation_internal::DenseBasicIndex<oracle_, OutputValue_, InputValue_, Index_, Helper_> >(
772 std::move(indices_ptr),
777 template<
bool oracle_>
778 std::unique_ptr<DenseExtractor<oracle_, OutputValue_, Index_> > dense_expanded_internal(
bool row,
MaybeOracle<oracle_, Index_> oracle,
const Options& opt)
const {
779 return std::make_unique<DelayedUnaryIsometricOperation_internal::DenseExpandedFull<oracle_, OutputValue_, InputValue_, Index_, Helper_> >(
788 template<
bool oracle_>
789 std::unique_ptr<DenseExtractor<oracle_, OutputValue_, Index_> > dense_expanded_internal(
bool row,
MaybeOracle<oracle_, Index_> oracle, Index_ block_start, Index_ block_length,
const Options& opt)
const {
790 return std::make_unique<DelayedUnaryIsometricOperation_internal::DenseExpandedBlock<oracle_, OutputValue_, InputValue_, Index_, Helper_> >(
801 template<
bool oracle_>
803 return std::make_unique<DelayedUnaryIsometricOperation_internal::DenseExpandedIndex<oracle_, OutputValue_, InputValue_, Index_, Helper_> >(
808 std::move(indices_ptr),
813 template<
bool oracle_,
typename ... Args_>
814 std::unique_ptr<DenseExtractor<oracle_, OutputValue_, Index_> > dense_internal(
bool row, Args_&& ... args)
const {
815 if (my_matrix->is_sparse()) {
816 if (DelayedIsometricOperation_internal::can_dense_expand(*my_helper, row)) {
817 return dense_expanded_internal<oracle_>(row, std::forward<Args_>(args)...);
820 return dense_basic_internal<oracle_>(row, std::forward<Args_>(args)...);
824 std::unique_ptr<MyopicDenseExtractor<OutputValue_, Index_> >
dense(
bool row,
const Options& opt)
const {
825 return dense_internal<false>(row,
false, opt);
828 std::unique_ptr<MyopicDenseExtractor<OutputValue_, Index_> >
dense(
bool row, Index_ block_start, Index_ block_length,
const Options& opt)
const {
829 return dense_internal<false>(row,
false, block_start, block_length, opt);
833 return dense_internal<false>(row,
false, std::move(indices_ptr), opt);
840 template<
bool oracle_,
typename ... Args_>
842 return std::make_unique<FullSparsifiedWrapper<oracle_, OutputValue_, Index_> >(
843 dense_internal<oracle_>(row, std::move(oracle), opt),
844 (row ? my_matrix->ncol() : my_matrix->nrow()),
849 template<
bool oracle_,
typename ... Args_>
850 std::unique_ptr<SparseExtractor<oracle_, OutputValue_, Index_> > sparse_to_dense_internal(
bool row,
MaybeOracle<oracle_, Index_> oracle, Index_ block_start, Index_ block_length,
const Options& opt)
const {
851 return std::make_unique<BlockSparsifiedWrapper<oracle_, OutputValue_, Index_> >(
852 dense_internal<oracle_>(row, std::move(oracle), block_start, block_length, opt),
859 template<
bool oracle_,
typename ... Args_>
861 return std::make_unique<IndexSparsifiedWrapper<oracle_, OutputValue_, Index_> >(
862 dense_internal<oracle_>(row, std::move(oracle), indices_ptr, opt),
868 template<
bool oracle_,
typename ... Args_>
869 std::unique_ptr<SparseExtractor<oracle_, OutputValue_, Index_> > sparse_internal(
bool row,
MaybeOracle<oracle_, Index_> oracle, Args_&& ... args)
const {
870 if (my_helper->is_sparse() && my_matrix->is_sparse()) {
871 if (DelayedIsometricOperation_internal::needs_sparse_indices(*my_helper, row)) {
872 return std::make_unique<DelayedUnaryIsometricOperation_internal::SparseNeedsIndices<oracle_, OutputValue_, InputValue_, Index_, Helper_> >(
877 std::forward<Args_>(args)...
881 return std::make_unique<DelayedUnaryIsometricOperation_internal::SparseSimple<oracle_, OutputValue_, InputValue_, Index_, Helper_> >(
886 std::forward<Args_>(args)...
890 return sparse_to_dense_internal<oracle_>(row, std::move(oracle), std::forward<Args_>(args)...);
894 std::unique_ptr<MyopicSparseExtractor<OutputValue_, Index_> >
sparse(
bool row,
const Options& opt)
const {
895 return sparse_internal<false>(row,
false, opt);
898 std::unique_ptr<MyopicSparseExtractor<OutputValue_, Index_> >
sparse(
bool row, Index_ block_start, Index_ block_length,
const Options& opt)
const {
899 return sparse_internal<false>(row,
false, block_start, block_length, opt);
903 return sparse_internal<false>(row,
false, std::move(indices_ptr), opt);
910 std::unique_ptr<OracularDenseExtractor<OutputValue_, Index_> >
dense(
bool row, std::shared_ptr<
const Oracle<Index_> > oracle,
const Options& opt)
const {
911 return dense_internal<true>(row, std::move(oracle), opt);
914 std::unique_ptr<OracularDenseExtractor<OutputValue_, Index_> >
dense(
bool row, std::shared_ptr<
const Oracle<Index_> > oracle, Index_ block_start, Index_ block_length,
const Options& opt)
const {
915 return dense_internal<true>(row, std::move(oracle), block_start, block_length, opt);
919 return dense_internal<true>(row, std::move(oracle), std::move(indices_ptr), opt);
926 std::unique_ptr<OracularSparseExtractor<OutputValue_, Index_> >
sparse(
bool row, std::shared_ptr<
const Oracle<Index_> > oracle,
const Options& opt)
const {
927 return sparse_internal<true>(row, std::move(oracle), opt);
930 std::unique_ptr<OracularSparseExtractor<OutputValue_, Index_> >
sparse(
bool row, std::shared_ptr<
const Oracle<Index_> > oracle, Index_ block_start, Index_ block_length,
const Options& opt)
const {
931 return sparse_internal<true>(row, std::move(oracle), block_start, block_length, opt);
935 return sparse_internal<true>(row, std::move(oracle), std::move(indices_ptr), opt);
943template<
typename OutputValue_ =
double,
typename InputValue_,
typename Index_,
class Helper_>
944std::shared_ptr<Matrix<OutputValue_, Index_> > make_DelayedUnaryIsometricOperation(std::shared_ptr<
const Matrix<InputValue_, Index_> > matrix, std::shared_ptr<const Helper_> helper) {
945 return std::shared_ptr<Matrix<OutputValue_, Index_> >(
new DelayedUnaryIsometricOperation<OutputValue_, InputValue_, Index_, Helper_>(std::move(matrix), std::move(helper)));
948template<
typename OutputValue_ =
double,
typename InputValue_,
typename Index_,
class Helper_>
949std::shared_ptr<Matrix<OutputValue_, Index_> > make_DelayedUnaryIsometricOperation(std::shared_ptr<Matrix<InputValue_, Index_> > matrix, std::shared_ptr<Helper_> helper) {
950 return std::shared_ptr<Matrix<OutputValue_, Index_> >(
new DelayedUnaryIsometricOperation<OutputValue_, InputValue_, Index_, Helper_>(std::move(matrix), std::move(helper)));
953template<
typename ... Args_>
954auto make_DelayedIsometricOperation(Args_&&... args) {
955 return make_DelayedUnaryIsometricOperation(std::forward<Args_>(args)...);
958template<
typename OutputValue_,
typename Index_,
class Helper_>
959using DelayedIsometricOperation = DelayedUnaryIsometricOperation<OutputValue_, Index_, Helper_, OutputValue_>;
Virtual class for a matrix of some numeric type.
Delayed isometric operation on a single matrix.
Definition DelayedUnaryIsometricOperation.hpp:671
bool prefer_rows() const
Definition DelayedUnaryIsometricOperation.hpp:721
double is_sparse_proportion() const
Definition DelayedUnaryIsometricOperation.hpp:714
std::unique_ptr< OracularDenseExtractor< OutputValue_, Index_ > > dense(bool row, std::shared_ptr< const Oracle< Index_ > > oracle, const Options &opt) const
Definition DelayedUnaryIsometricOperation.hpp:910
std::unique_ptr< MyopicDenseExtractor< OutputValue_, Index_ > > dense(bool row, VectorPtr< Index_ > indices_ptr, const Options &opt) const
Definition DelayedUnaryIsometricOperation.hpp:832
std::unique_ptr< MyopicDenseExtractor< OutputValue_, Index_ > > dense(bool row, const Options &opt) const
Definition DelayedUnaryIsometricOperation.hpp:824
Index_ ncol() const
Definition DelayedUnaryIsometricOperation.hpp:703
std::unique_ptr< OracularDenseExtractor< OutputValue_, Index_ > > dense(bool row, std::shared_ptr< const Oracle< Index_ > > oracle, VectorPtr< Index_ > indices_ptr, const Options &opt) const
Definition DelayedUnaryIsometricOperation.hpp:918
std::unique_ptr< OracularSparseExtractor< OutputValue_, Index_ > > sparse(bool row, std::shared_ptr< const Oracle< Index_ > > oracle, VectorPtr< Index_ > indices_ptr, const Options &opt) const
Definition DelayedUnaryIsometricOperation.hpp:934
bool uses_oracle(bool row) const
Definition DelayedUnaryIsometricOperation.hpp:729
std::unique_ptr< OracularSparseExtractor< OutputValue_, Index_ > > sparse(bool row, std::shared_ptr< const Oracle< Index_ > > oracle, Index_ block_start, Index_ block_length, const Options &opt) const
Definition DelayedUnaryIsometricOperation.hpp:930
double prefer_rows_proportion() const
Definition DelayedUnaryIsometricOperation.hpp:725
DelayedUnaryIsometricOperation(std::shared_ptr< const Matrix< InputValue_, Index_ > > matrix, std::shared_ptr< const Helper_ > helper)
Definition DelayedUnaryIsometricOperation.hpp:677
bool is_sparse() const
Definition DelayedUnaryIsometricOperation.hpp:707
std::unique_ptr< MyopicSparseExtractor< OutputValue_, Index_ > > sparse(bool row, const Options &opt) const
Definition DelayedUnaryIsometricOperation.hpp:894
std::unique_ptr< MyopicDenseExtractor< OutputValue_, Index_ > > dense(bool row, Index_ block_start, Index_ block_length, const Options &opt) const
Definition DelayedUnaryIsometricOperation.hpp:828
std::unique_ptr< OracularDenseExtractor< OutputValue_, Index_ > > dense(bool row, std::shared_ptr< const Oracle< Index_ > > oracle, Index_ block_start, Index_ block_length, const Options &opt) const
Definition DelayedUnaryIsometricOperation.hpp:914
std::unique_ptr< OracularSparseExtractor< OutputValue_, Index_ > > sparse(bool row, std::shared_ptr< const Oracle< Index_ > > oracle, const Options &opt) const
Definition DelayedUnaryIsometricOperation.hpp:926
std::unique_ptr< MyopicSparseExtractor< OutputValue_, Index_ > > sparse(bool row, VectorPtr< Index_ > indices_ptr, const Options &opt) const
Definition DelayedUnaryIsometricOperation.hpp:902
Index_ nrow() const
Definition DelayedUnaryIsometricOperation.hpp:699
std::unique_ptr< MyopicSparseExtractor< OutputValue_, Index_ > > sparse(bool row, Index_ block_start, Index_ block_length, const Options &opt) const
Definition DelayedUnaryIsometricOperation.hpp:898
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
decltype(std::declval< Container_ >().size()) cast_Index_to_container_size(Index_ x)
Definition Index_to_container.hpp:54
void resize_container_to_Index_size(Container_ &container, Index_ x, Args_ &&... args)
Definition Index_to_container.hpp:88
typename std::conditional< oracle_, std::shared_ptr< const Oracle< Index_ > >, bool >::type MaybeOracle
Definition new_extractor.hpp:20
typename std::conditional< oracle_, OracularDenseExtractor< Value_, Index_ >, MyopicDenseExtractor< Value_, Index_ > >::type DenseExtractor
Definition Extractor.hpp:273
Value_ * copy_n(const Value_ *input, Size_ n, Value_ *output)
Definition copy.hpp:26
auto new_extractor(const Matrix< Value_, Index_ > &matrix, bool row, MaybeOracle< oracle_, Index_ > oracle, Args_ &&... args)
Definition new_extractor.hpp:42
Options for accessing data from a Matrix instance.
Definition Options.hpp:30
Interface for tatami::DelayedUnaryIsometricOperation helpers.