Skip to content

Commit

Permalink
More consistent names for all delayed isometric classes and files. (#98)
Browse files Browse the repository at this point in the history
Also cleaned up the associated docstrings.
  • Loading branch information
LTLA authored May 17, 2024
1 parent 55d1384 commit 0d970d4
Show file tree
Hide file tree
Showing 30 changed files with 1,306 additions and 1,176 deletions.
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
#ifndef TATAMI_ARITH_UTILS_HPP
#define TATAMI_ARITH_UTILS_HPP
#ifndef TATAMI_ARITHMETIC_UTILS_HPP
#define TATAMI_ARITHMETIC_UTILS_HPP

#include <cmath>

/**
* @file arith_utils.hpp
* @file arithmetic_utils.hpp
*
* @brief Utilities for delayed arithmetic operations.
*/

namespace tatami {

/**
* Type of the delayed arithmetic operation.
* Type of arithmetic operation.
*/
enum class DelayedArithOp : char {
enum class ArithmeticOperation : char {
ADD,
SUBTRACT,
MULTIPLY,
Expand All @@ -27,19 +27,19 @@ enum class DelayedArithOp : char {
/**
* @cond
*/
template<DelayedArithOp op_, bool right_, typename Scalar_, typename Value_>
void delayed_arith_run(Value_& val, Scalar_ scalar) {
if constexpr(op_ == DelayedArithOp::ADD) {
template<ArithmeticOperation op_, bool right_, typename Scalar_, typename Value_>
void delayed_arithmetic_run(Value_& val, Scalar_ scalar) {
if constexpr(op_ == ArithmeticOperation::ADD) {
val += scalar;
} else if constexpr(op_ == DelayedArithOp::MULTIPLY) {
} else if constexpr(op_ == ArithmeticOperation::MULTIPLY) {
val *= scalar;
} else if constexpr(op_ == DelayedArithOp::SUBTRACT) {
} else if constexpr(op_ == ArithmeticOperation::SUBTRACT) {
if constexpr(right_) {
val -= scalar;
} else {
val = scalar - val;
}
} else if constexpr(op_ == DelayedArithOp::DIVIDE) {
} else if constexpr(op_ == ArithmeticOperation::DIVIDE) {
// Assume that either Value_ is an IEEE-754 float, or that division by
// zero is impossible in this context. We don't apply manual checks
// here to avoid performance degradation; we also don't check that the
Expand All @@ -50,19 +50,19 @@ void delayed_arith_run(Value_& val, Scalar_ scalar) {
} else {
val = scalar / val;
}
} else if constexpr(op_ == DelayedArithOp::POWER) {
} else if constexpr(op_ == ArithmeticOperation::POWER) {
if constexpr(right_) {
val = std::pow(val, scalar);
} else {
val = std::pow(scalar, val);
}
} else if constexpr(op_ == DelayedArithOp::MODULO) {
} else if constexpr(op_ == ArithmeticOperation::MODULO) {
if constexpr(right_) {
val = std::fmod(val, scalar);
} else {
val = std::fmod(scalar, val);
}
} else if constexpr(op_ == DelayedArithOp::INTEGER_DIVIDE) {
} else if constexpr(op_ == ArithmeticOperation::INTEGER_DIVIDE) {
if constexpr(right_) {
val = std::floor(val / scalar);
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef TATAMI_DELAYED_BINARY_ISOMETRIC_OP_H
#define TATAMI_DELAYED_BINARY_ISOMETRIC_OP_H
#ifndef TATAMI_DELAYED_BINARY_ISOMETRIC_OPERATION_H
#define TATAMI_DELAYED_BINARY_ISOMETRIC_OPERATION_H

#include "../../base/Matrix.hpp"
#include "../../utils/new_extractor.hpp"
Expand All @@ -14,16 +14,14 @@
* @file DelayedBinaryIsometricOp.hpp
*
* @brief Delayed binary isometric operations.
*
* This is equivalent to the class of the same name in the **DelayedArray** package.
*/

namespace tatami {

/**
* @cond
*/
namespace DelayedBinaryIsometricOp_internal {
namespace DelayedBinaryIsometricOperation_internal {

template<class Operation_, bool oracle_, typename Index_>
class MaybeOracleDepends {
Expand Down Expand Up @@ -488,23 +486,25 @@ class Sparse : public SparseExtractor<oracle_, Value_, Index_> {
*
* Implements any operation that takes two matrices of the same shape and returns another matrix of that shape.
* Each entry of the output matrix is a function of the corresponding values in the two input matrices.
* This operation is "delayed" in that it is only evaluated on request, e.g., with `DenseExtractor::fetch()` or friends.
* This operation is "delayed" in that it is only evaluated during data extraction, e.g., with `MyopicDenseExtractor::fetch()` or friends.
*
* This class is inspired by the `DelayedNaryIsoOp` class in the **DelayedArray** Bioconductor package.
*
* @tparam Value_ Type of matrix value.
* @tparam Index_ Type of index value.
* @tparam Operation_ Class implementing the operation.
* This should implement the same methods as `DelayedBinaryBasicMockHelper` or `DelayedBinaryAdvancedMockHelper`,
* @tparam Operation_ Helper class implementing the operation.
* This should implement the same methods as `DelayedBinaryIsometricMockBasic` or `DelayedBinaryIsometricMockAdvanced`,
* depending on whether it can take advantage of matrix sparsity.
*/
template<typename Value_, typename Index_, class Operation_>
class DelayedBinaryIsometricOp : public Matrix<Value_, Index_> {
class DelayedBinaryIsometricOperation : public Matrix<Value_, Index_> {
public:
/**
* @param left Pointer to the left matrix.
* @param right Pointer to the right matrix.
* @param operation Instance of the functor class.
*/
DelayedBinaryIsometricOp(std::shared_ptr<const Matrix<Value_, Index_> > left, std::shared_ptr<const Matrix<Value_, Index_> > right, Operation_ operation) :
DelayedBinaryIsometricOperation(std::shared_ptr<const Matrix<Value_, Index_> > left, std::shared_ptr<const Matrix<Value_, Index_> > right, Operation_ operation) :
my_left(std::move(left)), my_right(std::move(right)), my_operation(std::move(operation))
{
if (my_left->nrow() != my_right->nrow() || my_left->ncol() != my_right->ncol()) {
Expand Down Expand Up @@ -572,7 +572,7 @@ class DelayedBinaryIsometricOp : public Matrix<Value_, Index_> {
private:
template<bool oracle_>
std::unique_ptr<DenseExtractor<oracle_, Value_, Index_> > dense_simple_internal(bool row, MaybeOracle<oracle_, Index_> oracle, const Options& opt) const {
return std::make_unique<DelayedBinaryIsometricOp_internal::DenseSimpleFull<oracle_, Value_, Index_, Operation_> >(
return std::make_unique<DelayedBinaryIsometricOperation_internal::DenseSimpleFull<oracle_, Value_, Index_, Operation_> >(
my_left.get(),
my_right.get(),
my_operation,
Expand All @@ -584,7 +584,7 @@ class DelayedBinaryIsometricOp : public Matrix<Value_, Index_> {

template<bool oracle_>
std::unique_ptr<DenseExtractor<oracle_, Value_, Index_> > dense_simple_internal(bool row, MaybeOracle<oracle_, Index_> oracle, Index_ block_start, Index_ block_length, const Options& opt) const {
return std::make_unique<DelayedBinaryIsometricOp_internal::DenseSimpleBlock<oracle_, Value_, Index_, Operation_> >(
return std::make_unique<DelayedBinaryIsometricOperation_internal::DenseSimpleBlock<oracle_, Value_, Index_, Operation_> >(
my_left.get(),
my_right.get(),
my_operation,
Expand All @@ -598,7 +598,7 @@ class DelayedBinaryIsometricOp : public Matrix<Value_, Index_> {

template<bool oracle_>
std::unique_ptr<DenseExtractor<oracle_, Value_, Index_> > dense_simple_internal(bool row, MaybeOracle<oracle_, Index_> oracle, VectorPtr<Index_> indices_ptr, const Options& opt) const {
return std::make_unique<DelayedBinaryIsometricOp_internal::DenseSimpleIndex<oracle_, Value_, Index_, Operation_> >(
return std::make_unique<DelayedBinaryIsometricOperation_internal::DenseSimpleIndex<oracle_, Value_, Index_, Operation_> >(
my_left.get(),
my_right.get(),
my_operation,
Expand All @@ -611,7 +611,7 @@ class DelayedBinaryIsometricOp : public Matrix<Value_, Index_> {

template<bool oracle_>
std::unique_ptr<DenseExtractor<oracle_, Value_, Index_> > dense_expanded_internal(bool row, MaybeOracle<oracle_, Index_> oracle, const Options& opt) const {
return std::make_unique<DelayedBinaryIsometricOp_internal::DenseExpandedFull<oracle_, Value_, Index_, Operation_> >(
return std::make_unique<DelayedBinaryIsometricOperation_internal::DenseExpandedFull<oracle_, Value_, Index_, Operation_> >(
my_left.get(),
my_right.get(),
my_operation,
Expand All @@ -623,7 +623,7 @@ class DelayedBinaryIsometricOp : public Matrix<Value_, Index_> {

template<bool oracle_>
std::unique_ptr<DenseExtractor<oracle_, Value_, Index_> > dense_expanded_internal(bool row, MaybeOracle<oracle_, Index_> oracle, Index_ block_start, Index_ block_length, const Options& opt) const {
return std::make_unique<DelayedBinaryIsometricOp_internal::DenseExpandedBlock<oracle_, Value_, Index_, Operation_> >(
return std::make_unique<DelayedBinaryIsometricOperation_internal::DenseExpandedBlock<oracle_, Value_, Index_, Operation_> >(
my_left.get(),
my_right.get(),
my_operation,
Expand All @@ -637,7 +637,7 @@ class DelayedBinaryIsometricOp : public Matrix<Value_, Index_> {

template<bool oracle_>
std::unique_ptr<DenseExtractor<oracle_, Value_, Index_> > dense_expanded_internal(bool row, MaybeOracle<oracle_, Index_> oracle, VectorPtr<Index_> indices_ptr, const Options& opt) const {
return std::make_unique<DelayedBinaryIsometricOp_internal::DenseExpandedIndex<oracle_, Value_, Index_, Operation_> >(
return std::make_unique<DelayedBinaryIsometricOperation_internal::DenseExpandedIndex<oracle_, Value_, Index_, Operation_> >(
my_left.get(),
my_right.get(),
my_operation,
Expand Down Expand Up @@ -684,7 +684,7 @@ class DelayedBinaryIsometricOp : public Matrix<Value_, Index_> {
std::unique_ptr<SparseExtractor<oracle_, Value_, Index_> > sparse_internal(bool row, MaybeOracle<oracle_, Index_> oracle, const Options& opt) const {
if constexpr(is_advanced) {
if (my_is_sparse) {
return std::make_unique<DelayedBinaryIsometricOp_internal::Sparse<oracle_, Value_, Index_, Operation_> >(
return std::make_unique<DelayedBinaryIsometricOperation_internal::Sparse<oracle_, Value_, Index_, Operation_> >(
my_left.get(),
my_right.get(),
my_operation,
Expand All @@ -706,7 +706,7 @@ class DelayedBinaryIsometricOp : public Matrix<Value_, Index_> {
std::unique_ptr<SparseExtractor<oracle_, Value_, Index_> > sparse_internal(bool row, MaybeOracle<oracle_, Index_> oracle, Index_ block_start, Index_ block_length, const Options& opt) const {
if constexpr(is_advanced) {
if (my_is_sparse) {
return std::make_unique<DelayedBinaryIsometricOp_internal::Sparse<oracle_, Value_, Index_, Operation_> >(
return std::make_unique<DelayedBinaryIsometricOperation_internal::Sparse<oracle_, Value_, Index_, Operation_> >(
my_left.get(),
my_right.get(),
my_operation,
Expand All @@ -731,7 +731,7 @@ class DelayedBinaryIsometricOp : public Matrix<Value_, Index_> {
std::unique_ptr<SparseExtractor<oracle_, Value_, Index_> > sparse_internal(bool row, MaybeOracle<oracle_, Index_> oracle, VectorPtr<Index_> indices_ptr, const Options& opt) const {
if constexpr(is_advanced) {
if (my_is_sparse) {
return std::make_unique<DelayedBinaryIsometricOp_internal::Sparse<oracle_, Value_, Index_, Operation_> >(
return std::make_unique<DelayedBinaryIsometricOperation_internal::Sparse<oracle_, Value_, Index_, Operation_> >(
my_left.get(),
my_right.get(),
my_operation,
Expand Down Expand Up @@ -810,27 +810,27 @@ class DelayedBinaryIsometricOp : public Matrix<Value_, Index_> {
* @return Instance of a `DelayedBinaryIsometricOp` clas.
*/
template<typename Value_, typename Index_, class Operation_>
std::shared_ptr<Matrix<Value_, Index_> > make_DelayedBinaryIsometricOp(std::shared_ptr<const Matrix<Value_, Index_> > left, std::shared_ptr<const Matrix<Value_, Index_> > right, Operation_ op) {
typedef typename std::remove_reference<Operation_>::type Op_;
return std::shared_ptr<Matrix<Value_, Index_> >(new DelayedBinaryIsometricOp<Value_, Index_, Op_>(std::move(left), std::move(right), std::move(op)));
std::shared_ptr<Matrix<Value_, Index_> > make_DelayedBinaryIsometricOperation(std::shared_ptr<const Matrix<Value_, Index_> > left, std::shared_ptr<const Matrix<Value_, Index_> > right, Operation_ op) {
typedef typename std::remove_reference<Operation_>::type Operation2_;
return std::shared_ptr<Matrix<Value_, Index_> >(new DelayedBinaryIsometricOperation<Value_, Index_, Operation2_>(std::move(left), std::move(right), std::move(op)));
}

/**
* @cond
*/
// For automatic template deduction with non-const pointers.
template<typename Value_, typename Index_, class Operation_>
std::shared_ptr<Matrix<Value_, Index_> > make_DelayedBinaryIsometricOp(std::shared_ptr<Matrix<Value_, Index_> > left, std::shared_ptr<Matrix<Value_, Index_> > right, Operation_ op) {
typedef typename std::remove_reference<Operation_>::type Op_;
return std::shared_ptr<Matrix<Value_, Index_> >(new DelayedBinaryIsometricOp<Value_, Index_, Op_>(std::move(left), std::move(right), std::move(op)));
std::shared_ptr<Matrix<Value_, Index_> > make_DelayedBinaryIsometricOperation(std::shared_ptr<Matrix<Value_, Index_> > left, std::shared_ptr<Matrix<Value_, Index_> > right, Operation_ op) {
typedef typename std::remove_reference<Operation_>::type Operation2_;
return std::shared_ptr<Matrix<Value_, Index_> >(new DelayedBinaryIsometricOperation<Value_, Index_, Operation2_>(std::move(left), std::move(right), std::move(op)));
}
/**
* @endcond
*/

}

#include "arith_helpers.hpp"
#include "arithmetic_helpers.hpp"

#include "compare_helpers.hpp"

Expand Down
145 changes: 0 additions & 145 deletions include/tatami/isometric/binary/arith_helpers.hpp

This file was deleted.

Loading

0 comments on commit 0d970d4

Please sign in to comment.