1#ifndef TATAMI_ISOMETRIC_UNARY_BOOLEAN_HELPERS_H
2#define TATAMI_ISOMETRIC_UNARY_BOOLEAN_HELPERS_H
19template<
typename InputValue_,
typename Index_,
typename OutputValue_>
20void delayed_boolean_cast(
const InputValue_* input, Index_ length, OutputValue_* output) {
21 for (Index_ i = 0; i < length; ++i) {
22 if constexpr(std::is_same<InputValue_, OutputValue_>::value) {
23 auto& val = output[i];
24 val =
static_cast<bool>(val);
26 output[i] =
static_cast<bool>(input[i]);
31template<
typename InputValue_,
typename Index_,
typename OutputValue_>
32void delayed_boolean_not(
const InputValue_* input, Index_ length, OutputValue_* output) {
33 for (Index_ i = 0; i < length; ++i) {
34 if constexpr(std::is_same<InputValue_, OutputValue_>::value) {
35 auto& val = output[i];
36 val = !
static_cast<bool>(val);
38 output[i] = !
static_cast<bool>(input[i]);
43template<BooleanOperation op_,
typename InputValue_,
typename Index_,
typename OutputValue_>
44void delayed_boolean_run_simple(
const InputValue_* input, Index_ length,
bool scalar, OutputValue_* output) {
45 if constexpr(op_ == BooleanOperation::AND) {
47 delayed_boolean_cast(input, length, output);
49 std::fill_n(output, length, 0);
51 }
else if constexpr(op_ == BooleanOperation::OR) {
53 std::fill_n(output, length, 1);
55 delayed_boolean_cast(input, length, output);
57 }
else if constexpr(op_ == BooleanOperation::XOR) {
59 delayed_boolean_not(input, length, output);
61 delayed_boolean_cast(input, length, output);
65 delayed_boolean_cast(input, length, output);
67 delayed_boolean_not(input, length, output);
72template<BooleanOperation op_>
73bool delayed_boolean_actual_sparse(
bool scalar) {
74 return delayed_boolean<op_>(0, scalar) ==
static_cast<bool>(0);
90template<BooleanOperation op_>
97 my_sparse = delayed_boolean_actual_sparse<op_>(my_scalar);
108 static constexpr bool is_basic =
false;
110 bool is_sparse()
const {
121 template<
typename Index_,
typename InputValue_,
typename OutputValue_>
122 void dense(
bool, Index_, Index_, Index_ length,
const InputValue_* input, OutputValue_* output)
const {
123 delayed_boolean_run_simple<op_>(input, length, my_scalar, output);
126 template<
typename Index_,
typename InputValue_,
typename OutputValue_>
127 void dense(
bool, Index_,
const std::vector<Index_>& indices,
const InputValue_* input, OutputValue_* output)
const {
128 delayed_boolean_run_simple<op_>(input,
static_cast<Index_
>(indices.size()), my_scalar, output);
131 template<
typename Index_,
typename InputValue_,
typename OutputValue_>
132 void sparse(
bool, Index_, Index_ number,
const InputValue_* input_value,
const Index_*, OutputValue_* output_value)
const {
133 delayed_boolean_run_simple<op_>(input_value, number, my_scalar, output_value);
136 template<
typename OutputValue_,
typename InputValue_,
typename Index_>
137 OutputValue_ fill(
bool, Index_)
const {
140 return delayed_boolean<op_>(0, my_scalar);
159 static constexpr bool is_basic =
false;
161 bool is_sparse()
const {
174 template<
typename Index_,
typename InputValue_,
typename OutputValue_>
175 void dense(
bool, Index_, Index_, Index_ length,
const InputValue_* input, OutputValue_* output)
const {
176 delayed_boolean_not(input, length, output);
179 template<
typename Index_,
typename InputValue_,
typename OutputValue_>
180 void dense(
bool, Index_,
const std::vector<Index_>& indices,
const InputValue_* input, OutputValue_* output)
const {
181 delayed_boolean_not(input,
static_cast<Index_
>(indices.size()), output);
184 template<
typename Index_,
typename InputValue_,
typename OutputValue_>
185 void sparse(
bool, Index_, Index_ number,
const InputValue_* input_value,
const Index_*, OutputValue_* output_value)
const {
186 delayed_boolean_not(input_value, number, output_value);
189 template<
typename OutputValue_,
typename InputValue_,
typename Index_>
190 OutputValue_ fill(
bool, Index_)
const {
210 static constexpr bool is_basic =
false;
212 bool is_sparse()
const {
223 template<
typename Index_,
typename InputValue_,
typename OutputValue_>
224 void dense(
bool, Index_, Index_, Index_ length,
const InputValue_* input, OutputValue_* output)
const {
225 delayed_boolean_cast(input, length, output);
228 template<
typename Index_,
typename InputValue_,
typename OutputValue_>
229 void dense(
bool, Index_,
const std::vector<Index_>& indices,
const InputValue_* input, OutputValue_* output)
const {
230 delayed_boolean_cast(input,
static_cast<Index_
>(indices.size()), output);
233 template<
typename Index_,
typename InputValue_,
typename OutputValue_>
234 void sparse(
bool, Index_, Index_ number,
const InputValue_* input_value,
const Index_*, OutputValue_* output_value)
const {
235 delayed_boolean_cast(input_value, number, output_value);
238 template<
typename OutputValue_,
typename InputValue_,
typename Index_>
239 OutputValue_ fill(
bool, Index_)
const {
257template<BooleanOperation op_,
typename Vector_>
268 for (
auto x : my_vector) {
269 if (!delayed_boolean_actual_sparse<op_>(x)) {
279 bool my_sparse =
true;
285 static constexpr bool is_basic =
false;
287 bool zero_depends_on_row()
const {
291 bool zero_depends_on_column()
const {
295 bool non_zero_depends_on_row()
const {
299 bool non_zero_depends_on_column()
const {
303 bool is_sparse()
const {
314 template<
typename Index_,
typename InputValue_,
typename OutputValue_>
315 void dense(
bool row, Index_ idx, Index_ start, Index_ length,
const InputValue_* input, OutputValue_* output)
const {
316 if (row == my_by_row) {
317 delayed_boolean_run_simple<op_>(input, length, my_vector[idx], output);
319 for (Index_ i = 0; i < length; ++i) {
320 if constexpr(std::is_same<InputValue_, OutputValue_>::value) {
321 auto& val = output[i];
322 val = delayed_boolean<op_>(val, my_vector[i + start]);
324 output[i] = delayed_boolean<op_>(input[i], my_vector[i + start]);
330 template<
typename Index_,
typename InputValue_,
typename OutputValue_>
331 void dense(
bool row, Index_ idx,
const std::vector<Index_>& indices,
const InputValue_* input, OutputValue_* output)
const {
332 if (row == my_by_row) {
333 delayed_boolean_run_simple<op_>(input,
static_cast<Index_
>(indices.size()), my_vector[idx], output);
335 Index_ length = indices.size();
336 for (Index_ i = 0; i < length; ++i) {
337 if constexpr(std::is_same<InputValue_, OutputValue_>::value) {
338 auto& val = output[i];
339 val = delayed_boolean<op_>(val, my_vector[indices[i]]);
341 output[i] = delayed_boolean<op_>(input[i], my_vector[indices[i]]);
347 template<
typename Index_,
typename InputValue_,
typename OutputValue_>
348 void sparse(
bool row, Index_ idx, Index_ number,
const InputValue_* input_value,
const Index_* index, OutputValue_* output_value)
const {
349 if (row == my_by_row) {
350 delayed_boolean_run_simple<op_>(input_value, number, my_vector[idx], output_value);
352 for (Index_ i = 0; i < number; ++i) {
353 if constexpr(std::is_same<InputValue_, OutputValue_>::value) {
354 auto& val = output_value[i];
355 val = delayed_boolean<op_>(val, my_vector[index[i]]);
357 output_value[i] = delayed_boolean<op_>(input_value[i], my_vector[index[i]]);
363 template<
typename OutputValue_,
typename InputValue_,
typename Index_>
364 OutputValue_ fill(
bool row, Index_ idx)
const {
365 if (row == my_by_row) {
366 return delayed_boolean<op_>(0, my_vector[idx]);
429template<
typename Vector_>
441template<
typename Vector_>
453template<
typename Vector_>
465template<
typename Vector_>
Utilities for delayed boolean operations.
Delayed unary isometric boolean cast.
Definition boolean_helpers.hpp:205
Delayed unary isometric boolean NOT operation.
Definition boolean_helpers.hpp:154
Delayed unary isometric scalar boolean operation.
Definition boolean_helpers.hpp:91
DelayedUnaryIsometricBooleanScalar(bool scalar)
Definition boolean_helpers.hpp:96
Delayed unary isometric vector boolean operations.
Definition boolean_helpers.hpp:258
DelayedUnaryIsometricBooleanVector(Vector_ vector, bool by_row)
Definition boolean_helpers.hpp:267
Flexible representations for matrix data.
Definition Extractor.hpp:15
DelayedUnaryIsometricBooleanScalar< BooleanOperation::AND > make_DelayedUnaryIsometricBooleanAndScalar(bool scalar)
Definition boolean_helpers.hpp:391
DelayedUnaryIsometricBooleanVector< BooleanOperation::OR, Vector_ > make_DelayedUnaryIsometricBooleanOrVector(Vector_ vector, bool by_row)
Definition boolean_helpers.hpp:442
DelayedUnaryIsometricBooleanScalar< BooleanOperation::OR > make_DelayedUnaryIsometricBooleanOrScalar(bool scalar)
Definition boolean_helpers.hpp:400
DelayedUnaryIsometricBooleanVector< BooleanOperation::EQUAL, Vector_ > make_DelayedUnaryIsometricBooleanEqualVector(Vector_ vector, bool by_row)
Definition boolean_helpers.hpp:466
DelayedUnaryIsometricBooleanVector< BooleanOperation::XOR, Vector_ > make_DelayedUnaryIsometricBooleanXorVector(Vector_ vector, bool by_row)
Definition boolean_helpers.hpp:454
DelayedUnaryIsometricBooleanNot make_DelayedUnaryIsometricBooleanNot()
Definition boolean_helpers.hpp:382
DelayedUnaryIsometricBooleanScalar< BooleanOperation::EQUAL > make_DelayedUnaryIsometricBooleanEqualScalar(bool scalar)
Definition boolean_helpers.hpp:418
DelayedUnaryIsometricBooleanScalar< BooleanOperation::XOR > make_DelayedUnaryIsometricBooleanXorScalar(bool scalar)
Definition boolean_helpers.hpp:409
DelayedUnaryIsometricBooleanVector< BooleanOperation::AND, Vector_ > make_DelayedUnaryIsometricBooleanAndVector(Vector_ vector, bool by_row)
Definition boolean_helpers.hpp:430