Medial Code Documentation
Loading...
Searching...
No Matches
CwiseBinaryOp.h
1// This file is part of Eigen, a lightweight C++ template library
2// for linear algebra.
3//
4// Copyright (C) 2008-2014 Gael Guennebaud <gael.guennebaud@inria.fr>
5// Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com>
6//
7// This Source Code Form is subject to the terms of the Mozilla
8// Public License v. 2.0. If a copy of the MPL was not distributed
9// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
10
11#ifndef EIGEN_CWISE_BINARY_OP_H
12#define EIGEN_CWISE_BINARY_OP_H
13
14namespace Eigen {
15
36namespace internal {
37template<typename BinaryOp, typename Lhs, typename Rhs>
38struct traits<CwiseBinaryOp<BinaryOp, Lhs, Rhs> >
39{
40 // we must not inherit from traits<Lhs> since it has
41 // the potential to cause problems with MSVC
42 typedef typename remove_all<Lhs>::type Ancestor;
43 typedef typename traits<Ancestor>::XprKind XprKind;
44 enum {
45 RowsAtCompileTime = traits<Ancestor>::RowsAtCompileTime,
46 ColsAtCompileTime = traits<Ancestor>::ColsAtCompileTime,
47 MaxRowsAtCompileTime = traits<Ancestor>::MaxRowsAtCompileTime,
48 MaxColsAtCompileTime = traits<Ancestor>::MaxColsAtCompileTime
49 };
50
51 // even though we require Lhs and Rhs to have the same scalar type (see CwiseBinaryOp constructor),
52 // we still want to handle the case when the result type is different.
53 typedef typename result_of<
54 BinaryOp(
55 typename Lhs::Scalar,
56 typename Rhs::Scalar
57 )
58 >::type Scalar;
61 BinaryOp>::ret StorageKind;
64 typedef typename Lhs::Nested LhsNested;
65 typedef typename Rhs::Nested RhsNested;
66 typedef typename remove_reference<LhsNested>::type _LhsNested;
67 typedef typename remove_reference<RhsNested>::type _RhsNested;
68 enum {
69 Flags = _LhsNested::Flags & RowMajorBit
70 };
71};
72} // end namespace internal
73
74template<typename BinaryOp, typename Lhs, typename Rhs, typename StorageKind>
76
77template<typename BinaryOp, typename LhsType, typename RhsType>
79 public CwiseBinaryOpImpl<
80 BinaryOp, LhsType, RhsType,
81 typename internal::cwise_promote_storage_type<typename internal::traits<LhsType>::StorageKind,
82 typename internal::traits<RhsType>::StorageKind,
83 BinaryOp>::ret>,
85{
86 public:
87
90
91 typedef typename CwiseBinaryOpImpl<
92 BinaryOp, LhsType, RhsType,
95 BinaryOp>::ret>::Base Base;
96 EIGEN_GENERIC_PUBLIC_INTERFACE(CwiseBinaryOp)
97
100 typedef typename internal::remove_reference<LhsNested>::type _LhsNested;
101 typedef typename internal::remove_reference<RhsNested>::type _RhsNested;
102
104 EIGEN_STRONG_INLINE CwiseBinaryOp(const Lhs& aLhs, const Rhs& aRhs, const BinaryOp& func = BinaryOp())
105 : m_lhs(aLhs), m_rhs(aRhs), m_functor(func)
106 {
107 EIGEN_CHECK_BINARY_COMPATIBILIY(BinaryOp,typename Lhs::Scalar,typename Rhs::Scalar);
108 // require the sizes to match
109 EIGEN_STATIC_ASSERT_SAME_MATRIX_SIZE(Lhs, Rhs)
110 eigen_assert(aLhs.rows() == aRhs.rows() && aLhs.cols() == aRhs.cols());
111 }
112
114 EIGEN_STRONG_INLINE Index rows() const {
115 // return the fixed size type if available to enable compile time optimizations
116 if (internal::traits<typename internal::remove_all<LhsNested>::type>::RowsAtCompileTime==Dynamic)
117 return m_rhs.rows();
118 else
119 return m_lhs.rows();
120 }
122 EIGEN_STRONG_INLINE Index cols() const {
123 // return the fixed size type if available to enable compile time optimizations
124 if (internal::traits<typename internal::remove_all<LhsNested>::type>::ColsAtCompileTime==Dynamic)
125 return m_rhs.cols();
126 else
127 return m_lhs.cols();
128 }
129
132 const _LhsNested& lhs() const { return m_lhs; }
135 const _RhsNested& rhs() const { return m_rhs; }
138 const BinaryOp& functor() const { return m_functor; }
139
140 protected:
141 LhsNested m_lhs;
142 RhsNested m_rhs;
143 const BinaryOp m_functor;
144};
145
146// Generic API dispatcher
147template<typename BinaryOp, typename Lhs, typename Rhs, typename StorageKind>
149 : public internal::generic_xpr_base<CwiseBinaryOp<BinaryOp, Lhs, Rhs> >::type
150{
151public:
153};
154
159template<typename Derived>
160template<typename OtherDerived>
161EIGEN_STRONG_INLINE Derived &
163{
164 call_assignment(derived(), other.derived(), internal::sub_assign_op<Scalar>());
165 return derived();
166}
167
172template<typename Derived>
173template<typename OtherDerived>
174EIGEN_STRONG_INLINE Derived &
176{
177 call_assignment(derived(), other.derived(), internal::add_assign_op<Scalar>());
178 return derived();
179}
180
181} // end namespace Eigen
182
183#endif // EIGEN_CWISE_BINARY_OP_H
184
Definition CwiseBinaryOp.h:150
Generic expression where a coefficient-wise binary operator is applied to two expressions.
Definition CwiseBinaryOp.h:85
EIGEN_DEVICE_FUNC const _LhsNested & lhs() const
Definition CwiseBinaryOp.h:132
EIGEN_DEVICE_FUNC const BinaryOp & functor() const
Definition CwiseBinaryOp.h:138
EIGEN_DEVICE_FUNC const _RhsNested & rhs() const
Definition CwiseBinaryOp.h:135
Base class for all dense matrices, vectors, and expressions.
Definition MatrixBase.h:50
Pseudo expression representing a solving operation.
Definition Solve.h:63
const unsigned int RowMajorBit
for a matrix, this means that the storage order is row-major.
Definition Constants.h:61
Definition AssignmentFunctors.h:42
Definition XprHelper.h:445
Definition Meta.h:253
Definition AssignmentFunctors.h:63
Definition ForwardDeclarations.h:17
Definition Meta.h:30