1#ifndef TATAMI_DELAYED_UNARY_ISOMETRIC_OPERATION_H
2#define TATAMI_DELAYED_UNARY_ISOMETRIC_OPERATION_H
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(
const Index_ i, OutputValue_*
const buffer) {
74 if constexpr(same_value) {
75 const 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 const 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,
94 const Index_ block_start,
95 const Index_ block_length,
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(
const Index_ i, OutputValue_*
const buffer) {
123 if constexpr(same_value) {
124 const 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 const 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(
const Index_ i, OutputValue_*
const buffer) {
170 const auto& indices = *my_indices_ptr;
171 if constexpr(same_value) {
172 const 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 const 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_*
const buffer) {
235 const auto vbuffer = my_vbuffer.data();
236 const 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,
273 const Index_ block_start,
274 const Index_ block_length,
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_*
const buffer) {
309 const auto vbuffer = my_vbuffer.data();
310 const 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;
373 my_ext = new_extractor<true, oracle_>(matrix, my_row, std::move(oracle), std::move(indices_ptr), opt);
375 if constexpr(!same_value) {
381 const Helper_& my_helper;
384 DelayedIsometricOperation_internal::MaybeOracleDepends<oracle_, Helper_, Index_> my_oracle;
387 std::vector<InputValue_> my_vbuffer;
388 std::vector<Index_> my_ibuffer;
390 std::vector<Index_> my_remapping;
391 Index_ my_remapping_offset = 0;
392 std::unique_ptr<SparseExtractor<oracle_, InputValue_, Index_> > my_ext;
394 static constexpr bool same_value = std::is_same<OutputValue_, InputValue_>::value;
395 typename std::conditional<!same_value, std::vector<OutputValue_>,
bool>::type my_result_vbuffer;
398 const OutputValue_* fetch(Index_ i, OutputValue_*
const buffer) {
399 const auto vbuffer = my_vbuffer.data();
400 const auto range = my_ext->fetch(i, vbuffer, my_ibuffer.data());
402 i = my_oracle.get(i);
403 if constexpr(same_value) {
404 copy_n(range.value, range.number, vbuffer);
405 my_helper.sparse(my_row, i, range.number, vbuffer, range.index, vbuffer);
407 my_helper.sparse(my_row, i, range.number, range.value, range.index, my_result_vbuffer.data());
411 if (range.number < my_extent) {
412 std::fill_n(buffer, my_extent, my_helper.fill(my_row, i));
415 if constexpr(same_value) {
416 for (Index_ i = 0; i < range.number; ++i) {
417 buffer[my_remapping[range.index[i] - my_remapping_offset]] = vbuffer[i];
420 for (Index_ i = 0; i < range.number; ++i) {
421 buffer[my_remapping[range.index[i] - my_remapping_offset]] = my_result_vbuffer[i];
436template<
bool oracle_,
typename OutputValue_,
typename InputValue_,
typename Index_,
class Helper_>
437class SparseSimple final :
public SparseExtractor<oracle_, OutputValue_, Index_> {
440 const Matrix<InputValue_, Index_>& matrix,
441 const Helper_& helper,
443 MaybeOracle<oracle_, Index_> oracle,
444 const Options& opt) :
447 my_oracle(oracle, my_helper, row),
448 my_ext(
new_extractor<true, oracle_>(matrix, row, std::move(oracle), opt))
450 initialize(opt, row ? matrix.ncol() : matrix.nrow());
454 const Matrix<InputValue_, Index_>& matrix,
455 const Helper_& helper,
457 MaybeOracle<oracle_, Index_> oracle,
458 const Index_ block_start,
459 const Index_ block_length,
460 const Options& opt) :
463 my_oracle(oracle, my_helper, row),
464 my_ext(
new_extractor<true, oracle_>(matrix, row, std::move(oracle), block_start, block_length, opt))
466 initialize(opt, block_length);
470 const Matrix<InputValue_, Index_>& matrix,
471 const Helper_& helper,
473 MaybeOracle<oracle_, Index_> oracle,
474 VectorPtr<Index_> indices_ptr,
475 const Options& opt) :
478 my_oracle(oracle, my_helper, row)
480 initialize(opt, indices_ptr->size());
483 my_ext = new_extractor<true, oracle_>(matrix, row, std::move(oracle), std::move(indices_ptr), opt);
487 const Helper_& my_helper;
490 DelayedIsometricOperation_internal::MaybeOracleDepends<oracle_, Helper_, Index_> my_oracle;
492 std::unique_ptr<SparseExtractor<oracle_, InputValue_, Index_> > my_ext;
494 static constexpr bool same_value = std::is_same<OutputValue_, InputValue_>::value;
495 typename std::conditional<!same_value, std::vector<InputValue_>,
bool>::type my_holding_vbuffer;
497 void initialize(
const Options& opt,
const Index_ extent) {
498 if constexpr(!same_value) {
499 if (opt.sparse_extract_value) {
506 SparseRange<OutputValue_, Index_> fetch(
const Index_ i, OutputValue_*
const value_buffer, Index_*
const index_buffer) {
507 if constexpr(same_value) {
508 auto raw = my_ext->fetch(i, value_buffer, index_buffer);
510 copy_n(raw.value, raw.number, value_buffer);
511 my_helper.sparse(my_row, my_oracle.get(i), raw.number, value_buffer, raw.index, value_buffer);
512 raw.value = value_buffer;
516 const auto raw = my_ext->fetch(i, my_holding_vbuffer.data(), index_buffer);
518 SparseRange<OutputValue_, Index_> output(raw.number);
519 output.index = raw.index;
521 my_helper.sparse(my_row, my_oracle.get(i), raw.number, raw.value, raw.index, value_buffer);
522 output.value = value_buffer;
537template<
bool oracle_,
typename OutputValue_,
typename InputValue_,
typename Index_,
class Helper_>
538class SparseNeedsIndices final :
public SparseExtractor<oracle_, OutputValue_, Index_> {
541 const Matrix<InputValue_, Index_>& matrix,
542 const Helper_& helper,
544 MaybeOracle<oracle_, Index_> oracle,
548 my_oracle(oracle, my_helper, row)
550 initialize(opt, row ? matrix.ncol() : matrix.nrow());
551 my_ext = new_extractor<true, oracle_>(matrix, row, std::move(oracle), opt);
555 const Matrix<InputValue_, Index_>& matrix,
556 const Helper_& helper,
558 MaybeOracle<oracle_, Index_> oracle,
559 const Index_ block_start,
560 const Index_ block_length,
564 my_oracle(oracle, my_helper, row)
566 initialize(opt, block_length);
567 my_ext = new_extractor<true, oracle_>(matrix, row, std::move(oracle), block_start, block_length, opt);
571 const Matrix<InputValue_, Index_>& matrix,
572 const Helper_& helper,
574 MaybeOracle<oracle_, Index_> oracle,
575 VectorPtr<Index_> indices_ptr,
579 my_oracle(oracle, my_helper, row)
581 initialize(opt, indices_ptr->size());
584 my_ext = new_extractor<true, oracle_>(matrix, row, std::move(oracle), std::move(indices_ptr), opt);
588 void initialize(Options& opt,
const Index_ extent) {
589 my_report_value = opt.sparse_extract_value;
590 my_report_index = opt.sparse_extract_index;
594 if (my_report_value) {
595 opt.sparse_extract_index =
true;
600 if (!my_report_index) {
605 if constexpr(!same_value) {
606 if (my_report_value) {
613 const Helper_& my_helper;
616 DelayedIsometricOperation_internal::MaybeOracleDepends<oracle_, Helper_, Index_> my_oracle;
618 bool my_report_value, my_report_index;
619 std::vector<Index_> my_ibuffer;
621 std::unique_ptr<SparseExtractor<oracle_, InputValue_, Index_> > my_ext;
623 static constexpr bool same_value = std::is_same<OutputValue_, InputValue_>::value;
624 typename std::conditional<!same_value, std::vector<InputValue_>,
bool>::type my_holding_vbuffer;
627 SparseRange<OutputValue_, Index_> fetch(
const Index_ i, OutputValue_*
const value_buffer, Index_*
const index_buffer) {
628 const auto iptr = my_report_index ? index_buffer : my_ibuffer.data();
630 if constexpr(same_value) {
631 auto raw = my_ext->fetch(i, value_buffer, iptr);
632 if (my_report_value) {
633 copy_n(raw.value, raw.number, value_buffer);
634 my_helper.sparse(my_row, my_oracle.get(i), raw.number, value_buffer, raw.index, value_buffer);
635 raw.value = value_buffer;
637 if (!my_report_index) {
643 const auto raw = my_ext->fetch(i, my_holding_vbuffer.data(), iptr);
644 SparseRange<OutputValue_, Index_> output(raw.number, NULL, (my_report_index ? raw.index : NULL));
645 if (my_report_value) {
646 my_helper.sparse(my_row, my_oracle.get(i), raw.number, raw.value, raw.index, value_buffer);
647 output.value = value_buffer;
673template<
typename OutputValue_,
typename InputValue_,
typename Index_,
class Helper_ = DelayedUnaryIsometricOperationHelper<OutputValue_, InputValue_, Index_> >
682 std::shared_ptr<const Helper_> helper
684 my_matrix(std::move(matrix)),
685 my_helper(std::move(helper))
687 const auto expected_rows = my_helper->nrow();
688 if (expected_rows.has_value() && *expected_rows != my_matrix->nrow()) {
689 throw std::runtime_error(
"number of rows in 'matrix' is not consistent with those expected by 'helper'");
691 const auto expected_cols = my_helper->ncol();
692 if (expected_cols.has_value() && *expected_cols != my_matrix->ncol()) {
693 throw std::runtime_error(
"number of columns in 'matrix' is not consistent with those expected by 'helper'");
698 std::shared_ptr<const Matrix<InputValue_, Index_> > my_matrix;
699 std::shared_ptr<const Helper_> my_helper;
703 return my_matrix->nrow();
707 return my_matrix->ncol();
711 if (my_helper->is_sparse()) {
712 return my_matrix->is_sparse();
718 if (my_helper->is_sparse()) {
719 return my_matrix->is_sparse_proportion();
725 return my_matrix->prefer_rows();
729 return my_matrix->prefer_rows_proportion();
733 return my_matrix->uses_oracle(row);
744 template<
bool oracle_>
745 std::unique_ptr<DenseExtractor<oracle_, OutputValue_, Index_> > dense_basic_internal(
750 return std::make_unique<DelayedUnaryIsometricOperation_internal::DenseBasicFull<oracle_, OutputValue_, InputValue_, Index_, Helper_> >(
759 template<
bool oracle_>
760 std::unique_ptr<DenseExtractor<oracle_, OutputValue_, Index_> > dense_basic_internal(
763 const Index_ block_start,
764 const Index_ block_length,
767 return std::make_unique<DelayedUnaryIsometricOperation_internal::DenseBasicBlock<oracle_, OutputValue_, InputValue_, Index_, Helper_> >(
778 template<
bool oracle_>
779 std::unique_ptr<DenseExtractor<oracle_, OutputValue_, Index_> > dense_basic_internal(
785 return std::make_unique<DelayedUnaryIsometricOperation_internal::DenseBasicIndex<oracle_, OutputValue_, InputValue_, Index_, Helper_> >(
790 std::move(indices_ptr),
795 template<
bool oracle_>
796 std::unique_ptr<DenseExtractor<oracle_, OutputValue_, Index_> > dense_expanded_internal(
801 return std::make_unique<DelayedUnaryIsometricOperation_internal::DenseExpandedFull<oracle_, OutputValue_, InputValue_, Index_, Helper_> >(
810 template<
bool oracle_>
811 std::unique_ptr<DenseExtractor<oracle_, OutputValue_, Index_> > dense_expanded_internal(
814 const Index_ block_start,
815 const Index_ block_length,
818 return std::make_unique<DelayedUnaryIsometricOperation_internal::DenseExpandedBlock<oracle_, OutputValue_, InputValue_, Index_, Helper_> >(
829 template<
bool oracle_>
830 std::unique_ptr<DenseExtractor<oracle_, OutputValue_, Index_> > dense_expanded_internal(
836 return std::make_unique<DelayedUnaryIsometricOperation_internal::DenseExpandedIndex<oracle_, OutputValue_, InputValue_, Index_, Helper_> >(
841 std::move(indices_ptr),
846 template<
bool oracle_,
typename ... Args_>
847 std::unique_ptr<DenseExtractor<oracle_, OutputValue_, Index_> > dense_internal(
851 if (my_matrix->is_sparse()) {
852 if (DelayedIsometricOperation_internal::can_dense_expand(*my_helper, row)) {
853 return dense_expanded_internal<oracle_>(row, std::forward<Args_>(args)...);
856 return dense_basic_internal<oracle_>(row, std::forward<Args_>(args)...);
860 std::unique_ptr<MyopicDenseExtractor<OutputValue_, Index_> >
dense(
864 return dense_internal<false>(row,
false, opt);
867 std::unique_ptr<MyopicDenseExtractor<OutputValue_, Index_> >
dense(
869 const Index_ block_start,
870 const Index_ block_length,
873 return dense_internal<false>(row,
false, block_start, block_length, opt);
876 std::unique_ptr<MyopicDenseExtractor<OutputValue_, Index_> >
dense(
881 return dense_internal<false>(row,
false, std::move(indices_ptr), opt);
888 template<
bool oracle_,
typename ... Args_>
889 std::unique_ptr<SparseExtractor<oracle_, OutputValue_, Index_> > sparse_to_dense_internal(
894 return std::make_unique<FullSparsifiedWrapper<oracle_, OutputValue_, Index_> >(
895 dense_internal<oracle_>(row, std::move(oracle), opt),
896 (row ? my_matrix->ncol() : my_matrix->nrow()),
901 template<
bool oracle_,
typename ... Args_>
902 std::unique_ptr<SparseExtractor<oracle_, OutputValue_, Index_> > sparse_to_dense_internal(
905 const Index_ block_start,
906 const Index_ block_length,
909 return std::make_unique<BlockSparsifiedWrapper<oracle_, OutputValue_, Index_> >(
910 dense_internal<oracle_>(row, std::move(oracle), block_start, block_length, opt),
917 template<
bool oracle_,
typename ... Args_>
918 std::unique_ptr<SparseExtractor<oracle_, OutputValue_, Index_> > sparse_to_dense_internal(
924 return std::make_unique<IndexSparsifiedWrapper<oracle_, OutputValue_, Index_> >(
925 dense_internal<oracle_>(row, std::move(oracle), indices_ptr, opt),
931 template<
bool oracle_,
typename ... Args_>
932 std::unique_ptr<SparseExtractor<oracle_, OutputValue_, Index_> > sparse_internal(
937 if (my_helper->is_sparse() && my_matrix->is_sparse()) {
938 if (DelayedIsometricOperation_internal::needs_sparse_indices(*my_helper, row)) {
939 return std::make_unique<DelayedUnaryIsometricOperation_internal::SparseNeedsIndices<oracle_, OutputValue_, InputValue_, Index_, Helper_> >(
944 std::forward<Args_>(args)...
948 return std::make_unique<DelayedUnaryIsometricOperation_internal::SparseSimple<oracle_, OutputValue_, InputValue_, Index_, Helper_> >(
953 std::forward<Args_>(args)...
957 return sparse_to_dense_internal<oracle_>(row, std::move(oracle), std::forward<Args_>(args)...);
961 std::unique_ptr<MyopicSparseExtractor<OutputValue_, Index_> >
sparse(
965 return sparse_internal<false>(row,
false, opt);
968 std::unique_ptr<MyopicSparseExtractor<OutputValue_, Index_> >
sparse(
970 const Index_ block_start,
971 const Index_ block_length,
974 return sparse_internal<false>(row,
false, block_start, block_length, opt);
977 std::unique_ptr<MyopicSparseExtractor<OutputValue_, Index_> >
sparse(
982 return sparse_internal<false>(row,
false, std::move(indices_ptr), opt);
989 std::unique_ptr<OracularDenseExtractor<OutputValue_, Index_> >
dense(
994 return dense_internal<true>(row, std::move(oracle), opt);
997 std::unique_ptr<OracularDenseExtractor<OutputValue_, Index_> >
dense(
1000 const Index_ block_start,
1001 const Index_ block_length,
1004 return dense_internal<true>(row, std::move(oracle), block_start, block_length, opt);
1007 std::unique_ptr<OracularDenseExtractor<OutputValue_, Index_> >
dense(
1013 return dense_internal<true>(row, std::move(oracle), std::move(indices_ptr), opt);
1020 std::unique_ptr<OracularSparseExtractor<OutputValue_, Index_> >
sparse(
1025 return sparse_internal<true>(row, std::move(oracle), opt);
1028 std::unique_ptr<OracularSparseExtractor<OutputValue_, Index_> >
sparse(
1031 const Index_ block_start,
1032 const Index_ block_length,
1035 return sparse_internal<true>(row, std::move(oracle), block_start, block_length, opt);
1038 std::unique_ptr<OracularSparseExtractor<OutputValue_, Index_> >
sparse(
1044 return sparse_internal<true>(row, std::move(oracle), std::move(indices_ptr), opt);
1052template<
typename OutputValue_ =
double,
typename InputValue_,
typename Index_,
class Helper_>
1053std::shared_ptr<Matrix<OutputValue_, Index_> > make_DelayedUnaryIsometricOperation(std::shared_ptr<
const Matrix<InputValue_, Index_> > matrix, std::shared_ptr<const Helper_> helper) {
1054 return std::shared_ptr<Matrix<OutputValue_, Index_> >(
new DelayedUnaryIsometricOperation<OutputValue_, InputValue_, Index_, Helper_>(std::move(matrix), std::move(helper)));
1057template<
typename OutputValue_ =
double,
typename InputValue_,
typename Index_,
class Helper_>
1058std::shared_ptr<Matrix<OutputValue_, Index_> > make_DelayedUnaryIsometricOperation(std::shared_ptr<Matrix<InputValue_, Index_> > matrix, std::shared_ptr<Helper_> helper) {
1059 return std::shared_ptr<Matrix<OutputValue_, Index_> >(
new DelayedUnaryIsometricOperation<OutputValue_, InputValue_, Index_, Helper_>(std::move(matrix), std::move(helper)));
1062template<
typename ... Args_>
1063auto make_DelayedIsometricOperation(Args_&&... args) {
1064 return make_DelayedUnaryIsometricOperation(std::forward<Args_>(args)...);
1067template<
typename OutputValue_,
typename Index_,
class Helper_>
1068using DelayedIsometricOperation = DelayedUnaryIsometricOperation<OutputValue_, Index_, Helper_, OutputValue_>;
Convert index type to container size.
Virtual class for a matrix of some numeric type.
Delayed isometric operation on a single matrix.
Definition DelayedUnaryIsometricOperation.hpp:674
std::unique_ptr< MyopicSparseExtractor< OutputValue_, Index_ > > sparse(const bool row, VectorPtr< Index_ > indices_ptr, const Options &opt) const
Definition DelayedUnaryIsometricOperation.hpp:977
bool prefer_rows() const
Definition DelayedUnaryIsometricOperation.hpp:724
double is_sparse_proportion() const
Definition DelayedUnaryIsometricOperation.hpp:717
std::unique_ptr< OracularDenseExtractor< OutputValue_, Index_ > > dense(const bool row, std::shared_ptr< const Oracle< Index_ > > oracle, const Options &opt) const
Definition DelayedUnaryIsometricOperation.hpp:989
bool uses_oracle(const bool row) const
Definition DelayedUnaryIsometricOperation.hpp:732
std::unique_ptr< MyopicSparseExtractor< OutputValue_, Index_ > > sparse(const bool row, const Index_ block_start, const Index_ block_length, const Options &opt) const
Definition DelayedUnaryIsometricOperation.hpp:968
Index_ ncol() const
Definition DelayedUnaryIsometricOperation.hpp:706
std::unique_ptr< MyopicDenseExtractor< OutputValue_, Index_ > > dense(const bool row, VectorPtr< Index_ > indices_ptr, const Options &opt) const
Definition DelayedUnaryIsometricOperation.hpp:876
std::unique_ptr< OracularSparseExtractor< OutputValue_, Index_ > > sparse(const bool row, std::shared_ptr< const Oracle< Index_ > > oracle, VectorPtr< Index_ > indices_ptr, const Options &opt) const
Definition DelayedUnaryIsometricOperation.hpp:1038
std::unique_ptr< OracularSparseExtractor< OutputValue_, Index_ > > sparse(const bool row, std::shared_ptr< const Oracle< Index_ > > oracle, const Options &opt) const
Definition DelayedUnaryIsometricOperation.hpp:1020
double prefer_rows_proportion() const
Definition DelayedUnaryIsometricOperation.hpp:728
DelayedUnaryIsometricOperation(std::shared_ptr< const Matrix< InputValue_, Index_ > > matrix, std::shared_ptr< const Helper_ > helper)
Definition DelayedUnaryIsometricOperation.hpp:680
bool is_sparse() const
Definition DelayedUnaryIsometricOperation.hpp:710
std::unique_ptr< MyopicDenseExtractor< OutputValue_, Index_ > > dense(const bool row, const Options &opt) const
Definition DelayedUnaryIsometricOperation.hpp:860
std::unique_ptr< OracularDenseExtractor< OutputValue_, Index_ > > dense(const bool row, std::shared_ptr< const Oracle< Index_ > > oracle, VectorPtr< Index_ > indices_ptr, const Options &opt) const
Definition DelayedUnaryIsometricOperation.hpp:1007
std::unique_ptr< OracularDenseExtractor< OutputValue_, 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 DelayedUnaryIsometricOperation.hpp:997
std::unique_ptr< MyopicSparseExtractor< OutputValue_, Index_ > > sparse(const bool row, const Options &opt) const
Definition DelayedUnaryIsometricOperation.hpp:961
std::unique_ptr< OracularSparseExtractor< OutputValue_, 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 DelayedUnaryIsometricOperation.hpp:1028
std::unique_ptr< MyopicDenseExtractor< OutputValue_, Index_ > > dense(const bool row, const Index_ block_start, const Index_ block_length, const Options &opt) const
Definition DelayedUnaryIsometricOperation.hpp:867
Index_ nrow() const
Definition DelayedUnaryIsometricOperation.hpp:702
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
auto new_extractor(const Matrix< Value_, Index_ > &matrix, const bool row, MaybeOracle< oracle_, Index_ > oracle, Args_ &&... args)
Definition new_extractor.hpp:42
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:99
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
I< decltype(std::declval< Container_ >().size())> cast_Index_to_container_size(const Index_ x)
Definition Index_to_container.hpp:65
Value_ * copy_n(const Value_ *const input, const Size_ n, Value_ *const output)
Definition copy.hpp:37
Options for accessing data from a Matrix instance.
Definition Options.hpp:30
Interface for tatami::DelayedUnaryIsometricOperation helpers.