1#ifndef TATAMI_ISOMETRIC_BINARY_ARITHMETIC_HELPERS_H
2#define TATAMI_ISOMETRIC_BINARY_ARITHMETIC_HELPERS_H
29template<ArithmeticOperation op_,
typename OutputValue_,
typename InputValue_,
typename Index_>
38 void dense(
bool, Index_, Index_, Index_ length,
const InputValue_* left_buffer,
const InputValue_* right_buffer, OutputValue_* output_buffer)
const {
39 for (Index_ i = 0; i < length; ++i) {
40 if constexpr(std::is_same<InputValue_, OutputValue_>::value) {
41 auto& val = output_buffer[i];
42 val = delayed_arithmetic<op_, true>(val, right_buffer[i]);
44 output_buffer[i] = delayed_arithmetic<op_, true>(left_buffer[i], right_buffer[i]);
49 void dense(
bool, Index_,
const std::vector<Index_>& indices,
const InputValue_* left_buffer,
const InputValue_* right_buffer, OutputValue_* output_buffer)
const {
50 Index_ length = indices.size();
51 for (Index_ i = 0; i < length; ++i) {
52 if constexpr(std::is_same<InputValue_, OutputValue_>::value) {
53 auto& val = output_buffer[i];
54 val = delayed_arithmetic<op_, true>(val, right_buffer[i]);
56 output_buffer[i] = delayed_arithmetic<op_, true>(left_buffer[i], right_buffer[i]);
66 OutputValue_* value_buffer,
75 constexpr bool must_have_both = (op_ == ArithmeticOperation::MULTIPLY &&
76 !std::numeric_limits<InputValue_>::has_quiet_NaN &&
77 !std::numeric_limits<InputValue_>::has_infinity);
79 return delayed_binary_isometric_sparse_operation<must_have_both>(
86 [](InputValue_ l, InputValue_ r) ->
auto {
87 return delayed_arithmetic<op_, true>(l, r);
93 OutputValue_
fill(
bool, Index_)
const {
94 if constexpr(has_unsafe_divide_by_zero<op_, true, InputValue_, InputValue_>()) {
95 throw std::runtime_error(
"division by zero is not supported");
98 return delayed_arithmetic<op_, true, InputValue_, InputValue_>(0, 0);
104 op_ == ArithmeticOperation::ADD ||
105 op_ == ArithmeticOperation::SUBTRACT ||
106 op_ == ArithmeticOperation::MULTIPLY
111 std::optional<Index_>
nrow()
const {
115 std::optional<Index_>
ncol()
const {
127template<
typename OutputValue_ =
double,
typename InputValue_ =
double,
typename Index_ =
int>
137template<
typename OutputValue_ =
double,
typename InputValue_ =
double,
typename Index_ =
int>
147template<
typename OutputValue_ =
double,
typename InputValue_ =
double,
typename Index_ =
int>
157template<
typename OutputValue_ =
double,
typename InputValue_ =
double,
typename Index_ =
int>
167template<
typename OutputValue_ =
double,
typename InputValue_ =
double,
typename Index_ =
int>
177template<
typename OutputValue_ =
double,
typename InputValue_ =
double,
typename Index_ =
int>
187template<
typename OutputValue_ =
double,
typename InputValue_ =
double,
typename Index_ =
int>
194template<
typename OutputValue_ =
double,
typename InputValue_ =
double,
typename Index_ =
int>
195std::shared_ptr<DelayedBinaryIsometricOperationHelper<OutputValue_, InputValue_, Index_> > make_DelayedBinaryIsometricAdd() {
196 return std::make_shared<DelayedBinaryIsometricAddHelper<OutputValue_, InputValue_, Index_> >();
199template<
typename OutputValue_ =
double,
typename InputValue_ =
double,
typename Index_ =
int>
200std::shared_ptr<DelayedBinaryIsometricOperationHelper<OutputValue_, InputValue_, Index_> > make_DelayedBinaryIsometricSubtract() {
201 return std::make_shared<DelayedBinaryIsometricSubtractHelper<OutputValue_, InputValue_, Index_> >();
204template<
typename OutputValue_ =
double,
typename InputValue_ =
double,
typename Index_ =
int>
205std::shared_ptr<DelayedBinaryIsometricOperationHelper<OutputValue_, InputValue_, Index_> > make_DelayedBinaryIsometricMultiply() {
206 return std::make_shared<DelayedBinaryIsometricMultiplyHelper<OutputValue_, InputValue_, Index_> >();
209template<
typename OutputValue_ =
double,
typename InputValue_ =
double,
typename Index_ =
int>
210std::shared_ptr<DelayedBinaryIsometricOperationHelper<OutputValue_, InputValue_, Index_> > make_DelayedBinaryIsometricDivide() {
211 return std::make_shared<DelayedBinaryIsometricDivideHelper<OutputValue_, InputValue_, Index_> >();
214template<
typename OutputValue_ =
double,
typename InputValue_ =
double,
typename Index_ =
int>
215std::shared_ptr<DelayedBinaryIsometricOperationHelper<OutputValue_, InputValue_, Index_> > make_DelayedBinaryIsometricPower() {
216 return std::make_shared<DelayedBinaryIsometricPowerHelper<OutputValue_, InputValue_, Index_> >();
219template<
typename OutputValue_ =
double,
typename InputValue_ =
double,
typename Index_ =
int>
220std::shared_ptr<DelayedBinaryIsometricOperationHelper<OutputValue_, InputValue_, Index_> > make_DelayedBinaryIsometricModulo() {
221 return std::make_shared<DelayedBinaryIsometricModuloHelper<OutputValue_, InputValue_, Index_> >();
224template<
typename OutputValue_ =
double,
typename InputValue_ =
double,
typename Index_ =
int>
225std::shared_ptr<DelayedBinaryIsometricOperationHelper<OutputValue_, InputValue_, Index_> > make_DelayedBinaryIsometricIntegerDivide() {
226 return std::make_shared<DelayedBinaryIsometricIntegerDivideHelper<OutputValue_, InputValue_, Index_> >();
Utilities for delayed arithmetic operations.
Interface for tatami::DelayedBinaryIsometricOperation helpers.
Helper for delayed binary isometric arithmetic.
Definition arithmetic_helpers.hpp:30
bool zero_depends_on_column() const
Definition arithmetic_helpers.hpp:33
std::optional< Index_ > nrow() const
Definition arithmetic_helpers.hpp:111
bool zero_depends_on_row() const
Definition arithmetic_helpers.hpp:32
bool non_zero_depends_on_row() const
Definition arithmetic_helpers.hpp:34
Index_ sparse(bool, Index_, const SparseRange< InputValue_, Index_ > &left, const SparseRange< InputValue_, Index_ > &right, OutputValue_ *value_buffer, Index_ *index_buffer, bool needs_value, bool needs_index) const
Definition arithmetic_helpers.hpp:61
OutputValue_ fill(bool, Index_) const
Definition arithmetic_helpers.hpp:93
bool is_sparse() const
Definition arithmetic_helpers.hpp:102
bool non_zero_depends_on_column() const
Definition arithmetic_helpers.hpp:35
void dense(bool, Index_, Index_, Index_ length, const InputValue_ *left_buffer, const InputValue_ *right_buffer, OutputValue_ *output_buffer) const
Definition arithmetic_helpers.hpp:38
void dense(bool, Index_, const std::vector< Index_ > &indices, const InputValue_ *left_buffer, const InputValue_ *right_buffer, OutputValue_ *output_buffer) const
Definition arithmetic_helpers.hpp:49
std::optional< Index_ > ncol() const
Definition arithmetic_helpers.hpp:115
Helper operation interface for DelayedBinaryIsometricOperation.
Definition helper_interface.hpp:26
Flexible representations for matrix data.
Definition Extractor.hpp:15
A range of a sparse vector.
Definition SparseRange.hpp:32