chromium/third_party/eigen3/src/Eigen/src/Core/functors/BinaryFunctors.h

// This file is part of Eigen, a lightweight C++ template library
// for linear algebra.
//
// Copyright (C) 2008-2010 Gael Guennebaud <[email protected]>
//
// This Source Code Form is subject to the terms of the Mozilla
// Public License v. 2.0. If a copy of the MPL was not distributed
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.

#ifndef EIGEN_BINARY_FUNCTORS_H
#define EIGEN_BINARY_FUNCTORS_H

// IWYU pragma: private
#include "../InternalHeaderCheck.h"

namespace Eigen {

namespace internal {

//---------- associative binary functors ----------

template <typename Arg1, typename Arg2>
struct binary_op_base {};

/** \internal
 * \brief Template functor to compute the sum of two scalars
 *
 * \sa class CwiseBinaryOp, MatrixBase::operator+, class VectorwiseOp, DenseBase::sum()
 */
template <typename LhsScalar, typename RhsScalar>
struct scalar_sum_op : binary_op_base<LhsScalar, RhsScalar> {};
functor_traits<scalar_sum_op<LhsScalar, RhsScalar>>;

template <>
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool scalar_sum_op<bool, bool>::operator()(const bool& a, const bool& b) const {}

/** \internal
 * \brief Template functor to compute the product of two scalars
 *
 * \sa class CwiseBinaryOp, Cwise::operator*(), class VectorwiseOp, MatrixBase::redux()
 */
template <typename LhsScalar, typename RhsScalar>
struct scalar_product_op : binary_op_base<LhsScalar, RhsScalar> {};
functor_traits<scalar_product_op<LhsScalar, RhsScalar>>;

template <>
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool scalar_product_op<bool, bool>::operator()(const bool& a,
                                                                                     const bool& b) const {}

/** \internal
 * \brief Template functor to compute the conjugate product of two scalars
 *
 * This is a short cut for conj(x) * y which is needed for optimization purpose; in Eigen2 support mode, this becomes x
 * * conj(y)
 */
template <typename LhsScalar, typename RhsScalar>
struct scalar_conj_product_op : binary_op_base<LhsScalar, RhsScalar> {};
functor_traits<scalar_conj_product_op<LhsScalar, RhsScalar>>;

/** \internal
 * \brief Template functor to compute the min of two scalars
 *
 * \sa class CwiseBinaryOp, MatrixBase::cwiseMin, class VectorwiseOp, MatrixBase::minCoeff()
 */
template <typename LhsScalar, typename RhsScalar, int NaNPropagation>
struct scalar_min_op : binary_op_base<LhsScalar, RhsScalar> {};

functor_traits<scalar_min_op<LhsScalar, RhsScalar, NaNPropagation>>;

/** \internal
 * \brief Template functor to compute the max of two scalars
 *
 * \sa class CwiseBinaryOp, MatrixBase::cwiseMax, class VectorwiseOp, MatrixBase::maxCoeff()
 */
template <typename LhsScalar, typename RhsScalar, int NaNPropagation>
struct scalar_max_op : binary_op_base<LhsScalar, RhsScalar> {};

functor_traits<scalar_max_op<LhsScalar, RhsScalar, NaNPropagation>>;

/** \internal
 * \brief Template functors for comparison of two scalars
 * \todo Implement packet-comparisons
 */
template <typename LhsScalar, typename RhsScalar, ComparisonName cmp, bool UseTypedComparators = false>
struct scalar_cmp_op;

functor_traits<scalar_cmp_op<LhsScalar, RhsScalar, cmp, UseTypedComparators>>;

template <typename LhsScalar, typename RhsScalar, bool UseTypedComparators>
struct typed_cmp_helper {};

cmp_return_t;

scalar_cmp_op<LhsScalar, RhsScalar, cmp_EQ, UseTypedComparators>;

scalar_cmp_op<LhsScalar, RhsScalar, cmp_LT, UseTypedComparators>;

scalar_cmp_op<LhsScalar, RhsScalar, cmp_LE, UseTypedComparators>;

scalar_cmp_op<LhsScalar, RhsScalar, cmp_GT, UseTypedComparators>;

scalar_cmp_op<LhsScalar, RhsScalar, cmp_GE, UseTypedComparators>;

scalar_cmp_op<LhsScalar, RhsScalar, cmp_UNORD, UseTypedComparators>;

scalar_cmp_op<LhsScalar, RhsScalar, cmp_NEQ, UseTypedComparators>;

/** \internal
 * \brief Template functor to compute the hypot of two \b positive \b and \b real scalars
 *
 * \sa MatrixBase::stableNorm(), class Redux
 */
scalar_hypot_op<Scalar, Scalar>;
functor_traits<scalar_hypot_op<Scalar, Scalar>>;

/** \internal
 * \brief Template functor to compute the pow of two scalars
 * See the specification of pow in https://en.cppreference.com/w/cpp/numeric/math/pow
 */
template <typename Scalar, typename Exponent>
struct scalar_pow_op : binary_op_base<Scalar, Exponent> {};

functor_traits<scalar_pow_op<Scalar, Exponent>>;

//---------- non associative binary functors ----------

/** \internal
 * \brief Template functor to compute the difference of two scalars
 *
 * \sa class CwiseBinaryOp, MatrixBase::operator-
 */
template <typename LhsScalar, typename RhsScalar>
struct scalar_difference_op : binary_op_base<LhsScalar, RhsScalar> {};
functor_traits<scalar_difference_op<LhsScalar, RhsScalar>>;

template <typename Packet, bool IsInteger = NumTraits<typename unpacket_traits<Packet>::type>::IsInteger>
struct maybe_raise_div_by_zero {};

#ifndef EIGEN_GPU_COMPILE_PHASE
maybe_raise_div_by_zero<Packet, true>;
#endif

/** \internal
 * \brief Template functor to compute the quotient of two scalars
 *
 * \sa class CwiseBinaryOp, Cwise::operator/()
 */
template <typename LhsScalar, typename RhsScalar>
struct scalar_quotient_op : binary_op_base<LhsScalar, RhsScalar> {};
functor_traits<scalar_quotient_op<LhsScalar, RhsScalar>>;

/** \internal
 * \brief Template functor to compute the and of two scalars as if they were booleans
 *
 * \sa class CwiseBinaryOp, ArrayBase::operator&&
 */
template <typename Scalar>
struct scalar_boolean_and_op {};
functor_traits<scalar_boolean_and_op<Scalar>>;

/** \internal
 * \brief Template functor to compute the or of two scalars as if they were booleans
 *
 * \sa class CwiseBinaryOp, ArrayBase::operator||
 */
template <typename Scalar>
struct scalar_boolean_or_op {};
functor_traits<scalar_boolean_or_op<Scalar>>;

/** \internal
 * \brief Template functor to compute the xor of two scalars as if they were booleans
 *
 * \sa class CwiseBinaryOp, ArrayBase::operator^
 */
template <typename Scalar>
struct scalar_boolean_xor_op {};
functor_traits<scalar_boolean_xor_op<Scalar>>;

template <typename Scalar, bool IsComplex = NumTraits<Scalar>::IsComplex>
struct bitwise_binary_impl {};

bitwise_binary_impl<Scalar, true>;

/** \internal
 * \brief Template functor to compute the bitwise and of two scalars
 *
 * \sa class CwiseBinaryOp, ArrayBase::operator&
 */
template <typename Scalar>
struct scalar_bitwise_and_op {};
functor_traits<scalar_bitwise_and_op<Scalar>>;

/** \internal
 * \brief Template functor to compute the bitwise or of two scalars
 *
 * \sa class CwiseBinaryOp, ArrayBase::operator|
 */
template <typename Scalar>
struct scalar_bitwise_or_op {};
functor_traits<scalar_bitwise_or_op<Scalar>>;

/** \internal
 * \brief Template functor to compute the bitwise xor of two scalars
 *
 * \sa class CwiseBinaryOp, ArrayBase::operator^
 */
template <typename Scalar>
struct scalar_bitwise_xor_op {};
functor_traits<scalar_bitwise_xor_op<Scalar>>;

/** \internal
 * \brief Template functor to compute the absolute difference of two scalars
 *
 * \sa class CwiseBinaryOp, MatrixBase::absolute_difference
 */
template <typename LhsScalar, typename RhsScalar>
struct scalar_absolute_difference_op : binary_op_base<LhsScalar, RhsScalar> {};
functor_traits<scalar_absolute_difference_op<LhsScalar, RhsScalar>>;

template <typename LhsScalar, typename RhsScalar>
struct scalar_atan2_op {};

functor_traits<scalar_atan2_op<LhsScalar, RhsScalar>>;

//---------- binary functors bound to a constant, thus appearing as a unary functor ----------

// The following two classes permits to turn any binary functor into a unary one with one argument bound to a constant
// value. They are analogues to std::binder1st/binder2nd but with the following differences:
//  - they are compatible with packetOp
//  - they are portable across C++ versions (the std::binder* are deprecated in C++11)
template <typename BinaryOp>
struct bind1st_op : BinaryOp {};
functor_traits<bind1st_op<BinaryOp>>;

template <typename BinaryOp>
struct bind2nd_op : BinaryOp {};
functor_traits<bind2nd_op<BinaryOp>>;

}  // end namespace internal

}  // end namespace Eigen

#endif  // EIGEN_BINARY_FUNCTORS_H