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 final : 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(const bool row) const {
68 return my_matrix->uses_oracle(!row);
69 }
70
71 using Matrix<Value_, Index_>::dense;
72
73 using Matrix<Value_, Index_>::sparse;
74
75 /********************
76 *** Myopic dense ***
77 ********************/
78public:
79 std::unique_ptr<MyopicDenseExtractor<Value_, Index_> > dense(
80 const bool row,
81 const Options& opt
82 ) const {
83 return my_matrix->dense(!row, opt);
84 }
85
86 std::unique_ptr<MyopicDenseExtractor<Value_, Index_> > dense(
87 const bool row,
88 const Index_ block_start,
89 const Index_ block_length,
90 const Options& opt
91 ) const {
92 return my_matrix->dense(!row, block_start, block_length, opt);
93 }
94
95 std::unique_ptr<MyopicDenseExtractor<Value_, Index_> > dense(
96 const bool row,
97 VectorPtr<Index_> indices_ptr,
98 const Options& opt
99 ) const {
100 return my_matrix->dense(!row, std::move(indices_ptr), opt);
101 }
102
103 /*********************
104 *** Myopic sparse ***
105 *********************/
106public:
107 std::unique_ptr<MyopicSparseExtractor<Value_, Index_> > sparse(
108 const bool row,
109 const Options& opt
110 ) const {
111 return my_matrix->sparse(!row, opt);
112 }
113
114 std::unique_ptr<MyopicSparseExtractor<Value_, Index_> > sparse(
115 const bool row,
116 const Index_ block_start,
117 const Index_ block_length,
118 const Options& opt
119 ) const {
120 return my_matrix->sparse(!row, block_start, block_length, opt);
121 }
122
123 std::unique_ptr<MyopicSparseExtractor<Value_, Index_> > sparse(
124 const bool row,
125 VectorPtr<Index_> indices_ptr,
126 const Options& opt
127 ) const {
128 return my_matrix->sparse(!row, std::move(indices_ptr), opt);
129 }
130
131 /**********************
132 *** Oracular dense ***
133 **********************/
134public:
135 std::unique_ptr<OracularDenseExtractor<Value_, Index_> > dense(
136 const bool row,
137 std::shared_ptr<const Oracle<Index_> > oracle,
138 const Options& opt
139 ) const {
140 return my_matrix->dense(!row, std::move(oracle), opt);
141 }
142
143 std::unique_ptr<OracularDenseExtractor<Value_, Index_> > dense(
144 const bool row,
145 std::shared_ptr<const Oracle<Index_> > oracle,
146 const Index_ block_start,
147 const Index_ block_length,
148 const Options& opt
149 ) const {
150 return my_matrix->dense(!row, std::move(oracle), block_start, block_length, opt);
151 }
152
153 std::unique_ptr<OracularDenseExtractor<Value_, Index_> > dense(
154 const bool row,
155 std::shared_ptr<const Oracle<Index_> > oracle,
156 VectorPtr<Index_> indices_ptr,
157 const Options& opt
158 ) const {
159 return my_matrix->dense(!row, std::move(oracle), std::move(indices_ptr), opt);
160 }
161
162 /***********************
163 *** Oracular sparse ***
164 ***********************/
165public:
166 std::unique_ptr<OracularSparseExtractor<Value_, Index_> > sparse(
167 const bool row,
168 std::shared_ptr<const Oracle<Index_> > oracle,
169 const Options& opt
170 ) const {
171 return my_matrix->sparse(!row, std::move(oracle), opt);
172 }
173
174 std::unique_ptr<OracularSparseExtractor<Value_, Index_> > sparse(
175 const bool row,
176 std::shared_ptr<const Oracle<Index_> > oracle,
177 const Index_ block_start,
178 const Index_ block_length,
179 const Options& opt
180 ) const {
181 return my_matrix->sparse(!row, std::move(oracle), block_start, block_length, opt);
182 }
183
184 std::unique_ptr<OracularSparseExtractor<Value_, Index_> > sparse(
185 const bool row,
186 std::shared_ptr<const Oracle<Index_> > oracle,
187 VectorPtr<Index_> indices,
188 const Options& opt
189 ) const {
190 return my_matrix->sparse(!row, std::move(oracle), std::move(indices), opt);
191 }
192};
193
197// Soft-deprecated, kept around for back-compatibility only.
198template<typename Value_, typename Index_>
199std::shared_ptr<Matrix<Value_, Index_> > make_DelayedTranspose(std::shared_ptr<const Matrix<Value_, Index_> > matrix) {
200 return std::shared_ptr<Matrix<Value_, Index_> >(new DelayedTranspose<Value_, Index_>(std::move(matrix)));
201}
202
203template<typename Value_, typename Index_>
204std::shared_ptr<Matrix<Value_, Index_> > make_DelayedTranspose(std::shared_ptr<Matrix<Value_, Index_> > matrix) {
205 return std::shared_ptr<Matrix<Value_, Index_> >(new DelayedTranspose<Value_, Index_>(std::move(matrix)));
206}
211}
212
213#endif
Virtual class for a matrix of some numeric type.
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< MyopicDenseExtractor< Value_, Index_ > > dense(const bool row, const Options &opt) const
Definition DelayedTranspose.hpp:79
Index_ ncol() const
Definition DelayedTranspose.hpp:47
std::unique_ptr< OracularDenseExtractor< Value_, Index_ > > dense(const bool row, std::shared_ptr< const Oracle< Index_ > > oracle, const Options &opt) const
Definition DelayedTranspose.hpp:135
std::unique_ptr< OracularSparseExtractor< Value_, Index_ > > sparse(const bool row, std::shared_ptr< const Oracle< Index_ > > oracle, const Index_ block_start, const Index_ block_length, const Options &opt) const
Definition DelayedTranspose.hpp:174
bool is_sparse() const
Definition DelayedTranspose.hpp:51
std::unique_ptr< OracularSparseExtractor< Value_, Index_ > > sparse(const bool row, std::shared_ptr< const Oracle< Index_ > > oracle, VectorPtr< Index_ > indices, const Options &opt) const
Definition DelayedTranspose.hpp:184
std::unique_ptr< OracularDenseExtractor< Value_, Index_ > > dense(const bool row, std::shared_ptr< const Oracle< Index_ > > oracle, VectorPtr< Index_ > indices_ptr, const Options &opt) const
Definition DelayedTranspose.hpp:153
std::unique_ptr< MyopicDenseExtractor< Value_, Index_ > > dense(const bool row, VectorPtr< Index_ > indices_ptr, const Options &opt) const
Definition DelayedTranspose.hpp:95
std::unique_ptr< OracularSparseExtractor< Value_, Index_ > > sparse(const bool row, std::shared_ptr< const Oracle< Index_ > > oracle, const Options &opt) const
Definition DelayedTranspose.hpp:166
bool prefer_rows() const
Definition DelayedTranspose.hpp:59
bool uses_oracle(const bool row) const
Definition DelayedTranspose.hpp:67
std::unique_ptr< MyopicDenseExtractor< Value_, Index_ > > dense(const bool row, const Index_ block_start, const Index_ block_length, const Options &opt) const
Definition DelayedTranspose.hpp:86
DelayedTranspose(std::shared_ptr< Matrix< Value_, Index_ > > matrix)
Definition DelayedTranspose.hpp:37
std::unique_ptr< MyopicSparseExtractor< Value_, Index_ > > sparse(const bool row, VectorPtr< Index_ > indices_ptr, const Options &opt) const
Definition DelayedTranspose.hpp:123
std::unique_ptr< MyopicSparseExtractor< Value_, Index_ > > sparse(const bool row, const Options &opt) const
Definition DelayedTranspose.hpp:107
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
std::unique_ptr< OracularDenseExtractor< Value_, Index_ > > dense(const bool row, std::shared_ptr< const Oracle< Index_ > > oracle, const Index_ block_start, const Index_ block_length, const Options &opt) const
Definition DelayedTranspose.hpp:143
std::unique_ptr< MyopicSparseExtractor< Value_, Index_ > > sparse(const bool row, const Index_ block_start, const Index_ block_length, const Options &opt) const
Definition DelayedTranspose.hpp:114
Virtual class for a matrix.
Definition Matrix.hpp:59
Predict future access requests on the target dimension.
Definition Oracle.hpp:29
Flexible representations for matrix data.
Definition Extractor.hpp:15
std::shared_ptr< const std::vector< Index_ > > VectorPtr
Definition Matrix.hpp:26
Options for accessing data from a Matrix instance.
Definition Options.hpp:30