1#ifndef TATAMI_ISOMETRIC_UNARY_COMPARE_HELPERS_H
2#define TATAMI_ISOMETRIC_UNARY_COMPARE_HELPERS_H
20template<CompareOperation op_,
typename InputValue_,
typename Index_,
typename Scalar_,
typename OutputValue_>
21void delayed_compare_run_simple(
const InputValue_* input, Index_ length, Scalar_ scalar, OutputValue_* output) {
22 if constexpr(std::is_same<InputValue_, OutputValue_>::value) {
25 for (Index_ i = 0; i < length; ++i) {
26 output[i] = delayed_compare<op_>(input[i], scalar);
30template<CompareOperation op_,
typename InputValue_,
typename Scalar_>
31bool delayed_compare_actual_sparse(Scalar_ scalar) {
32 return !delayed_compare<op_, InputValue_>(0, scalar);
50template<CompareOperation op_,
typename OutputValue_,
typename InputValue_,
typename Index_,
typename Scalar_>
58 my_sparse = delayed_compare_actual_sparse<op_, InputValue_>(my_scalar);
66 std::optional<Index_>
nrow()
const {
70 std::optional<Index_>
ncol()
const {
92 void dense(
bool, Index_, Index_, Index_ length,
const InputValue_* input, OutputValue_* output)
const {
93 delayed_compare_run_simple<op_>(input, length, my_scalar, output);
96 void dense(
bool, Index_,
const std::vector<Index_>& indices,
const InputValue_* input, OutputValue_* output)
const {
97 delayed_compare_run_simple<op_>(input,
static_cast<Index_
>(indices.size()), my_scalar, output);
105 void sparse(
bool, Index_, Index_ number,
const InputValue_* input_value,
const Index_*, OutputValue_* output_value)
const {
106 delayed_compare_run_simple<op_>(input_value, number, my_scalar, output_value);
109 OutputValue_
fill(
bool, Index_)
const {
110 return delayed_compare<op_, InputValue_>(0, my_scalar);
122template<
typename OutputValue_,
typename InputValue_,
typename Index_,
typename Scalar_>
133template<
typename OutputValue_,
typename InputValue_,
typename Index_,
typename Scalar_>
144template<
typename OutputValue_,
typename InputValue_,
typename Index_,
typename Scalar_>
155template<
typename OutputValue_,
typename InputValue_,
typename Index_,
typename Scalar_>
166template<
typename OutputValue_,
typename InputValue_,
typename Index_,
typename Scalar_>
177template<
typename OutputValue_,
typename InputValue_,
typename Index_,
typename Scalar_>
184template<
typename OutputValue_ =
double,
typename InputValue_ =
double,
typename Index_ =
int,
typename Scalar_>
185std::shared_ptr<DelayedUnaryIsometricOperationHelper<OutputValue_, InputValue_, Index_> > make_DelayedUnaryIsometricEqualScalar(Scalar_ scalar) {
186 return std::make_shared<DelayedUnaryIsometricEqualScalarHelper<OutputValue_, InputValue_, Index_, Scalar_> >(std::move(scalar));
189template<
typename OutputValue_ =
double,
typename InputValue_ =
double,
typename Index_ =
int,
typename Scalar_>
190std::shared_ptr<DelayedUnaryIsometricOperationHelper<OutputValue_, InputValue_, Index_> > make_DelayedUnaryIsometricGreaterThanScalar(Scalar_ scalar) {
191 return std::make_shared<DelayedUnaryIsometricGreaterThanScalarHelper<OutputValue_, InputValue_, Index_, Scalar_> >(std::move(scalar));
194template<
typename OutputValue_ =
double,
typename InputValue_ =
double,
typename Index_ =
int,
typename Scalar_>
195std::shared_ptr<DelayedUnaryIsometricOperationHelper<OutputValue_, InputValue_, Index_> > make_DelayedUnaryIsometricLessThanScalar(Scalar_ scalar) {
196 return std::make_shared<DelayedUnaryIsometricLessThanScalarHelper<OutputValue_, InputValue_, Index_, Scalar_> >(std::move(scalar));
199template<
typename OutputValue_ =
double,
typename InputValue_ =
double,
typename Index_ =
int,
typename Scalar_>
200std::shared_ptr<DelayedUnaryIsometricOperationHelper<OutputValue_, InputValue_, Index_> > make_DelayedUnaryIsometricGreaterThanOrEqualScalar(Scalar_ scalar) {
201 return std::make_shared<DelayedUnaryIsometricGreaterThanOrEqualScalarHelper<OutputValue_, InputValue_, Index_, Scalar_> >(std::move(scalar));
204template<
typename OutputValue_ =
double,
typename InputValue_ =
double,
typename Index_ =
int,
typename Scalar_>
205std::shared_ptr<DelayedUnaryIsometricOperationHelper<OutputValue_, InputValue_, Index_> > make_DelayedUnaryIsometricLessThanOrEqualScalar(Scalar_ scalar) {
206 return std::make_shared<DelayedUnaryIsometricLessThanOrEqualScalarHelper<OutputValue_, InputValue_, Index_, Scalar_> >(std::move(scalar));
209template<
typename OutputValue_ =
double,
typename InputValue_ =
double,
typename Index_ =
int,
typename Scalar_>
210std::shared_ptr<DelayedUnaryIsometricOperationHelper<OutputValue_, InputValue_, Index_> > make_DelayedUnaryIsometricNotEqualScalar(Scalar_ scalar) {
211 return std::make_shared<DelayedUnaryIsometricNotEqualScalarHelper<OutputValue_, InputValue_, Index_, Scalar_> >(std::move(scalar));
229template<CompareOperation op_,
typename OutputValue_,
typename InputValue_,
typename Index_,
typename Vector_>
241 my_vector(std::move(vector)),
244 for (
auto x : my_vector) {
245 if (!delayed_compare_actual_sparse<op_, InputValue_>(x)) {
255 bool my_sparse =
true;
258 std::optional<Index_>
nrow()
const {
260 return my_vector.size();
266 std::optional<Index_>
ncol()
const {
270 return my_vector.size();
292 void dense(
bool row, Index_ idx, Index_ start, Index_ length,
const InputValue_* input, OutputValue_* output)
const {
293 if (row == my_by_row) {
294 delayed_compare_run_simple<op_, InputValue_>(input, length, my_vector[idx], output);
296 if constexpr(std::is_same<InputValue_, OutputValue_>::value) {
299 for (Index_ i = 0; i < length; ++i) {
300 output[i] = delayed_compare<op_, InputValue_>(input[i], my_vector[i + start]);
305 void dense(
bool row, Index_ idx,
const std::vector<Index_>& indices,
const InputValue_* input, OutputValue_* output)
const {
306 if (row == my_by_row) {
307 delayed_compare_run_simple<op_, InputValue_>(input,
static_cast<Index_
>(indices.size()), my_vector[idx], output);
309 if constexpr(std::is_same<InputValue_, OutputValue_>::value) {
312 Index_ length = indices.size();
313 for (Index_ i = 0; i < length; ++i) {
314 output[i] = delayed_compare<op_, InputValue_>(input[i], my_vector[indices[i]]);
324 void sparse(
bool row, Index_ idx, Index_ number,
const InputValue_* input_value,
const Index_* indices, OutputValue_* output_value)
const {
325 if (row == my_by_row) {
326 delayed_compare_run_simple<op_, InputValue_>(input_value, number, my_vector[idx], output_value);
328 if constexpr(std::is_same<InputValue_, OutputValue_>::value) {
329 input_value = output_value;
331 for (Index_ i = 0; i < number; ++i) {
332 output_value[i] = delayed_compare<op_, InputValue_>(input_value[i], my_vector[indices[i]]);
337 OutputValue_
fill(
bool row, Index_ idx)
const {
338 if (row == my_by_row) {
339 return delayed_compare<op_, InputValue_>(0, my_vector[idx]);
356template<
typename OutputValue_,
typename InputValue_,
typename Index_,
typename Vector_>
367template<
typename OutputValue_,
typename InputValue_,
typename Index_,
typename Vector_>
378template<
typename OutputValue_,
typename InputValue_,
typename Index_,
typename Vector_>
389template<
typename OutputValue_,
typename InputValue_,
typename Index_,
typename Vector_>
400template<
typename OutputValue_,
typename InputValue_,
typename Index_,
typename Vector_>
411template<
typename OutputValue_,
typename InputValue_,
typename Index_,
typename Vector_>
418template<
typename OutputValue_ =
double,
typename InputValue_ =
double,
typename Index_ =
int,
typename Vector_>
419std::shared_ptr<DelayedUnaryIsometricOperationHelper<OutputValue_, InputValue_, Index_> > make_DelayedUnaryIsometricEqualVector(Vector_ vector,
bool by_row) {
420 return std::make_shared<DelayedUnaryIsometricEqualVectorHelper<OutputValue_, InputValue_, Index_, Vector_> >(std::move(vector), by_row);
423template<
typename OutputValue_ =
double,
typename InputValue_ =
double,
typename Index_ =
int,
typename Vector_>
424std::shared_ptr<DelayedUnaryIsometricOperationHelper<OutputValue_, InputValue_, Index_> > make_DelayedUnaryIsometricGreaterThanVector(Vector_ vector,
bool by_row) {
425 return std::make_shared<DelayedUnaryIsometricGreaterThanVectorHelper<OutputValue_, InputValue_, Index_, Vector_> >(std::move(vector), by_row);
428template<
typename OutputValue_ =
double,
typename InputValue_ =
double,
typename Index_ =
int,
typename Vector_>
429std::shared_ptr<DelayedUnaryIsometricOperationHelper<OutputValue_, InputValue_, Index_> > make_DelayedUnaryIsometricLessThanVector(Vector_ vector,
bool by_row) {
430 return std::make_shared<DelayedUnaryIsometricLessThanVectorHelper<OutputValue_, InputValue_, Index_, Vector_> >(std::move(vector), by_row);
433template<
typename OutputValue_ =
double,
typename InputValue_ =
double,
typename Index_ =
int,
typename Vector_>
434std::shared_ptr<DelayedUnaryIsometricOperationHelper<OutputValue_, InputValue_, Index_> > make_DelayedUnaryIsometricGreaterThanOrEqualVector(Vector_ vector,
bool by_row) {
435 return std::make_shared<DelayedUnaryIsometricGreaterThanOrEqualVectorHelper<OutputValue_, InputValue_, Index_, Vector_> >(std::move(vector), by_row);
438template<
typename OutputValue_ =
double,
typename InputValue_ =
double,
typename Index_ =
int,
typename Vector_>
439std::shared_ptr<DelayedUnaryIsometricOperationHelper<OutputValue_, InputValue_, Index_> > make_DelayedUnaryIsometricLessThanOrEqualVector(Vector_ vector,
bool by_row) {
440 return std::make_shared<DelayedUnaryIsometricLessThanOrEqualVectorHelper<OutputValue_, InputValue_, Index_, Vector_> >(std::move(vector), by_row);
443template<
typename OutputValue_ =
double,
typename InputValue_ =
double,
typename Index_ =
int,
typename Vector_>
444std::shared_ptr<DelayedUnaryIsometricOperationHelper<OutputValue_, InputValue_, Index_> > make_DelayedUnaryIsometricNotEqualVector(Vector_ vector,
bool by_row) {
445 return std::make_shared<DelayedUnaryIsometricNotEqualVectorHelper<OutputValue_, InputValue_, Index_, Vector_> >(std::move(vector), by_row);
454template<SpecialCompareOperation op_,
bool pass_,
typename InputValue_,
typename Index_,
typename OutputValue_>
455void delayed_special_compare_run_simple(
const InputValue_* input, Index_ length, OutputValue_* output) {
456 for (Index_ i = 0; i < length; ++i) {
457 output[i] = delayed_special_compare<op_, pass_, InputValue_>(input[i]);
461template<SpecialCompareOperation op_,
bool pass_,
typename InputValue_>
462bool delayed_special_compare_actual_sparse() {
463 return !delayed_special_compare<op_, pass_, InputValue_>(0);
481template<SpecialCompareOperation op_,
bool pass_,
typename OutputValue_,
typename InputValue_,
typename Index_>
488 my_sparse = !delayed_special_compare<op_, pass_, InputValue_>(0);
495 std::optional<Index_>
nrow()
const {
499 std::optional<Index_>
ncol()
const {
521 void dense(
bool, Index_, Index_, Index_ length,
const InputValue_* input, OutputValue_* output)
const {
522 delayed_special_compare_run_simple<op_, pass_>(input, length, output);
525 void dense(
bool, Index_,
const std::vector<Index_>& indices,
const InputValue_* input, OutputValue_* output)
const {
526 delayed_special_compare_run_simple<op_, pass_>(input,
static_cast<Index_
>(indices.size()), output);
534 void sparse(
bool, Index_, Index_ number,
const InputValue_* input_value,
const Index_*, OutputValue_* output_value)
const {
535 delayed_special_compare_run_simple<op_, pass_>(input_value, number, output_value);
538 OutputValue_
fill(
bool, Index_)
const {
551template<
bool pass_,
typename OutputValue_,
typename InputValue_,
typename Index_>
562template<
bool pass_,
typename OutputValue_,
typename InputValue_,
typename Index_>
573template<
bool pass_,
typename OutputValue_,
typename InputValue_,
typename Index_>
580template<
bool pass_ = true,
typename OutputValue_ =
double,
typename InputValue_ =
double,
typename Index_ =
int>
581std::shared_ptr<DelayedUnaryIsometricOperationHelper<OutputValue_, InputValue_, Index_> > make_DelayedUnaryIsometricIsnan() {
582 return std::make_shared<DelayedUnaryIsometricIsnanHelper<pass_, OutputValue_, InputValue_, Index_> >();
585template<
bool pass_ = true,
typename OutputValue_ =
double,
typename InputValue_ =
double,
typename Index_ =
int>
586std::shared_ptr<DelayedUnaryIsometricOperationHelper<OutputValue_, InputValue_, Index_> > make_DelayedUnaryIsometricIsinf() {
587 return std::make_shared<DelayedUnaryIsometricIsinfHelper<pass_, OutputValue_, InputValue_, Index_> >();
590template<
bool pass_ = true,
typename OutputValue_ =
double,
typename InputValue_ =
double,
typename Index_ =
int>
591std::shared_ptr<DelayedUnaryIsometricOperationHelper<OutputValue_, InputValue_, Index_> > make_DelayedUnaryIsometricIsfinite() {
592 return std::make_shared<DelayedUnaryIsometricIsfiniteHelper<pass_, OutputValue_, InputValue_, Index_> >();
Helper for delayed scalar comparisons.
Definition compare_helpers.hpp:51
bool zero_depends_on_row() const
Definition compare_helpers.hpp:75
void dense(bool, Index_, Index_, Index_ length, const InputValue_ *input, OutputValue_ *output) const
Definition compare_helpers.hpp:92
void sparse(bool, Index_, Index_ number, const InputValue_ *input_value, const Index_ *, OutputValue_ *output_value) const
Definition compare_helpers.hpp:105
DelayedUnaryIsometricCompareScalarHelper(Scalar_ scalar)
Definition compare_helpers.hpp:57
std::optional< Index_ > ncol() const
Definition compare_helpers.hpp:70
bool zero_depends_on_column() const
Definition compare_helpers.hpp:79
void dense(bool, Index_, const std::vector< Index_ > &indices, const InputValue_ *input, OutputValue_ *output) const
Definition compare_helpers.hpp:96
bool is_sparse() const
Definition compare_helpers.hpp:101
bool non_zero_depends_on_row() const
Definition compare_helpers.hpp:83
std::optional< Index_ > nrow() const
Definition compare_helpers.hpp:66
OutputValue_ fill(bool, Index_) const
Definition compare_helpers.hpp:109
bool non_zero_depends_on_column() const
Definition compare_helpers.hpp:87
Helper for delayed vector comparisons.
Definition compare_helpers.hpp:230
bool zero_depends_on_column() const
Definition compare_helpers.hpp:279
bool is_sparse() const
Definition compare_helpers.hpp:320
std::optional< Index_ > nrow() const
Definition compare_helpers.hpp:258
void sparse(bool row, Index_ idx, Index_ number, const InputValue_ *input_value, const Index_ *indices, OutputValue_ *output_value) const
Definition compare_helpers.hpp:324
bool non_zero_depends_on_column() const
Definition compare_helpers.hpp:287
bool zero_depends_on_row() const
Definition compare_helpers.hpp:275
void dense(bool row, Index_ idx, Index_ start, Index_ length, const InputValue_ *input, OutputValue_ *output) const
Definition compare_helpers.hpp:292
void dense(bool row, Index_ idx, const std::vector< Index_ > &indices, const InputValue_ *input, OutputValue_ *output) const
Definition compare_helpers.hpp:305
OutputValue_ fill(bool row, Index_ idx) const
Definition compare_helpers.hpp:337
bool non_zero_depends_on_row() const
Definition compare_helpers.hpp:283
std::optional< Index_ > ncol() const
Definition compare_helpers.hpp:266
DelayedUnaryIsometricCompareVectorHelper(Vector_ vector, bool by_row)
Definition compare_helpers.hpp:240
Helper operation interface for DelayedUnaryIsometricOperation.
Definition helper_interface.hpp:27
Delayed special value comparison.
Definition compare_helpers.hpp:482
std::optional< Index_ > ncol() const
Definition compare_helpers.hpp:499
bool non_zero_depends_on_column() const
Definition compare_helpers.hpp:516
bool is_sparse() const
Definition compare_helpers.hpp:530
void dense(bool, Index_, const std::vector< Index_ > &indices, const InputValue_ *input, OutputValue_ *output) const
Definition compare_helpers.hpp:525
bool zero_depends_on_row() const
Definition compare_helpers.hpp:504
bool zero_depends_on_column() const
Definition compare_helpers.hpp:508
bool non_zero_depends_on_row() const
Definition compare_helpers.hpp:512
void dense(bool, Index_, Index_, Index_ length, const InputValue_ *input, OutputValue_ *output) const
Definition compare_helpers.hpp:521
DelayedUnaryIsometricSpecialCompareHelper()
Definition compare_helpers.hpp:487
void sparse(bool, Index_, Index_ number, const InputValue_ *input_value, const Index_ *, OutputValue_ *output_value) const
Definition compare_helpers.hpp:534
OutputValue_ fill(bool, Index_) const
Definition compare_helpers.hpp:538
std::optional< Index_ > nrow() const
Definition compare_helpers.hpp:495
Utilities for delayed comparison operations.
Flexible representations for matrix data.
Definition Extractor.hpp:15
Interface for tatami::DelayedUnaryIsometricOperation helpers.