10 #ifndef EIGEN_SPARSE_CWISE_BINARY_OP_H 11 #define EIGEN_SPARSE_CWISE_BINARY_OP_H 35 template<
typename BinaryOp,
typename Lhs,
typename Rhs>
42 EIGEN_SPARSE_PUBLIC_INTERFACE(Derived)
48 || ((Lhs::Flags&
RowMajorBit) == (Rhs::Flags&RowMajorBit))),
49 THE_STORAGE_ORDER_OF_BOTH_SIDES_MUST_MATCH);
59 template<
typename BinaryOp,
typename Lhs,
typename Rhs>
68 typedef typename XprType::StorageIndex StorageIndex;
76 : m_lhsIter(aEval.m_lhsImpl,outer), m_rhsIter(aEval.m_rhsImpl,outer), m_functor(aEval.m_functor)
81 EIGEN_STRONG_INLINE InnerIterator& operator++()
83 if (m_lhsIter && m_rhsIter && (m_lhsIter.index() == m_rhsIter.index()))
85 m_id = m_lhsIter.index();
86 m_value = m_functor(m_lhsIter.value(), m_rhsIter.value());
90 else if (m_lhsIter && (!m_rhsIter || (m_lhsIter.index() < m_rhsIter.index())))
92 m_id = m_lhsIter.index();
93 m_value = m_functor(m_lhsIter.value(), Scalar(0));
96 else if (m_rhsIter && (!m_lhsIter || (m_lhsIter.index() > m_rhsIter.index())))
98 m_id = m_rhsIter.index();
99 m_value = m_functor(Scalar(0), m_rhsIter.value());
110 EIGEN_STRONG_INLINE Scalar value()
const {
return m_value; }
112 EIGEN_STRONG_INLINE StorageIndex index()
const {
return m_id; }
113 EIGEN_STRONG_INLINE
Index row()
const {
return Lhs::IsRowMajor ? m_lhsIter.row() : index(); }
114 EIGEN_STRONG_INLINE
Index col()
const {
return Lhs::IsRowMajor ? index() : m_lhsIter.col(); }
116 EIGEN_STRONG_INLINE
operator bool()
const {
return m_id>=0; }
119 LhsIterator m_lhsIter;
120 RhsIterator m_rhsIter;
121 const BinaryOp& m_functor;
129 Flags = XprType::Flags
134 m_lhsImpl(xpr.
lhs()),
138 EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
141 inline Index nonZerosEstimate()
const {
142 return m_lhsImpl.nonZerosEstimate() + m_rhsImpl.nonZerosEstimate();
146 const BinaryOp m_functor;
152 template<
typename BinaryOp,
typename Lhs,
typename Rhs>
160 typedef typename XprType::StorageIndex StorageIndex;
169 : m_lhsEval(aEval.m_lhsImpl), m_rhsIter(aEval.m_rhsImpl,outer), m_functor(aEval.m_functor), m_value(0), m_id(-1), m_innerSize(aEval.m_expr.rhs().innerSize())
174 EIGEN_STRONG_INLINE InnerIterator& operator++()
179 Scalar lhsVal = m_lhsEval.coeff(IsRowMajor?m_rhsIter.outer():m_id,
180 IsRowMajor?m_id:m_rhsIter.outer());
181 if(m_rhsIter && m_rhsIter.index()==m_id)
183 m_value = m_functor(lhsVal, m_rhsIter.value());
187 m_value = m_functor(lhsVal, Scalar(0));
193 EIGEN_STRONG_INLINE Scalar value()
const { eigen_internal_assert(m_id<m_innerSize);
return m_value; }
195 EIGEN_STRONG_INLINE StorageIndex index()
const {
return m_id; }
196 EIGEN_STRONG_INLINE
Index row()
const {
return IsRowMajor ? m_rhsIter.outer() : m_id; }
197 EIGEN_STRONG_INLINE
Index col()
const {
return IsRowMajor ? m_id : m_rhsIter.outer(); }
199 EIGEN_STRONG_INLINE
operator bool()
const {
return m_id<m_innerSize; }
203 RhsIterator m_rhsIter;
204 const BinaryOp& m_functor;
207 StorageIndex m_innerSize;
219 m_lhsImpl(xpr.
lhs()),
220 m_rhsImpl(xpr.
rhs()),
224 EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
227 inline Index nonZerosEstimate()
const {
228 return m_expr.size();
232 const BinaryOp m_functor;
235 const XprType &m_expr;
239 template<
typename BinaryOp,
typename Lhs,
typename Rhs>
247 typedef typename XprType::StorageIndex StorageIndex;
256 : m_lhsIter(aEval.m_lhsImpl,outer), m_rhsEval(aEval.m_rhsImpl), m_functor(aEval.m_functor), m_value(0), m_id(-1), m_innerSize(aEval.m_expr.lhs().innerSize())
261 EIGEN_STRONG_INLINE InnerIterator& operator++()
266 Scalar rhsVal = m_rhsEval.coeff(IsRowMajor?m_lhsIter.outer():m_id,
267 IsRowMajor?m_id:m_lhsIter.outer());
268 if(m_lhsIter && m_lhsIter.index()==m_id)
270 m_value = m_functor(m_lhsIter.value(), rhsVal);
274 m_value = m_functor(Scalar(0),rhsVal);
280 EIGEN_STRONG_INLINE Scalar value()
const { eigen_internal_assert(m_id<m_innerSize);
return m_value; }
282 EIGEN_STRONG_INLINE StorageIndex index()
const {
return m_id; }
283 EIGEN_STRONG_INLINE
Index row()
const {
return IsRowMajor ? m_lhsIter.outer() : m_id; }
284 EIGEN_STRONG_INLINE
Index col()
const {
return IsRowMajor ? m_id : m_lhsIter.outer(); }
286 EIGEN_STRONG_INLINE
operator bool()
const {
return m_id<m_innerSize; }
289 LhsIterator m_lhsIter;
291 const BinaryOp& m_functor;
294 StorageIndex m_innerSize;
306 m_lhsImpl(xpr.
lhs()),
307 m_rhsImpl(xpr.
rhs()),
311 EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
314 inline Index nonZerosEstimate()
const {
315 return m_expr.size();
319 const BinaryOp m_functor;
322 const XprType &m_expr;
332 template<
typename T1,
typename T2,
typename Lhs,
typename Rhs>
341 template<
typename T1,
typename T2,
typename Lhs,
typename Rhs>
350 template<
typename T1,
typename T2,
typename Lhs,
typename Rhs>
360 template<
typename Lhs,
typename Rhs>
369 template<
typename Lhs,
typename Rhs>
378 template<
typename Lhs,
typename Rhs>
388 template<
typename XprType>
393 typedef typename XprType::Functor BinaryOp;
394 typedef typename XprType::Lhs LhsArg;
395 typedef typename XprType::Rhs RhsArg;
398 typedef typename XprType::StorageIndex StorageIndex;
407 : m_lhsIter(aEval.m_lhsImpl,outer), m_rhsIter(aEval.m_rhsImpl,outer), m_functor(aEval.m_functor)
409 while (m_lhsIter && m_rhsIter && (m_lhsIter.index() != m_rhsIter.index()))
411 if (m_lhsIter.index() < m_rhsIter.index())
418 EIGEN_STRONG_INLINE InnerIterator& operator++()
422 while (m_lhsIter && m_rhsIter && (m_lhsIter.index() != m_rhsIter.index()))
424 if (m_lhsIter.index() < m_rhsIter.index())
432 EIGEN_STRONG_INLINE Scalar value()
const {
return m_functor(m_lhsIter.value(), m_rhsIter.value()); }
434 EIGEN_STRONG_INLINE StorageIndex index()
const {
return m_lhsIter.index(); }
435 EIGEN_STRONG_INLINE
Index row()
const {
return m_lhsIter.row(); }
436 EIGEN_STRONG_INLINE
Index col()
const {
return m_lhsIter.col(); }
438 EIGEN_STRONG_INLINE
operator bool()
const {
return (m_lhsIter && m_rhsIter); }
441 LhsIterator m_lhsIter;
442 RhsIterator m_rhsIter;
443 const BinaryOp& m_functor;
449 Flags = XprType::Flags
453 : m_functor(xpr.functor()),
454 m_lhsImpl(xpr.lhs()),
458 EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
461 inline Index nonZerosEstimate()
const {
462 return (std::min)(m_lhsImpl.nonZerosEstimate(), m_rhsImpl.nonZerosEstimate());
466 const BinaryOp m_functor;
472 template<
typename XprType>
477 typedef typename XprType::Functor BinaryOp;
478 typedef typename XprType::Lhs LhsArg;
479 typedef typename XprType::Rhs RhsArg;
482 typedef typename XprType::StorageIndex StorageIndex;
493 : m_lhsEval(aEval.m_lhsImpl), m_rhsIter(aEval.m_rhsImpl,outer), m_functor(aEval.m_functor), m_outer(outer)
496 EIGEN_STRONG_INLINE InnerIterator& operator++()
502 EIGEN_STRONG_INLINE Scalar value()
const 503 {
return m_functor(m_lhsEval.coeff(IsRowMajor?m_outer:m_rhsIter.index(),IsRowMajor?m_rhsIter.index():m_outer), m_rhsIter.value()); }
505 EIGEN_STRONG_INLINE StorageIndex index()
const {
return m_rhsIter.index(); }
506 EIGEN_STRONG_INLINE
Index row()
const {
return m_rhsIter.row(); }
507 EIGEN_STRONG_INLINE
Index col()
const {
return m_rhsIter.col(); }
509 EIGEN_STRONG_INLINE
operator bool()
const {
return m_rhsIter; }
512 const LhsEvaluator &m_lhsEval;
513 RhsIterator m_rhsIter;
514 const BinaryOp& m_functor;
526 : m_functor(xpr.functor()),
527 m_lhsImpl(xpr.lhs()),
531 EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
534 inline Index nonZerosEstimate()
const {
535 return m_rhsImpl.nonZerosEstimate();
539 const BinaryOp m_functor;
545 template<
typename XprType>
550 typedef typename XprType::Functor BinaryOp;
551 typedef typename XprType::Lhs LhsArg;
552 typedef typename XprType::Rhs RhsArg;
555 typedef typename XprType::StorageIndex StorageIndex;
566 : m_lhsIter(aEval.m_lhsImpl,outer), m_rhsEval(aEval.m_rhsImpl), m_functor(aEval.m_functor), m_outer(outer)
569 EIGEN_STRONG_INLINE InnerIterator& operator++()
575 EIGEN_STRONG_INLINE Scalar value()
const 576 {
return m_functor(m_lhsIter.value(),
577 m_rhsEval.coeff(IsRowMajor?m_outer:m_lhsIter.index(),IsRowMajor?m_lhsIter.index():m_outer)); }
579 EIGEN_STRONG_INLINE StorageIndex index()
const {
return m_lhsIter.index(); }
580 EIGEN_STRONG_INLINE
Index row()
const {
return m_lhsIter.row(); }
581 EIGEN_STRONG_INLINE
Index col()
const {
return m_lhsIter.col(); }
583 EIGEN_STRONG_INLINE
operator bool()
const {
return m_lhsIter; }
586 LhsIterator m_lhsIter;
588 const BinaryOp& m_functor;
600 : m_functor(xpr.functor()),
601 m_lhsImpl(xpr.lhs()),
605 EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
608 inline Index nonZerosEstimate()
const {
609 return m_lhsImpl.nonZerosEstimate();
613 const BinaryOp m_functor;
624 template<
typename Derived>
625 template<
typename OtherDerived>
626 EIGEN_STRONG_INLINE Derived &
629 return derived() = derived() - other.derived();
632 template<
typename Derived>
633 template<
typename OtherDerived>
634 EIGEN_STRONG_INLINE Derived &
637 return derived() = derived() + other.derived();
640 template<
typename Derived>
641 template<
typename OtherDerived>
648 template<
typename Derived>
649 template<
typename OtherDerived>
656 template<
typename Derived>
657 template<
typename OtherDerived>
661 return typename CwiseProductDenseReturnType<OtherDerived>::Type(derived(), other.derived());
664 template<
typename DenseDerived,
typename SparseDerived>
668 return CwiseBinaryOp<internal::scalar_sum_op<typename DenseDerived::Scalar,typename SparseDerived::Scalar>,
const DenseDerived,
const SparseDerived>(a.derived(), b.derived());
671 template<
typename SparseDerived,
typename DenseDerived>
675 return CwiseBinaryOp<internal::scalar_sum_op<typename SparseDerived::Scalar,typename DenseDerived::Scalar>,
const SparseDerived,
const DenseDerived>(a.derived(), b.derived());
678 template<
typename DenseDerived,
typename SparseDerived>
682 return CwiseBinaryOp<internal::scalar_difference_op<typename DenseDerived::Scalar,typename SparseDerived::Scalar>,
const DenseDerived,
const SparseDerived>(a.derived(), b.derived());
685 template<
typename SparseDerived,
typename DenseDerived>
689 return CwiseBinaryOp<internal::scalar_difference_op<typename SparseDerived::Scalar,typename DenseDerived::Scalar>,
const SparseDerived,
const DenseDerived>(a.derived(), b.derived());
694 #endif // EIGEN_SPARSE_CWISE_BINARY_OP_H Definition: Constants.h:526
Definition: AssignmentFunctors.h:67
Definition: CoreEvaluators.h:90
Definition: SparseCwiseBinaryOp.h:57
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:85
const unsigned int RowMajorBit
for a matrix, this means that the storage order is row-major.
Definition: Constants.h:61
EIGEN_DEVICE_FUNC const _RhsNested & rhs() const
Definition: CwiseBinaryOp.h:135
Definition: Constants.h:529
Definition: CoreEvaluators.h:109
Definition: CwiseBinaryOp.h:55
Definition: BinaryFunctors.h:389
Definition: BinaryFunctors.h:76
Generic expression where a coefficient-wise binary operator is applied to two expressions.
Definition: CwiseBinaryOp.h:77
Base class of any sparse matrices or sparse expressions.
Definition: ForwardDeclarations.h:281
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:33
The type used to identify a general sparse storage.
Definition: Constants.h:494
Definition: CoreEvaluators.h:61
EIGEN_DEVICE_FUNC const BinaryOp & functor() const
Definition: CwiseBinaryOp.h:138
Definition: BandTriangularSolver.h:13
Definition: XprHelper.h:146
Definition: DiagonalMatrix.h:18
Definition: SparseCwiseBinaryOp.h:329
Definition: AssignmentFunctors.h:46
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48
Definition: ForwardDeclarations.h:17
EIGEN_DEVICE_FUNC const _LhsNested & lhs() const
Definition: CwiseBinaryOp.h:132
An InnerIterator allows to loop over the element of any matrix expression.
Definition: CoreIterators.h:33