CommonCwiseBinaryOps.h File Reference

Go to the source code of this file.

Functions

template<typename CustomBinaryOp , typename OtherDerived >
const CwiseBinaryOp< CustomBinaryOp, const Derived, const OtherDerived > binaryExpr (const EIGEN_CURRENT_STORAGE_BASE_CLASS< OtherDerived > &other, const CustomBinaryOp &func=CustomBinaryOp()) const
 
template<typename OtherDerived >
const CwiseBinaryOp< internal::scalar_bitwise_and_op< Scalar >, const Derived, const OtherDerived > operator& (const EIGEN_CURRENT_STORAGE_BASE_CLASS< OtherDerived > &other) const
 
template<typename OtherDerived >
const CwiseBinaryOp< internal::scalar_boolean_and_op< Scalar >, const Derived, const OtherDerived > operator&& (const EIGEN_CURRENT_STORAGE_BASE_CLASS< OtherDerived > &other) const
 
template<typename T >
const CwiseBinaryOp< internal::scalar_product_op< Scalar, T >, Derived, Constant< T > > operator* (const T &scalar) const
 
template<typename T >
const CwiseBinaryOp< internal::scalar_product_op< T, Scalar >, Constant< T >, Derived > operator* (const T &scalar, const StorageBaseType &expr)
 
template<typename OtherDerived >
const CwiseBinaryOp< sum< Scalar >, const Derived, const OtherDerived > operator+ (const EIGEN_CURRENT_STORAGE_BASE_CLASS< OtherDerived > &other) const
 
template<typename OtherDerived >
const CwiseBinaryOp< difference< Scalar >, const Derived, const OtherDerived > operator- (const EIGEN_CURRENT_STORAGE_BASE_CLASS< OtherDerived > &other) const
 
template<typename T >
const CwiseBinaryOp< internal::scalar_quotient_op< Scalar, T >, Derived, Constant< T > > operator/ (const T &scalar) const
 
template<typename OtherDerived >
const CwiseBinaryOp< internal::scalar_bitwise_xor_op< Scalar >, const Derived, const OtherDerived > operator^ (const EIGEN_CURRENT_STORAGE_BASE_CLASS< OtherDerived > &other) const
 
template<typename OtherDerived >
const CwiseBinaryOp< internal::scalar_bitwise_or_op< Scalar >, const Derived, const OtherDerived > operator| (const EIGEN_CURRENT_STORAGE_BASE_CLASS< OtherDerived > &other) const
 
template<typename OtherDerived >
const CwiseBinaryOp< internal::scalar_boolean_or_op< Scalar >, const Derived, const OtherDerived > operator|| (const EIGEN_CURRENT_STORAGE_BASE_CLASS< OtherDerived > &other) const
 

Function Documentation

◆ binaryExpr()

template<typename CustomBinaryOp , typename OtherDerived >
const CwiseBinaryOp<CustomBinaryOp, const Derived, const OtherDerived> binaryExpr ( const EIGEN_CURRENT_STORAGE_BASE_CLASS< OtherDerived > &  other,
const CustomBinaryOp &  func = CustomBinaryOp() 
) const
inline
Returns
an expression of a custom coefficient-wise operator func of *this and other

The template parameter CustomBinaryOp is the type of the functor of the custom operator (see class CwiseBinaryOp for an example)

Here is an example illustrating the use of custom functors:

#include <Eigen/Core>
#include <iostream>
// define a custom template binary functor
template<typename Scalar> struct MakeComplexOp {
typedef std::complex<Scalar> result_type;
result_type operator()(const Scalar& a, const Scalar& b) const { return result_type(a,b); }
};
int main(int, char**)
{
Matrix4d m1 = Matrix4d::Random(), m2 = Matrix4d::Random();
std::cout << m1.binaryExpr(m2, MakeComplexOp<double>()) << std::endl;
return 0;
}
Array< int, 3, 1 > b
Matrix3d m1
Definition: IOFormat.cpp:2
IndexedView_or_Block operator()(const RowIndices &rowIndices, const ColIndices &colIndices)
MatrixType m2(n_dims)
int main(int, char **)
Definition: class_Block.cpp:18
Matrix< double, 4, 4 > Matrix4d
4×4 matrix of type double.
Definition: Matrix.h:502

Output:

   (0.68,0.271)  (0.823,-0.967) (-0.444,-0.687)   (-0.27,0.998)
 (-0.211,0.435) (-0.605,-0.514)  (0.108,-0.198) (0.0268,-0.563)
 (0.566,-0.717)  (-0.33,-0.726) (-0.0452,-0.74)  (0.904,0.0259)
  (0.597,0.214)   (0.536,0.608)  (0.258,-0.782)   (0.832,0.678)
See also
class CwiseBinaryOp, operator+(), operator-(), cwiseProduct()

Definition at line 43 of file CommonCwiseBinaryOps.h.

44 {
45  return CwiseBinaryOp<CustomBinaryOp, const Derived, const OtherDerived>(derived(), other.derived(), func);
46 }

◆ operator&()

template<typename OtherDerived >
const CwiseBinaryOp<internal::scalar_bitwise_and_op<Scalar>, const Derived, const OtherDerived> operator& ( const EIGEN_CURRENT_STORAGE_BASE_CLASS< OtherDerived > &  other) const
inline
Returns
an expression of the bitwise and operator of *this and other
See also
operator|(), operator^()

Definition at line 113 of file CommonCwiseBinaryOps.h.

113  {
114  return CwiseBinaryOp<internal::scalar_bitwise_and_op<Scalar>, const Derived, const OtherDerived>(derived(),
115  other.derived());
116 }

◆ operator&&()

template<typename OtherDerived >
const CwiseBinaryOp<internal::scalar_boolean_and_op<Scalar>, const Derived, const OtherDerived> operator&& ( const EIGEN_CURRENT_STORAGE_BASE_CLASS< OtherDerived > &  other) const
inline
Returns
an expression of the coefficient-wise boolean and operator of *this and other

Example:

Array3d v(-1,2,1), w(-3,2,3);
cout << ((v<w) && (v<0)) << endl;
Array< int, Dynamic, 1 > v
RowVector3d w
Array< double, 3, 1 > Array3d
Definition: Array.h:346

Output:

0
0
0
See also
operator||(), select()

Definition at line 88 of file CommonCwiseBinaryOps.h.

88  {
89  return CwiseBinaryOp<internal::scalar_boolean_and_op<Scalar>, const Derived, const OtherDerived>(derived(),
90  other.derived());
91 }

◆ operator*() [1/2]

template<typename T >
const CwiseBinaryOp<internal::scalar_product_op<Scalar,T>,Derived,Constant<T> > operator* ( const T scalar) const
Returns
an expression of *this scaled by the scalar factor scalar
Template Parameters
Tis the scalar type of scalar. It must be compatible with the scalar type of the given expression.

◆ operator*() [2/2]

template<typename T >
friend const CwiseBinaryOp<internal::scalar_product_op<T,Scalar>,Constant<T>,Derived> operator* ( const T scalar,
const StorageBaseType &  expr 
)
Returns
an expression of expr scaled by the scalar factor scalar
Template Parameters
Tis the scalar type of scalar. It must be compatible with the scalar type of the given expression.

◆ operator+()

template<typename OtherDerived >
const CwiseBinaryOp< sum <Scalar>, const Derived, const OtherDerived> operator+ ( const EIGEN_CURRENT_STORAGE_BASE_CLASS< OtherDerived > &  other) const
Returns
an expression of the sum of *this and other
Note
If you want to add a given scalar to all coefficients, see Cwise::operator+().
See also
class CwiseBinaryOp, operator+=()

◆ operator-()

template<typename OtherDerived >
const CwiseBinaryOp< difference <Scalar>, const Derived, const OtherDerived> operator- ( const EIGEN_CURRENT_STORAGE_BASE_CLASS< OtherDerived > &  other) const
Returns
an expression of the difference of *this and other
Note
If you want to subtract a given scalar from all coefficients, see Cwise::operator-().
See also
class CwiseBinaryOp, operator-=()

◆ operator/()

template<typename T >
const CwiseBinaryOp<internal::scalar_quotient_op<Scalar,T>,Derived,Constant<T> > operator/ ( const T scalar) const
Returns
an expression of *this divided by the scalar value scalar
Template Parameters
Tis the scalar type of scalar. It must be compatible with the scalar type of the given expression.

◆ operator^()

template<typename OtherDerived >
const CwiseBinaryOp<internal::scalar_bitwise_xor_op<Scalar>, const Derived, const OtherDerived> operator^ ( const EIGEN_CURRENT_STORAGE_BASE_CLASS< OtherDerived > &  other) const
inline
Returns
an expression of the bitwise xor operator of *this and other
See also
operator&(), operator|()

Definition at line 134 of file CommonCwiseBinaryOps.h.

134  {
135  return CwiseBinaryOp<internal::scalar_bitwise_xor_op<Scalar>, const Derived, const OtherDerived>(derived(),
136  other.derived());
137 }

◆ operator|()

template<typename OtherDerived >
const CwiseBinaryOp<internal::scalar_bitwise_or_op<Scalar>, const Derived, const OtherDerived> operator| ( const EIGEN_CURRENT_STORAGE_BASE_CLASS< OtherDerived > &  other) const
inline
Returns
an expression of the bitwise boolean or operator of *this and other
See also
operator&(), operator^()

Definition at line 124 of file CommonCwiseBinaryOps.h.

124  {
125  return CwiseBinaryOp<internal::scalar_bitwise_or_op<Scalar>, const Derived, const OtherDerived>(derived(),
126  other.derived());
127 }

◆ operator||()

template<typename OtherDerived >
const CwiseBinaryOp<internal::scalar_boolean_or_op<Scalar>, const Derived, const OtherDerived> operator|| ( const EIGEN_CURRENT_STORAGE_BASE_CLASS< OtherDerived > &  other) const
inline
Returns
an expression of the coefficient-wise boolean or operator of *this and other

Example:

Array3d v(-1,2,1), w(-3,2,3);
cout << ((v<w) || (v<0)) << endl;

Output:

1
0
1
See also
operator&&(), select()

Definition at line 102 of file CommonCwiseBinaryOps.h.

102  {
103  return CwiseBinaryOp<internal::scalar_boolean_or_op<Scalar>, const Derived, const OtherDerived>(derived(),
104  other.derived());
105 }