1#ifndef TATAMI_DELAYED_UNARY_ISOMETRIC_OPERATION_H
2#define TATAMI_DELAYED_UNARY_ISOMETRIC_OPERATION_H
7#include "../depends_utils.hpp"
27namespace DelayedUnaryIsometricOperation_internal {
39template<
bool oracle_,
typename OutputValue_,
typename InputValue_,
typename Index_,
class Helper_>
40class DenseBasicFull final :
public DenseExtractor<oracle_, OutputValue_, Index_> {
43 const Matrix<InputValue_, Index_>& matrix,
44 const Helper_& helper,
46 MaybeOracle<oracle_, Index_> oracle,
50 my_oracle(oracle, my_helper, row),
51 my_extent(row ? matrix.ncol() : matrix.nrow()),
52 my_ext(
new_extractor<false, oracle_>(matrix, row, std::move(oracle), opt))
54 if constexpr(!same_value) {
55 my_holding_buffer.resize(my_extent);
60 const Helper_& my_helper;
63 DelayedIsometricOperation_internal::MaybeOracleDepends<oracle_, Helper_, Index_> my_oracle;
66 std::unique_ptr<DenseExtractor<oracle_, InputValue_, Index_> > my_ext;
68 static constexpr bool same_value = std::is_same<OutputValue_, InputValue_>::value;
69 typename std::conditional<!same_value, std::vector<InputValue_>,
bool>::type my_holding_buffer;
72 const OutputValue_* fetch(Index_ i, OutputValue_* buffer) {
73 if constexpr(same_value) {
74 auto ptr = my_ext->fetch(i, buffer);
75 copy_n(ptr, my_extent, buffer);
76 my_helper.dense(my_row, my_oracle.get(i),
static_cast<Index_
>(0), my_extent, buffer, buffer);
78 auto ptr = my_ext->fetch(i, my_holding_buffer.data());
79 my_helper.dense(my_row, my_oracle.get(i),
static_cast<Index_
>(0), my_extent, ptr, buffer);
85template<
bool oracle_,
typename OutputValue_,
typename InputValue_,
typename Index_,
class Helper_>
86class DenseBasicBlock final :
public DenseExtractor<oracle_, OutputValue_, Index_> {
89 const Matrix<InputValue_, Index_>& matrix,
90 const Helper_& helper,
92 MaybeOracle<oracle_, Index_> oracle,
98 my_oracle(oracle, my_helper, row),
99 my_block_start(block_start),
100 my_block_length(block_length),
101 my_ext(
new_extractor<false, oracle_>(matrix, row, std::move(oracle), block_start, block_length, opt))
103 if constexpr(!same_value) {
104 my_holding_buffer.resize(my_block_length);
109 const Helper_& my_helper;
112 DelayedIsometricOperation_internal::MaybeOracleDepends<oracle_, Helper_, Index_> my_oracle;
113 Index_ my_block_start, my_block_length;
115 std::unique_ptr<DenseExtractor<oracle_, InputValue_, Index_> > my_ext;
117 static constexpr bool same_value = std::is_same<OutputValue_, InputValue_>::value;
118 typename std::conditional<!same_value, std::vector<InputValue_>,
bool>::type my_holding_buffer;
121 const OutputValue_* fetch(Index_ i, OutputValue_* buffer) {
122 if constexpr(same_value) {
123 auto ptr = my_ext->fetch(i, buffer);
124 copy_n(ptr, my_block_length, buffer);
125 my_helper.dense(my_row, my_oracle.get(i), my_block_start, my_block_length, buffer, buffer);
127 auto ptr = my_ext->fetch(i, my_holding_buffer.data());
128 my_helper.dense(my_row, my_oracle.get(i), my_block_start, my_block_length, ptr, buffer);
134template<
bool oracle_,
typename OutputValue_,
typename InputValue_,
typename Index_,
class Helper_>
135class DenseBasicIndex final :
public DenseExtractor<oracle_, OutputValue_, Index_> {
138 const Matrix<InputValue_, Index_>& matrix,
139 const Helper_& helper,
141 MaybeOracle<oracle_, Index_> oracle,
142 VectorPtr<Index_> indices_ptr,
143 const Options& opt) :
146 my_oracle(oracle, my_helper, row),
147 my_indices_ptr(indices_ptr),
148 my_ext(
new_extractor<false, oracle_>(matrix, row, std::move(oracle), std::move(indices_ptr), opt))
150 if constexpr(!same_value) {
151 my_holding_buffer.resize(my_indices_ptr->size());
156 const Helper_& my_helper;
159 DelayedIsometricOperation_internal::MaybeOracleDepends<oracle_, Helper_, Index_> my_oracle;
160 VectorPtr<Index_> my_indices_ptr;
162 std::unique_ptr<DenseExtractor<oracle_, InputValue_, Index_> > my_ext;
164 static constexpr bool same_value = std::is_same<OutputValue_, InputValue_>::value;
165 typename std::conditional<!same_value, std::vector<InputValue_>,
bool>::type my_holding_buffer;
168 const OutputValue_* fetch(Index_ i, OutputValue_* buffer) {
169 const auto& indices = *my_indices_ptr;
170 if constexpr(same_value) {
171 auto ptr = my_ext->fetch(i, buffer);
172 copy_n(ptr, indices.size(), buffer);
173 my_helper.dense(my_row, my_oracle.get(i), indices, buffer, buffer);
175 auto ptr = my_ext->fetch(i, my_holding_buffer.data());
176 my_helper.dense(my_row, my_oracle.get(i), indices, ptr, buffer);
193template<
bool oracle_,
typename OutputValue_,
typename InputValue_,
typename Index_,
class Helper_>
194class DenseExpandedFull final :
public DenseExtractor<oracle_, OutputValue_, Index_> {
197 const Matrix<InputValue_, Index_>& matrix,
198 const Helper_& helper,
200 MaybeOracle<oracle_, Index_> oracle,
204 my_oracle(oracle, my_helper, row),
205 my_extent(row ? matrix.ncol() : matrix.nrow()),
206 my_vbuffer(my_extent),
207 my_ibuffer(my_extent)
209 opt.sparse_extract_value =
true;
210 opt.sparse_extract_index =
true;
211 my_ext = new_extractor<true, oracle_>(matrix, my_row, std::move(oracle), opt);
213 if constexpr(!same_value) {
214 my_result_vbuffer.resize(my_extent);
219 const Helper_& my_helper;
222 DelayedIsometricOperation_internal::MaybeOracleDepends<oracle_, Helper_, Index_> my_oracle;
225 std::vector<InputValue_> my_vbuffer;
226 std::vector<Index_> my_ibuffer;
227 std::unique_ptr<SparseExtractor<oracle_, InputValue_, Index_> > my_ext;
229 static constexpr bool same_value = std::is_same<OutputValue_, InputValue_>::value;
230 typename std::conditional<!same_value, std::vector<OutputValue_>,
bool>::type my_result_vbuffer;
233 const OutputValue_* fetch(Index_ i, OutputValue_* buffer) {
234 auto vbuffer = my_vbuffer.data();
235 auto range = my_ext->fetch(i, vbuffer, my_ibuffer.data());
237 i = my_oracle.get(i);
238 if constexpr(same_value) {
239 copy_n(range.value, range.number, vbuffer);
240 my_helper.sparse(my_row, i, range.number, vbuffer, range.index, vbuffer);
242 my_helper.sparse(my_row, i, range.number, range.value, range.index, my_result_vbuffer.data());
246 if (range.number < my_extent) {
247 std::fill_n(buffer, my_extent, my_helper.fill(my_row, i));
250 if constexpr(same_value) {
251 for (Index_ i = 0; i < range.number; ++i) {
252 buffer[range.index[i]] = vbuffer[i];
255 for (Index_ i = 0; i < range.number; ++i) {
256 buffer[range.index[i]] = my_result_vbuffer[i];
264template<
bool oracle_,
typename OutputValue_,
typename InputValue_,
typename Index_,
class Helper_>
265class DenseExpandedBlock final :
public DenseExtractor<oracle_, OutputValue_, Index_> {
268 const Matrix<InputValue_, Index_>& matrix,
269 const Helper_& helper,
271 MaybeOracle<oracle_, Index_> oracle,
277 my_oracle(oracle, my_helper, row),
278 my_block_start(block_start),
279 my_block_length(block_length),
280 my_vbuffer(block_length),
281 my_ibuffer(block_length)
283 opt.sparse_extract_value =
true;
284 opt.sparse_extract_index =
true;
285 my_ext = new_extractor<true, oracle_>(matrix, row, std::move(oracle), block_start, block_length, opt);
287 if constexpr(!same_value) {
288 my_result_vbuffer.resize(my_block_length);
293 const Helper_& my_helper;
296 DelayedIsometricOperation_internal::MaybeOracleDepends<oracle_, Helper_, Index_> my_oracle;
297 Index_ my_block_start, my_block_length;
299 std::vector<InputValue_> my_vbuffer;
300 std::vector<Index_> my_ibuffer;
301 std::unique_ptr<SparseExtractor<oracle_, InputValue_, Index_> > my_ext;
303 static constexpr bool same_value = std::is_same<OutputValue_, InputValue_>::value;
304 typename std::conditional<!same_value, std::vector<OutputValue_>,
bool>::type my_result_vbuffer;
307 const OutputValue_* fetch(Index_ i, OutputValue_* buffer) {
308 auto vbuffer = my_vbuffer.data();
309 auto range = my_ext->fetch(i, vbuffer, my_ibuffer.data());
311 i = my_oracle.get(i);
312 if constexpr(same_value) {
313 copy_n(range.value, range.number, vbuffer);
314 my_helper.sparse(my_row, i, range.number, vbuffer, range.index, vbuffer);
316 my_helper.sparse(my_row, i, range.number, range.value, range.index, my_result_vbuffer.data());
320 if (range.number < my_block_length) {
321 std::fill_n(buffer, my_block_length, my_helper.fill(my_row, i));
324 if constexpr(same_value) {
325 for (Index_ i = 0; i < range.number; ++i) {
326 buffer[range.index[i] - my_block_start] = vbuffer[i];
329 for (Index_ i = 0; i < range.number; ++i) {
330 buffer[range.index[i] - my_block_start] = my_result_vbuffer[i];
338template<
bool oracle_,
typename OutputValue_,
typename InputValue_,
typename Index_,
class Helper_>
339class DenseExpandedIndex final :
public DenseExtractor<oracle_, OutputValue_, Index_> {
342 const Matrix<InputValue_, Index_>& matrix,
343 const Helper_& helper,
345 MaybeOracle<oracle_, Index_> oracle,
346 VectorPtr<Index_> indices_ptr,
350 my_oracle(oracle, my_helper, row)
352 opt.sparse_extract_value =
true;
353 opt.sparse_extract_index =
true;
355 const auto& indices = *indices_ptr;
356 my_extent = indices.size();
357 my_vbuffer.resize(my_extent);
358 my_ibuffer.resize(my_extent);
364 my_remapping_offset = indices.front();
365 my_remapping.resize(indices.back() - my_remapping_offset + 1);
366 for (Index_ i = 0; i < my_extent; ++i) {
367 my_remapping[indices[i] - my_remapping_offset] = i;
371 my_ext = new_extractor<true, oracle_>(matrix, my_row, std::move(oracle), std::move(indices_ptr), opt);
373 if constexpr(!same_value) {
374 my_result_vbuffer.resize(my_extent);
379 const Helper_& my_helper;
382 DelayedIsometricOperation_internal::MaybeOracleDepends<oracle_, Helper_, Index_> my_oracle;
385 std::vector<InputValue_> my_vbuffer;
386 std::vector<Index_> my_ibuffer;
388 std::vector<Index_> my_remapping;
389 Index_ my_remapping_offset = 0;
390 std::unique_ptr<SparseExtractor<oracle_, InputValue_, Index_> > my_ext;
392 static constexpr bool same_value = std::is_same<OutputValue_, InputValue_>::value;
393 typename std::conditional<!same_value, std::vector<OutputValue_>,
bool>::type my_result_vbuffer;
396 const OutputValue_* fetch(Index_ i, OutputValue_* buffer) {
397 auto vbuffer = my_vbuffer.data();
398 auto range = my_ext->fetch(i, vbuffer, my_ibuffer.data());
400 i = my_oracle.get(i);
401 if constexpr(same_value) {
402 copy_n(range.value, range.number, vbuffer);
403 my_helper.sparse(my_row, i, range.number, vbuffer, range.index, vbuffer);
405 my_helper.sparse(my_row, i, range.number, range.value, range.index, my_result_vbuffer.data());
409 if (range.number < my_extent) {
410 std::fill_n(buffer, my_extent, my_helper.fill(my_row, i));
413 if constexpr(same_value) {
414 for (Index_ i = 0; i < range.number; ++i) {
415 buffer[my_remapping[range.index[i] - my_remapping_offset]] = vbuffer[i];
418 for (Index_ i = 0; i < range.number; ++i) {
419 buffer[my_remapping[range.index[i] - my_remapping_offset]] = my_result_vbuffer[i];
434template<
bool oracle_,
typename OutputValue_,
typename InputValue_,
typename Index_,
class Helper_>
435class SparseSimple final :
public SparseExtractor<oracle_, OutputValue_, Index_> {
438 const Matrix<InputValue_, Index_>& matrix,
439 const Helper_& helper,
441 MaybeOracle<oracle_, Index_> oracle,
442 const Options& opt) :
445 my_oracle(oracle, my_helper, row),
446 my_ext(
new_extractor<true, oracle_>(matrix, row, std::move(oracle), opt))
448 initialize(opt, row ? matrix.ncol() : matrix.nrow());
452 const Matrix<InputValue_, Index_>& matrix,
453 const Helper_& helper,
455 MaybeOracle<oracle_, Index_> oracle,
458 const Options& opt) :
461 my_oracle(oracle, my_helper, row),
462 my_ext(
new_extractor<true, oracle_>(matrix, row, std::move(oracle), block_start, block_length, opt))
464 initialize(opt, block_length);
468 const Matrix<InputValue_, Index_>& matrix,
469 const Helper_& helper,
471 MaybeOracle<oracle_, Index_> oracle,
472 VectorPtr<Index_> indices_ptr,
473 const Options& opt) :
476 my_oracle(oracle, my_helper, row)
478 initialize(opt, indices_ptr->size());
481 my_ext = new_extractor<true, oracle_>(matrix, row, std::move(oracle), std::move(indices_ptr), opt);
485 const Helper_& my_helper;
488 DelayedIsometricOperation_internal::MaybeOracleDepends<oracle_, Helper_, Index_> my_oracle;
490 std::unique_ptr<SparseExtractor<oracle_, InputValue_, Index_> > my_ext;
492 static constexpr bool same_value = std::is_same<OutputValue_, InputValue_>::value;
493 typename std::conditional<!same_value, std::vector<InputValue_>,
bool>::type my_holding_vbuffer;
495 void initialize(
const Options& opt, std::size_t extent) {
496 if constexpr(!same_value) {
497 if (opt.sparse_extract_value) {
498 my_holding_vbuffer.resize(extent);
504 SparseRange<OutputValue_, Index_> fetch(Index_ i, OutputValue_* value_buffer, Index_* index_buffer) {
505 if constexpr(same_value) {
506 auto raw = my_ext->fetch(i, value_buffer, index_buffer);
508 copy_n(raw.value, raw.number, value_buffer);
509 my_helper.sparse(my_row, my_oracle.get(i), raw.number, value_buffer, raw.index, value_buffer);
510 raw.value = value_buffer;
514 auto raw = my_ext->fetch(i, my_holding_vbuffer.data(), index_buffer);
516 SparseRange<OutputValue_, Index_> output(raw.number);
517 output.index = raw.index;
519 my_helper.sparse(my_row, my_oracle.get(i), raw.number, raw.value, raw.index, value_buffer);
520 output.value = value_buffer;
535template<
bool oracle_,
typename OutputValue_,
typename InputValue_,
typename Index_,
class Helper_>
536class SparseNeedsIndices final :
public SparseExtractor<oracle_, OutputValue_, Index_> {
539 const Matrix<InputValue_, Index_>& matrix,
540 const Helper_& helper,
542 MaybeOracle<oracle_, Index_> oracle,
546 my_oracle(oracle, my_helper, row)
548 initialize(opt, row ? matrix.ncol() : matrix.nrow());
549 my_ext = new_extractor<true, oracle_>(matrix, row, std::move(oracle), opt);
553 const Matrix<InputValue_, Index_>& matrix,
554 const Helper_& helper,
556 MaybeOracle<oracle_, Index_> oracle,
562 my_oracle(oracle, my_helper, row)
564 initialize(opt, block_length);
565 my_ext = new_extractor<true, oracle_>(matrix, row, std::move(oracle), block_start, block_length, opt);
569 const Matrix<InputValue_, Index_>& matrix,
570 const Helper_& helper,
572 MaybeOracle<oracle_, Index_> oracle,
573 VectorPtr<Index_> indices_ptr,
577 my_oracle(oracle, my_helper, row)
579 initialize(opt, indices_ptr->size());
580 my_ext = new_extractor<true, oracle_>(matrix, row, std::move(oracle), std::move(indices_ptr), opt);
584 void initialize(Options& opt, std::size_t extent) {
585 my_report_value = opt.sparse_extract_value;
586 my_report_index = opt.sparse_extract_index;
590 if (my_report_value) {
591 opt.sparse_extract_index =
true;
596 if (!my_report_index) {
597 my_ibuffer.resize(extent);
601 if constexpr(!same_value) {
602 if (my_report_value) {
603 my_holding_vbuffer.resize(extent);
609 const Helper_& my_helper;
612 DelayedIsometricOperation_internal::MaybeOracleDepends<oracle_, Helper_, Index_> my_oracle;
614 bool my_report_value, my_report_index;
615 std::vector<Index_> my_ibuffer;
617 std::unique_ptr<SparseExtractor<oracle_, InputValue_, Index_> > my_ext;
619 static constexpr bool same_value = std::is_same<OutputValue_, InputValue_>::value;
620 typename std::conditional<!same_value, std::vector<InputValue_>,
bool>::type my_holding_vbuffer;
623 SparseRange<OutputValue_, Index_> fetch(Index_ i, OutputValue_* value_buffer, Index_* index_buffer) {
624 auto iptr = my_report_index ? index_buffer : my_ibuffer.data();
626 if constexpr(same_value) {
627 auto raw = my_ext->fetch(i, value_buffer, iptr);
628 if (my_report_value) {
629 copy_n(raw.value, raw.number, value_buffer);
630 my_helper.sparse(my_row, my_oracle.get(i), raw.number, value_buffer, raw.index, value_buffer);
631 raw.value = value_buffer;
633 if (!my_report_index) {
639 auto raw = my_ext->fetch(i, my_holding_vbuffer.data(), iptr);
640 SparseRange<OutputValue_, Index_> output(raw.number, NULL, (my_report_index ? raw.index : NULL));
641 if (my_report_value) {
642 my_helper.sparse(my_row, my_oracle.get(i), raw.number, raw.value, raw.index, value_buffer);
643 output.value = value_buffer;
669template<
typename OutputValue_,
typename InputValue_,
typename Index_,
class Helper_ = DelayedUnaryIsometricOperationHelper<OutputValue_, InputValue_, Index_> >
678 std::shared_ptr<const Helper_> helper
680 my_matrix(std::move(matrix)),
681 my_helper(std::move(helper))
683 auto expected_rows = my_helper->nrow();
684 if (expected_rows.has_value() && *expected_rows != my_matrix->nrow()) {
685 throw std::runtime_error(
"number of rows in 'matrix' is not consistent with those expected by 'helper'");
687 auto expected_cols = my_helper->ncol();
688 if (expected_cols.has_value() && *expected_cols != my_matrix->ncol()) {
689 throw std::runtime_error(
"number of columns in 'matrix' is not consistent with those expected by 'helper'");
694 std::shared_ptr<const Matrix<InputValue_, Index_> > my_matrix;
695 std::shared_ptr<const Helper_> my_helper;
699 return my_matrix->nrow();
703 return my_matrix->ncol();
707 if (my_helper->is_sparse()) {
708 return my_matrix->is_sparse();
714 if (my_helper->is_sparse()) {
715 return my_matrix->is_sparse_proportion();
721 return my_matrix->prefer_rows();
725 return my_matrix->prefer_rows_proportion();
729 return my_matrix->uses_oracle(row);
740 template<
bool oracle_>
742 return std::make_unique<DelayedUnaryIsometricOperation_internal::DenseBasicFull<oracle_, OutputValue_, InputValue_, Index_, Helper_> >(
751 template<
bool oracle_>
752 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 {
753 return std::make_unique<DelayedUnaryIsometricOperation_internal::DenseBasicBlock<oracle_, OutputValue_, InputValue_, Index_, Helper_> >(
764 template<
bool oracle_>
766 return std::make_unique<DelayedUnaryIsometricOperation_internal::DenseBasicIndex<oracle_, OutputValue_, InputValue_, Index_, Helper_> >(
771 std::move(indices_ptr),
776 template<
bool oracle_>
777 std::unique_ptr<DenseExtractor<oracle_, OutputValue_, Index_> > dense_expanded_internal(
bool row,
MaybeOracle<oracle_, Index_> oracle,
const Options& opt)
const {
778 return std::make_unique<DelayedUnaryIsometricOperation_internal::DenseExpandedFull<oracle_, OutputValue_, InputValue_, Index_, Helper_> >(
787 template<
bool oracle_>
788 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 {
789 return std::make_unique<DelayedUnaryIsometricOperation_internal::DenseExpandedBlock<oracle_, OutputValue_, InputValue_, Index_, Helper_> >(
800 template<
bool oracle_>
802 return std::make_unique<DelayedUnaryIsometricOperation_internal::DenseExpandedIndex<oracle_, OutputValue_, InputValue_, Index_, Helper_> >(
807 std::move(indices_ptr),
812 template<
bool oracle_,
typename ... Args_>
813 std::unique_ptr<DenseExtractor<oracle_, OutputValue_, Index_> > dense_internal(
bool row, Args_&& ... args)
const {
814 if (my_matrix->is_sparse()) {
815 if (DelayedIsometricOperation_internal::can_dense_expand(*my_helper, row)) {
816 return dense_expanded_internal<oracle_>(row, std::forward<Args_>(args)...);
819 return dense_basic_internal<oracle_>(row, std::forward<Args_>(args)...);
823 std::unique_ptr<MyopicDenseExtractor<OutputValue_, Index_> >
dense(
bool row,
const Options& opt)
const {
824 return dense_internal<false>(row,
false, opt);
827 std::unique_ptr<MyopicDenseExtractor<OutputValue_, Index_> >
dense(
bool row, Index_ block_start, Index_ block_length,
const Options& opt)
const {
828 return dense_internal<false>(row,
false, block_start, block_length, opt);
832 return dense_internal<false>(row,
false, std::move(indices_ptr), opt);
839 template<
bool oracle_,
typename ... Args_>
841 return std::make_unique<FullSparsifiedWrapper<oracle_, OutputValue_, Index_> >(
842 dense_internal<oracle_>(row, std::move(oracle), opt),
843 (row ? my_matrix->ncol() : my_matrix->nrow()),
848 template<
bool oracle_,
typename ... Args_>
849 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 {
850 return std::make_unique<BlockSparsifiedWrapper<oracle_, OutputValue_, Index_> >(
851 dense_internal<oracle_>(row, std::move(oracle), block_start, block_length, opt),
858 template<
bool oracle_,
typename ... Args_>
860 return std::make_unique<IndexSparsifiedWrapper<oracle_, OutputValue_, Index_> >(
861 dense_internal<oracle_>(row, std::move(oracle), indices_ptr, opt),
867 template<
bool oracle_,
typename ... Args_>
868 std::unique_ptr<SparseExtractor<oracle_, OutputValue_, Index_> > sparse_internal(
bool row,
MaybeOracle<oracle_, Index_> oracle, Args_&& ... args)
const {
869 if (my_helper->is_sparse() && my_matrix->is_sparse()) {
870 if (DelayedIsometricOperation_internal::needs_sparse_indices(*my_helper, row)) {
871 return std::make_unique<DelayedUnaryIsometricOperation_internal::SparseNeedsIndices<oracle_, OutputValue_, InputValue_, Index_, Helper_> >(
876 std::forward<Args_>(args)...
880 return std::make_unique<DelayedUnaryIsometricOperation_internal::SparseSimple<oracle_, OutputValue_, InputValue_, Index_, Helper_> >(
885 std::forward<Args_>(args)...
889 return sparse_to_dense_internal<oracle_>(row, std::move(oracle), std::forward<Args_>(args)...);
893 std::unique_ptr<MyopicSparseExtractor<OutputValue_, Index_> >
sparse(
bool row,
const Options& opt)
const {
894 return sparse_internal<false>(row,
false, opt);
897 std::unique_ptr<MyopicSparseExtractor<OutputValue_, Index_> >
sparse(
bool row, Index_ block_start, Index_ block_length,
const Options& opt)
const {
898 return sparse_internal<false>(row,
false, block_start, block_length, opt);
902 return sparse_internal<false>(row,
false, std::move(indices_ptr), opt);
909 std::unique_ptr<OracularDenseExtractor<OutputValue_, Index_> >
dense(
bool row, std::shared_ptr<
const Oracle<Index_> > oracle,
const Options& opt)
const {
910 return dense_internal<true>(row, std::move(oracle), opt);
913 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 {
914 return dense_internal<true>(row, std::move(oracle), block_start, block_length, opt);
918 return dense_internal<true>(row, std::move(oracle), std::move(indices_ptr), opt);
925 std::unique_ptr<OracularSparseExtractor<OutputValue_, Index_> >
sparse(
bool row, std::shared_ptr<
const Oracle<Index_> > oracle,
const Options& opt)
const {
926 return sparse_internal<true>(row, std::move(oracle), opt);
929 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 {
930 return sparse_internal<true>(row, std::move(oracle), block_start, block_length, opt);
934 return sparse_internal<true>(row, std::move(oracle), std::move(indices_ptr), opt);
942template<
typename OutputValue_ =
double,
typename InputValue_,
typename Index_,
class Helper_>
943std::shared_ptr<Matrix<OutputValue_, Index_> > make_DelayedUnaryIsometricOperation(std::shared_ptr<
const Matrix<InputValue_, Index_> > matrix, std::shared_ptr<const Helper_> helper) {
944 return std::shared_ptr<Matrix<OutputValue_, Index_> >(
new DelayedUnaryIsometricOperation<OutputValue_, InputValue_, Index_, Helper_>(std::move(matrix), std::move(helper)));
947template<
typename OutputValue_ =
double,
typename InputValue_,
typename Index_,
class Helper_>
948std::shared_ptr<Matrix<OutputValue_, Index_> > make_DelayedUnaryIsometricOperation(std::shared_ptr<Matrix<InputValue_, Index_> > matrix, std::shared_ptr<Helper_> helper) {
949 return std::shared_ptr<Matrix<OutputValue_, Index_> >(
new DelayedUnaryIsometricOperation<OutputValue_, InputValue_, Index_, Helper_>(std::move(matrix), std::move(helper)));
952template<
typename ... Args_>
953auto make_DelayedIsometricOperation(Args_&&... args) {
954 return make_DelayedUnaryIsometricOperation(std::forward<Args_>(args)...);
957template<
typename OutputValue_,
typename Index_,
class Helper_>
958using 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:670
bool prefer_rows() const
Definition DelayedUnaryIsometricOperation.hpp:720
double is_sparse_proportion() const
Definition DelayedUnaryIsometricOperation.hpp:713
std::unique_ptr< OracularDenseExtractor< OutputValue_, Index_ > > dense(bool row, std::shared_ptr< const Oracle< Index_ > > oracle, const Options &opt) const
Definition DelayedUnaryIsometricOperation.hpp:909
std::unique_ptr< MyopicDenseExtractor< OutputValue_, Index_ > > dense(bool row, VectorPtr< Index_ > indices_ptr, const Options &opt) const
Definition DelayedUnaryIsometricOperation.hpp:831
std::unique_ptr< MyopicDenseExtractor< OutputValue_, Index_ > > dense(bool row, const Options &opt) const
Definition DelayedUnaryIsometricOperation.hpp:823
Index_ ncol() const
Definition DelayedUnaryIsometricOperation.hpp:702
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:917
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:933
bool uses_oracle(bool row) const
Definition DelayedUnaryIsometricOperation.hpp:728
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:929
double prefer_rows_proportion() const
Definition DelayedUnaryIsometricOperation.hpp:724
DelayedUnaryIsometricOperation(std::shared_ptr< const Matrix< InputValue_, Index_ > > matrix, std::shared_ptr< const Helper_ > helper)
Definition DelayedUnaryIsometricOperation.hpp:676
bool is_sparse() const
Definition DelayedUnaryIsometricOperation.hpp:706
std::unique_ptr< MyopicSparseExtractor< OutputValue_, Index_ > > sparse(bool row, const Options &opt) const
Definition DelayedUnaryIsometricOperation.hpp:893
std::unique_ptr< MyopicDenseExtractor< OutputValue_, Index_ > > dense(bool row, Index_ block_start, Index_ block_length, const Options &opt) const
Definition DelayedUnaryIsometricOperation.hpp:827
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:913
std::unique_ptr< OracularSparseExtractor< OutputValue_, Index_ > > sparse(bool row, std::shared_ptr< const Oracle< Index_ > > oracle, const Options &opt) const
Definition DelayedUnaryIsometricOperation.hpp:925
std::unique_ptr< MyopicSparseExtractor< OutputValue_, Index_ > > sparse(bool row, VectorPtr< Index_ > indices_ptr, const Options &opt) const
Definition DelayedUnaryIsometricOperation.hpp:901
Index_ nrow() const
Definition DelayedUnaryIsometricOperation.hpp:698
std::unique_ptr< MyopicSparseExtractor< OutputValue_, Index_ > > sparse(bool row, Index_ block_start, Index_ block_length, const Options &opt) const
Definition DelayedUnaryIsometricOperation.hpp:897
Virtual class for a matrix.
Definition Matrix.hpp:59
Predict future access requests on the target dimension.
Definition Oracle.hpp:23
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
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:25
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.