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
34private:
35 std::shared_ptr<const Matrix<Value_, Index_> > my_matrix;
36
37public:
38 Index_ nrow() const {
39 return my_matrix->ncol();
40 }
41
42 Index_ ncol() const {
43 return my_matrix->nrow();
44 }
45
46 bool is_sparse() const {
47 return my_matrix->is_sparse();
48 }
49
50 double is_sparse_proportion() const {
51 return my_matrix->is_sparse_proportion();
52 }
53
54 bool prefer_rows() const {
55 return !my_matrix->prefer_rows();
56 }
57
58 double prefer_rows_proportion() const {
59 return 1 - my_matrix->prefer_rows_proportion();
60 }
61
62 bool uses_oracle(const bool row) const {
63 return my_matrix->uses_oracle(!row);
64 }
65
66 using Matrix<Value_, Index_>::dense;
67
68 using Matrix<Value_, Index_>::sparse;
69
70 /********************
71 *** Myopic dense ***
72 ********************/
73public:
74 std::unique_ptr<MyopicDenseExtractor<Value_, Index_> > dense(
75 const bool row,
76 const Options& opt
77 ) const {
78 return my_matrix->dense(!row, opt);
79 }
80
81 std::unique_ptr<MyopicDenseExtractor<Value_, Index_> > dense(
82 const bool row,
83 const Index_ block_start,
84 const Index_ block_length,
85 const Options& opt
86 ) const {
87 return my_matrix->dense(!row, block_start, block_length, opt);
88 }
89
90 std::unique_ptr<MyopicDenseExtractor<Value_, Index_> > dense(
91 const bool row,
92 VectorPtr<Index_> indices_ptr,
93 const Options& opt
94 ) const {
95 return my_matrix->dense(!row, std::move(indices_ptr), opt);
96 }
97
98 /*********************
99 *** Myopic sparse ***
100 *********************/
101public:
102 std::unique_ptr<MyopicSparseExtractor<Value_, Index_> > sparse(
103 const bool row,
104 const Options& opt
105 ) const {
106 return my_matrix->sparse(!row, opt);
107 }
108
109 std::unique_ptr<MyopicSparseExtractor<Value_, Index_> > sparse(
110 const bool row,
111 const Index_ block_start,
112 const Index_ block_length,
113 const Options& opt
114 ) const {
115 return my_matrix->sparse(!row, block_start, block_length, opt);
116 }
117
118 std::unique_ptr<MyopicSparseExtractor<Value_, Index_> > sparse(
119 const bool row,
120 VectorPtr<Index_> indices_ptr,
121 const Options& opt
122 ) const {
123 return my_matrix->sparse(!row, std::move(indices_ptr), opt);
124 }
125
126 /**********************
127 *** Oracular dense ***
128 **********************/
129public:
130 std::unique_ptr<OracularDenseExtractor<Value_, Index_> > dense(
131 const bool row,
132 std::shared_ptr<const Oracle<Index_> > oracle,
133 const Options& opt
134 ) const {
135 return my_matrix->dense(!row, std::move(oracle), opt);
136 }
137
138 std::unique_ptr<OracularDenseExtractor<Value_, Index_> > dense(
139 const bool row,
140 std::shared_ptr<const Oracle<Index_> > oracle,
141 const Index_ block_start,
142 const Index_ block_length,
143 const Options& opt
144 ) const {
145 return my_matrix->dense(!row, std::move(oracle), block_start, block_length, opt);
146 }
147
148 std::unique_ptr<OracularDenseExtractor<Value_, Index_> > dense(
149 const bool row,
150 std::shared_ptr<const Oracle<Index_> > oracle,
151 VectorPtr<Index_> indices_ptr,
152 const Options& opt
153 ) const {
154 return my_matrix->dense(!row, std::move(oracle), std::move(indices_ptr), opt);
155 }
156
157 /***********************
158 *** Oracular sparse ***
159 ***********************/
160public:
161 std::unique_ptr<OracularSparseExtractor<Value_, Index_> > sparse(
162 const bool row,
163 std::shared_ptr<const Oracle<Index_> > oracle,
164 const Options& opt
165 ) const {
166 return my_matrix->sparse(!row, std::move(oracle), opt);
167 }
168
169 std::unique_ptr<OracularSparseExtractor<Value_, Index_> > sparse(
170 const bool row,
171 std::shared_ptr<const Oracle<Index_> > oracle,
172 const Index_ block_start,
173 const Index_ block_length,
174 const Options& opt
175 ) const {
176 return my_matrix->sparse(!row, std::move(oracle), block_start, block_length, opt);
177 }
178
179 std::unique_ptr<OracularSparseExtractor<Value_, Index_> > sparse(
180 const bool row,
181 std::shared_ptr<const Oracle<Index_> > oracle,
182 VectorPtr<Index_> indices,
183 const Options& opt
184 ) const {
185 return my_matrix->sparse(!row, std::move(oracle), std::move(indices), opt);
186 }
187};
188
192// Soft-deprecated, kept around for back-compatibility only.
193template<typename Value_, typename Index_>
194std::shared_ptr<Matrix<Value_, Index_> > make_DelayedTranspose(std::shared_ptr<const Matrix<Value_, Index_> > matrix) {
195 return std::shared_ptr<Matrix<Value_, Index_> >(new DelayedTranspose<Value_, Index_>(std::move(matrix)));
196}
197
198template<typename Value_, typename Index_>
199std::shared_ptr<Matrix<Value_, Index_> > make_DelayedTranspose(std::shared_ptr<Matrix<Value_, Index_> > matrix) {
200 return std::shared_ptr<Matrix<Value_, Index_> >(new DelayedTranspose<Value_, Index_>(std::move(matrix)));
201}
206}
207
208#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:74
Index_ ncol() const
Definition DelayedTranspose.hpp:42
std::unique_ptr< OracularDenseExtractor< Value_, Index_ > > dense(const bool row, std::shared_ptr< const Oracle< Index_ > > oracle, const Options &opt) const
Definition DelayedTranspose.hpp:130
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:169
bool is_sparse() const
Definition DelayedTranspose.hpp:46
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:179
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:148
std::unique_ptr< MyopicDenseExtractor< Value_, Index_ > > dense(const bool row, VectorPtr< Index_ > indices_ptr, const Options &opt) const
Definition DelayedTranspose.hpp:90
std::unique_ptr< OracularSparseExtractor< Value_, Index_ > > sparse(const bool row, std::shared_ptr< const Oracle< Index_ > > oracle, const Options &opt) const
Definition DelayedTranspose.hpp:161
bool prefer_rows() const
Definition DelayedTranspose.hpp:54
bool uses_oracle(const bool row) const
Definition DelayedTranspose.hpp:62
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:81
std::unique_ptr< MyopicSparseExtractor< Value_, Index_ > > sparse(const bool row, VectorPtr< Index_ > indices_ptr, const Options &opt) const
Definition DelayedTranspose.hpp:118
std::unique_ptr< MyopicSparseExtractor< Value_, Index_ > > sparse(const bool row, const Options &opt) const
Definition DelayedTranspose.hpp:102
Index_ nrow() const
Definition DelayedTranspose.hpp:38
double is_sparse_proportion() const
Definition DelayedTranspose.hpp:50
double prefer_rows_proportion() const
Definition DelayedTranspose.hpp:58
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:138
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:109
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