tatami
C++ API for different matrix representations
Loading...
Searching...
No Matches
DelayedTranspose.hpp
Go to the documentation of this file.
1#ifndef TATAMI_DELAYED_TRANSPOSE
2#define TATAMI_DELAYED_TRANSPOSE
3
4#include "../base/Matrix.hpp"
5#include <memory>
6
15namespace tatami {
16
26template<typename Value_, typename Index_>
27class DelayedTranspose : public Matrix<Value_, Index_> {
28public:
32 DelayedTranspose(std::shared_ptr<const Matrix<Value_, Index_> > matrix) : my_matrix(std::move(matrix)) {}
33
37 DelayedTranspose(std::shared_ptr<Matrix<Value_, Index_> > matrix) : my_matrix(std::move(matrix)) {}
38
39private:
40 std::shared_ptr<const Matrix<Value_, Index_> > my_matrix;
41
42public:
43 Index_ nrow() const {
44 return my_matrix->ncol();
45 }
46
47 Index_ ncol() const {
48 return my_matrix->nrow();
49 }
50
51 bool is_sparse() const {
52 return my_matrix->is_sparse();
53 }
54
55 double is_sparse_proportion() const {
56 return my_matrix->is_sparse_proportion();
57 }
58
59 bool prefer_rows() const {
60 return !my_matrix->prefer_rows();
61 }
62
63 double prefer_rows_proportion() const {
64 return 1 - my_matrix->prefer_rows_proportion();
65 }
66
67 bool uses_oracle(bool row) const {
68 return my_matrix->uses_oracle(!row);
69 }
70
72
74
75 /********************
76 *** Myopic dense ***
77 ********************/
78public:
79 std::unique_ptr<MyopicDenseExtractor<Value_, Index_> > dense(bool row, const Options& opt) const {
80 return my_matrix->dense(!row, opt);
81 }
82
83 std::unique_ptr<MyopicDenseExtractor<Value_, Index_> > dense(bool row, Index_ block_start, Index_ block_length, const Options& opt) const {
84 return my_matrix->dense(!row, block_start, block_length, opt);
85 }
86
87 std::unique_ptr<MyopicDenseExtractor<Value_, Index_> > dense(bool row, VectorPtr<Index_> indices_ptr, const Options& opt) const {
88 return my_matrix->dense(!row, std::move(indices_ptr), opt);
89 }
90
91 /*********************
92 *** Myopic sparse ***
93 *********************/
94public:
95 std::unique_ptr<MyopicSparseExtractor<Value_, Index_> > sparse(bool row, const Options& opt) const {
96 return my_matrix->sparse(!row, opt);
97 }
98
99 std::unique_ptr<MyopicSparseExtractor<Value_, Index_> > sparse(bool row, Index_ block_start, Index_ block_length, const Options& opt) const {
100 return my_matrix->sparse(!row, block_start, block_length, opt);
101 }
102
103 std::unique_ptr<MyopicSparseExtractor<Value_, Index_> > sparse(bool row, VectorPtr<Index_> indices_ptr, const Options& opt) const {
104 return my_matrix->sparse(!row, std::move(indices_ptr), opt);
105 }
106
107 /**********************
108 *** Oracular dense ***
109 **********************/
110public:
111 std::unique_ptr<OracularDenseExtractor<Value_, Index_> > dense(bool row, std::shared_ptr<const Oracle<Index_> > oracle, const Options& opt) const {
112 return my_matrix->dense(!row, std::move(oracle), opt);
113 }
114
115 std::unique_ptr<OracularDenseExtractor<Value_, Index_> > dense(bool row, std::shared_ptr<const Oracle<Index_> > oracle, Index_ block_start, Index_ block_length, const Options& opt) const {
116 return my_matrix->dense(!row, std::move(oracle), block_start, block_length, opt);
117 }
118
119 std::unique_ptr<OracularDenseExtractor<Value_, Index_> > dense(bool row, std::shared_ptr<const Oracle<Index_> > oracle, VectorPtr<Index_> indices_ptr, const Options& opt) const {
120 return my_matrix->dense(!row, std::move(oracle), std::move(indices_ptr), opt);
121 }
122
123 /***********************
124 *** Oracular sparse ***
125 ***********************/
126public:
127 std::unique_ptr<OracularSparseExtractor<Value_, Index_> > sparse(bool row, std::shared_ptr<const Oracle<Index_> > oracle, const Options& opt) const {
128 return my_matrix->sparse(!row, std::move(oracle), opt);
129 }
130
131 std::unique_ptr<OracularSparseExtractor<Value_, Index_> > sparse(bool row, std::shared_ptr<const Oracle<Index_> > oracle, Index_ block_start, Index_ block_length, const Options& opt) const {
132 return my_matrix->sparse(!row, std::move(oracle), block_start, block_length, opt);
133 }
134
135 std::unique_ptr<OracularSparseExtractor<Value_, Index_> > sparse(bool row, std::shared_ptr<const Oracle<Index_> > oracle, VectorPtr<Index_> indices, const Options& opt) const {
136 return my_matrix->sparse(!row, std::move(oracle), std::move(indices), opt);
137 }
138};
139
143// Soft-deprecated, kept around for back-compatibility only.
144template<typename Value_, typename Index_>
145std::shared_ptr<Matrix<Value_, Index_> > make_DelayedTranspose(std::shared_ptr<const Matrix<Value_, Index_> > matrix) {
146 return std::shared_ptr<Matrix<Value_, Index_> >(new DelayedTranspose<Value_, Index_>(std::move(matrix)));
147}
148
149template<typename Value_, typename Index_>
150std::shared_ptr<Matrix<Value_, Index_> > make_DelayedTranspose(std::shared_ptr<Matrix<Value_, Index_> > matrix) {
151 return std::shared_ptr<Matrix<Value_, Index_> >(new DelayedTranspose<Value_, Index_>(std::move(matrix)));
152}
157}
158
159#endif
Delayed transposition of a matrix.
Definition DelayedTranspose.hpp:27
DelayedTranspose(std::shared_ptr< const Matrix< Value_, Index_ > > matrix)
Definition DelayedTranspose.hpp:32
std::unique_ptr< MyopicSparseExtractor< Value_, Index_ > > sparse(bool row, Index_ block_start, Index_ block_length, const Options &opt) const
Definition DelayedTranspose.hpp:99
std::unique_ptr< MyopicDenseExtractor< Value_, Index_ > > dense(bool row, VectorPtr< Index_ > indices_ptr, const Options &opt) const
Definition DelayedTranspose.hpp:87
std::unique_ptr< MyopicDenseExtractor< Value_, Index_ > > dense(bool row, Index_ block_start, Index_ block_length, const Options &opt) const
Definition DelayedTranspose.hpp:83
std::unique_ptr< MyopicDenseExtractor< Value_, Index_ > > dense(bool row, const Options &opt) const
Definition DelayedTranspose.hpp:79
Index_ ncol() const
Definition DelayedTranspose.hpp:47
std::unique_ptr< OracularSparseExtractor< Value_, Index_ > > sparse(bool row, std::shared_ptr< const Oracle< Index_ > > oracle, Index_ block_start, Index_ block_length, const Options &opt) const
Definition DelayedTranspose.hpp:131
std::unique_ptr< MyopicSparseExtractor< Value_, Index_ > > sparse(bool row, VectorPtr< Index_ > indices_ptr, const Options &opt) const
Definition DelayedTranspose.hpp:103
bool is_sparse() const
Definition DelayedTranspose.hpp:51
std::unique_ptr< OracularDenseExtractor< Value_, Index_ > > dense(bool row, std::shared_ptr< const Oracle< Index_ > > oracle, Index_ block_start, Index_ block_length, const Options &opt) const
Definition DelayedTranspose.hpp:115
bool uses_oracle(bool row) const
Definition DelayedTranspose.hpp:67
std::unique_ptr< MyopicSparseExtractor< Value_, Index_ > > sparse(bool row, const Options &opt) const
Definition DelayedTranspose.hpp:95
bool prefer_rows() const
Definition DelayedTranspose.hpp:59
std::unique_ptr< OracularSparseExtractor< Value_, Index_ > > sparse(bool row, std::shared_ptr< const Oracle< Index_ > > oracle, const Options &opt) const
Definition DelayedTranspose.hpp:127
DelayedTranspose(std::shared_ptr< Matrix< Value_, Index_ > > matrix)
Definition DelayedTranspose.hpp:37
std::unique_ptr< OracularSparseExtractor< Value_, Index_ > > sparse(bool row, std::shared_ptr< const Oracle< Index_ > > oracle, VectorPtr< Index_ > indices, const Options &opt) const
Definition DelayedTranspose.hpp:135
std::unique_ptr< OracularDenseExtractor< Value_, Index_ > > dense(bool row, std::shared_ptr< const Oracle< Index_ > > oracle, const Options &opt) const
Definition DelayedTranspose.hpp:111
std::unique_ptr< OracularDenseExtractor< Value_, Index_ > > dense(bool row, std::shared_ptr< const Oracle< Index_ > > oracle, VectorPtr< Index_ > indices_ptr, const Options &opt) const
Definition DelayedTranspose.hpp:119
Index_ nrow() const
Definition DelayedTranspose.hpp:43
double is_sparse_proportion() const
Definition DelayedTranspose.hpp:55
double prefer_rows_proportion() const
Definition DelayedTranspose.hpp:63
Virtual class for a matrix.
Definition Matrix.hpp:59
Predict future access requests on the target dimension.
Definition Oracle.hpp:21
Flexible representations for matrix data.
Definition Extractor.hpp:15
std::shared_ptr< const std::vector< Index_ > > VectorPtr
Definition Matrix.hpp:26
auto consecutive_extractor(const Matrix< Value_, Index_ > *mat, bool row, Index_ iter_start, Index_ iter_length, Args_ &&... args)
Definition consecutive_extractor.hpp:35
Options for accessing data from a Matrix instance.
Definition Options.hpp:30