tatami
C++ API for different matrix representations
Loading...
Searching...
No Matches
compare_helpers.hpp
Go to the documentation of this file.
1#ifndef TATAMI_ISOMETRIC_UNARY_COMPARE_HELPERS_H
2#define TATAMI_ISOMETRIC_UNARY_COMPARE_HELPERS_H
3
4#include "../compare_utils.hpp"
5#include <vector>
6#include <type_traits>
7
14namespace tatami {
15
19template<CompareOperation op_, typename InputValue_, typename Index_, typename OutputValue_>
21 for (Index_ i = 0; i < length; ++i) {
22 if constexpr(std::is_same<InputValue_, OutputValue_>::value) {
23 auto& val = output[i];
25 } else {
27 }
28 }
29}
30
31template<CompareOperation op_, typename InputValue_>
34}
49template<CompareOperation op_, typename InputValue_>
51public:
59
60private:
61 InputValue_ my_scalar;
62 bool my_sparse;
63
64public:
68 static constexpr bool is_basic = false;
69
70 bool is_sparse() const {
71 return my_sparse;
72 }
77public:
81 template<typename Index_, typename OutputValue_>
82 void dense(bool, Index_, Index_, Index_ length, const InputValue_* input, OutputValue_* output) const {
84 }
85
86 template<typename Index_, typename OutputValue_>
87 void dense(bool, Index_, const std::vector<Index_>& indices, const InputValue_* input, OutputValue_* output) const {
88 delayed_compare_run_simple<op_>(input, static_cast<Index_>(indices.size()), my_scalar, output);
89 }
90
91 template<typename Index_, typename OutputValue_>
92 void sparse(bool, Index_, Index_ number, const InputValue_* input_value, const Index_*, OutputValue_* output_value) const {
94 }
95
96 template<typename OutputValue_, typename, typename Index_>
97 OutputValue_ fill(bool, Index_) const {
98 return delayed_compare<op_, InputValue_>(0, my_scalar);
99 }
103};
104
116template<CompareOperation op_, typename InputValue_, typename Vector_>
118public:
128 for (auto x : my_vector) {
130 my_sparse = false;
131 break;
132 }
133 }
134 }
135
136private:
137 Vector_ my_vector;
138 bool my_by_row;
139 bool my_sparse = true;
140
141public:
145 static constexpr bool is_basic = false;
146
147 bool zero_depends_on_row() const {
148 return my_by_row;
149 }
150
151 bool zero_depends_on_column() const {
152 return !my_by_row;
153 }
154
155 bool non_zero_depends_on_row() const {
156 return my_by_row;
157 }
158
159 bool non_zero_depends_on_column() const {
160 return !my_by_row;
161 }
162
163 bool is_sparse() const {
164 return my_sparse;
165 }
170public:
174 template<typename Index_, typename OutputValue_>
175 void dense(bool row, Index_ idx, Index_ start, Index_ length, const InputValue_* input, OutputValue_* output) const {
176 if (row == my_by_row) {
178 } else {
179 for (Index_ i = 0; i < length; ++i) {
180 if constexpr(std::is_same<InputValue_, OutputValue_>::value) {
181 auto& val = output[i];
183 } else {
185 }
186 }
187 }
188 }
189
190 template<typename Index_, typename OutputValue_>
191 void dense(bool row, Index_ idx, const std::vector<Index_>& indices, const InputValue_* input, OutputValue_* output) const {
192 if (row == my_by_row) {
194 } else {
195 Index_ length = indices.size();
196 for (Index_ i = 0; i < length; ++i) {
197 if constexpr(std::is_same<InputValue_, OutputValue_>::value) {
198 auto& val = output[i];
200 } else {
202 }
203 }
204 }
205 }
206
207 template<typename Index_, typename OutputValue_>
208 void sparse(bool row, Index_ idx, Index_ number, const InputValue_* input, const Index_* indices, OutputValue_* output) const {
209 if (row == my_by_row) {
211 } else {
212 for (Index_ i = 0; i < number; ++i) {
213 if constexpr(std::is_same<InputValue_, OutputValue_>::value) {
214 auto& val = output[i];
216 } else {
218 }
219 }
220 }
221 }
222
223 template<typename OutputValue_, typename, typename Index_>
224 OutputValue_ fill(bool row, Index_ idx) const {
225 if (row == my_by_row) {
226 return delayed_compare<op_, InputValue_>(0, my_vector[idx]);
227 } else {
228 // We should only get to this point if it's sparse, otherwise no
229 // single fill value would work across the length of my_vector.
230 return 0;
231 }
232 }
236};
237
244template<typename InputValue_ = double>
248
255template<typename InputValue_ = double>
259
266template<typename InputValue_ = double>
270
277template<typename InputValue_ = double>
281
288template<typename InputValue_ = double>
292
299template<typename InputValue_ = double>
303
312template<typename InputValue_ = double, typename Vector_>
316
325template<typename InputValue_ = double, typename Vector_>
329
338template<typename InputValue_ = double, typename Vector_>
342
351template<typename InputValue_ = double, typename Vector_>
355
364template<typename InputValue_ = double, typename Vector_>
368
377template<typename InputValue_ = double, typename Vector_>
381
385template<SpecialCompareOperation op_, bool pass_, typename InputValue_, typename Index_>
387 for (Index_ i = 0; i < length; ++i) {
388 auto& val = buffer[i];
390 }
391}
392
393template<SpecialCompareOperation op_, bool pass_, typename InputValue_, typename Index_, typename OutputValue_>
395 for (Index_ i = 0; i < length; ++i) {
397 }
398}
399
400template<SpecialCompareOperation op_, bool pass_, typename InputValue_>
403}
419template<SpecialCompareOperation op_, bool pass_, typename InputValue_>
421public:
424 }
425
426private:
427 bool my_sparse;
428
429public:
433 static constexpr bool is_basic = false;
434
435 bool is_sparse() const {
436 return my_sparse;
437 }
442public:
446 template<typename Index_>
447 void dense(bool, Index_, Index_, Index_ length, InputValue_* buffer) const {
449 }
450
451 template<typename Index_, typename OutputValue_>
452 void dense(bool, Index_, Index_, Index_ length, const InputValue_* input, OutputValue_* output) const {
454 }
455
456 template<typename Index_>
457 void dense(bool, Index_, const std::vector<Index_>& indices, InputValue_* buffer) const {
459 }
460
461 template<typename Index_, typename OutputValue_>
462 void dense(bool, Index_, const std::vector<Index_>& indices, const InputValue_* input, OutputValue_* output) const {
464 }
465
466 template<typename Index_>
467 void sparse(bool, Index_, Index_ number, InputValue_* buffer, const Index_*) const {
469 }
470
471 template<typename Index_, typename OutputValue_>
472 void sparse(bool, Index_, Index_ number, const InputValue_* input, const Index_*, OutputValue_* output) const {
474 }
475
476 template<typename OutputValue_, typename, typename Index_>
477 OutputValue_ fill(bool, Index_) const {
478 return !my_sparse;
479 }
483};
484
491template<bool pass_ = true, typename InputValue_ = double>
495
502template<bool pass_ = true, typename InputValue_ = double>
506
513template<bool pass_ = true, typename InputValue_ = double>
517
518}
519
520#endif
Delayed scalar comparison.
Definition compare_helpers.hpp:50
DelayedUnaryIsometricCompareScalar(InputValue_ scalar)
Definition compare_helpers.hpp:56
Delayed vector comparisons.
Definition compare_helpers.hpp:117
DelayedUnaryIsometricCompareVector(Vector_ vector, bool by_row)
Definition compare_helpers.hpp:127
Delayed special value comparison.
Definition compare_helpers.hpp:420
Flexible representations for matrix data.
Definition Extractor.hpp:15
DelayedUnaryIsometricCompareScalar< CompareOperation::LESS_THAN, InputValue_ > make_DelayedUnaryIsometricLessThanScalar(InputValue_ scalar)
Definition compare_helpers.hpp:267
DelayedUnaryIsometricCompareVector< CompareOperation::NOT_EQUAL, InputValue_, Vector_ > make_DelayedUnaryIsometricNotEqualVector(Vector_ vector, bool by_row)
Definition compare_helpers.hpp:378
DelayedUnaryIsometricCompareVector< CompareOperation::LESS_THAN, InputValue_, Vector_ > make_DelayedUnaryIsometricLessThanVector(Vector_ vector, bool by_row)
Definition compare_helpers.hpp:339
DelayedUnaryIsometricSpecialCompare< SpecialCompareOperation::ISINF, pass_, InputValue_ > make_DelayedUnaryIsometricIsinf()
Definition compare_helpers.hpp:503
DelayedUnaryIsometricSpecialCompare< SpecialCompareOperation::ISFINITE, pass_, InputValue_ > make_DelayedUnaryIsometricIsfinite()
Definition compare_helpers.hpp:514
DelayedUnaryIsometricCompareScalar< CompareOperation::NOT_EQUAL, InputValue_ > make_DelayedUnaryIsometricNotEqualScalar(InputValue_ scalar)
Definition compare_helpers.hpp:300
DelayedUnaryIsometricSpecialCompare< SpecialCompareOperation::ISNAN, pass_, InputValue_ > make_DelayedUnaryIsometricIsnan()
Definition compare_helpers.hpp:492
DelayedUnaryIsometricCompareVector< CompareOperation::EQUAL, InputValue_, Vector_ > make_DelayedUnaryIsometricEqualVector(Vector_ vector, bool by_row)
Definition compare_helpers.hpp:313
DelayedUnaryIsometricCompareScalar< CompareOperation::GREATER_THAN_OR_EQUAL, InputValue_ > make_DelayedUnaryIsometricGreaterThanOrEqualScalar(InputValue_ scalar)
Definition compare_helpers.hpp:278
DelayedUnaryIsometricCompareScalar< CompareOperation::GREATER_THAN, InputValue_ > make_DelayedUnaryIsometricGreaterThanScalar(InputValue_ scalar)
Definition compare_helpers.hpp:256
DelayedUnaryIsometricCompareScalar< CompareOperation::EQUAL, InputValue_ > make_DelayedUnaryIsometricEqualScalar(InputValue_ scalar)
Definition compare_helpers.hpp:245
DelayedUnaryIsometricCompareVector< CompareOperation::LESS_THAN_OR_EQUAL, InputValue_, Vector_ > make_DelayedUnaryIsometricLessThanOrEqualVector(Vector_ vector, bool by_row)
Definition compare_helpers.hpp:365
DelayedUnaryIsometricCompareScalar< CompareOperation::LESS_THAN_OR_EQUAL, InputValue_ > make_DelayedUnaryIsometricLessThanOrEqualScalar(InputValue_ scalar)
Definition compare_helpers.hpp:289
DelayedUnaryIsometricCompareVector< CompareOperation::GREATER_THAN_OR_EQUAL, InputValue_, Vector_ > make_DelayedUnaryIsometricGreaterThanOrEqualVector(Vector_ vector, bool by_row)
Definition compare_helpers.hpp:352
auto consecutive_extractor(const Matrix< Value_, Index_ > *mat, bool row, Index_ iter_start, Index_ iter_length, Args_ &&... args)
Definition consecutive_extractor.hpp:35
DelayedUnaryIsometricCompareVector< CompareOperation::GREATER_THAN, InputValue_, Vector_ > make_DelayedUnaryIsometricGreaterThanVector(Vector_ vector, bool by_row)
Definition compare_helpers.hpp:326