10#ifndef EIGEN_SPARSE_CWISE_BINARY_OP_H
11#define EIGEN_SPARSE_CWISE_BINARY_OP_H
32template<
typename BinaryOp,
typename Lhs,
typename Rhs>
39 EIGEN_SPARSE_PUBLIC_INTERFACE(
Derived)
46 THE_STORAGE_ORDER_OF_BOTH_SIDES_MUST_MATCH);
52template<
typename BinaryOp,
typename Lhs,
typename Rhs,
typename Derived,
63template<
typename BinaryOp,
typename Lhs,
typename Rhs>
72 typedef typename XprType::StorageIndex StorageIndex;
75 class ReverseInnerIterator;
81 : m_lhsIter(
aEval.m_lhsImpl,outer), m_rhsIter(
aEval.m_rhsImpl,outer), m_functor(
aEval.m_functor)
88 if (m_lhsIter && m_rhsIter && (m_lhsIter.index() == m_rhsIter.index()))
90 m_id = m_lhsIter.
index();
91 m_value = m_functor(m_lhsIter.value(), m_rhsIter.value());
95 else if (m_lhsIter && (!m_rhsIter || (m_lhsIter.index() < m_rhsIter.index())))
97 m_id = m_lhsIter.index();
98 m_value = m_functor(m_lhsIter.value(),
Scalar(0));
101 else if (m_rhsIter && (!m_lhsIter || (m_lhsIter.index() > m_rhsIter.index())))
103 m_id = m_rhsIter.index();
104 m_value = m_functor(
Scalar(0), m_rhsIter.value());
115 EIGEN_STRONG_INLINE
Scalar value()
const {
return m_value; }
117 EIGEN_STRONG_INLINE StorageIndex index()
const {
return m_id; }
118 EIGEN_STRONG_INLINE Index row()
const {
return Lhs::IsRowMajor ? m_lhsIter.row() : index(); }
119 EIGEN_STRONG_INLINE Index col()
const {
return Lhs::IsRowMajor ? index() : m_lhsIter.col(); }
121 EIGEN_STRONG_INLINE
operator bool()
const {
return m_id>=0; }
126 const BinaryOp& m_functor;
134 Flags = XprType::Flags
138 : m_functor(
xpr.functor()),
139 m_lhsImpl(
xpr.lhs()),
143 EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
146 inline Index nonZerosEstimate()
const {
147 return m_lhsImpl.nonZerosEstimate() + m_rhsImpl.nonZerosEstimate();
151 const BinaryOp m_functor;
152 evaluator<Lhs> m_lhsImpl;
153 evaluator<Rhs> m_rhsImpl;
157template<
typename T,
typename Lhs,
typename Rhs>
166 typedef typename XprType::StorageIndex StorageIndex;
170 class ReverseInnerIterator;
176 : m_lhsIter(
aEval.m_lhsImpl,outer), m_rhsIter(
aEval.m_rhsImpl,outer), m_functor(
aEval.m_functor)
178 while (m_lhsIter && m_rhsIter && (m_lhsIter.index() != m_rhsIter.index()))
180 if (m_lhsIter.index() < m_rhsIter.index())
191 while (m_lhsIter && m_rhsIter && (m_lhsIter.index() != m_rhsIter.index()))
193 if (m_lhsIter.index() < m_rhsIter.index())
201 EIGEN_STRONG_INLINE
Scalar value()
const {
return m_functor(m_lhsIter.value(), m_rhsIter.value()); }
203 EIGEN_STRONG_INLINE StorageIndex index()
const {
return m_lhsIter.index(); }
204 EIGEN_STRONG_INLINE Index row()
const {
return m_lhsIter.row(); }
205 EIGEN_STRONG_INLINE Index col()
const {
return m_lhsIter.col(); }
207 EIGEN_STRONG_INLINE
operator bool()
const {
return (m_lhsIter && m_rhsIter); }
218 Flags = XprType::Flags
222 : m_functor(
xpr.functor()),
223 m_lhsImpl(
xpr.lhs()),
227 EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
230 inline Index nonZerosEstimate()
const {
231 return (std::min)(m_lhsImpl.nonZerosEstimate(), m_rhsImpl.nonZerosEstimate());
235 const BinaryOp m_functor;
236 evaluator<Lhs> m_lhsImpl;
237 evaluator<Rhs> m_rhsImpl;
241template<
typename T,
typename Lhs,
typename Rhs>
250 typedef typename XprType::StorageIndex StorageIndex;
254 class ReverseInnerIterator;
262 : m_lhsEval(
aEval.m_lhsImpl), m_rhsIter(
aEval.m_rhsImpl,outer), m_functor(
aEval.m_functor), m_outer(outer)
271 EIGEN_STRONG_INLINE
Scalar value()
const
272 {
return m_functor(m_lhsEval.coeff(IsRowMajor?m_outer:m_rhsIter.index(),IsRowMajor?m_rhsIter.index():m_outer), m_rhsIter.value()); }
274 EIGEN_STRONG_INLINE StorageIndex index()
const {
return m_rhsIter.index(); }
275 EIGEN_STRONG_INLINE Index row()
const {
return m_rhsIter.row(); }
276 EIGEN_STRONG_INLINE Index col()
const {
return m_rhsIter.col(); }
278 EIGEN_STRONG_INLINE
operator bool()
const {
return m_rhsIter; }
290 Flags = XprType::Flags
294 : m_functor(
xpr.functor()),
295 m_lhsImpl(
xpr.lhs()),
299 EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
302 inline Index nonZerosEstimate()
const {
303 return m_rhsImpl.nonZerosEstimate();
307 const BinaryOp m_functor;
308 evaluator<Lhs> m_lhsImpl;
309 evaluator<Rhs> m_rhsImpl;
313template<
typename T,
typename Lhs,
typename Rhs>
322 typedef typename XprType::StorageIndex StorageIndex;
326 class ReverseInnerIterator;
334 : m_lhsIter(
aEval.m_lhsImpl,outer), m_rhsEval(
aEval.m_rhsImpl), m_functor(
aEval.m_functor), m_outer(outer)
343 EIGEN_STRONG_INLINE
Scalar value()
const
344 {
return m_functor(m_lhsIter.value(),
345 m_rhsEval.coeff(IsRowMajor?m_outer:m_lhsIter.index(),IsRowMajor?m_lhsIter.index():m_outer)); }
347 EIGEN_STRONG_INLINE StorageIndex index()
const {
return m_lhsIter.index(); }
348 EIGEN_STRONG_INLINE Index row()
const {
return m_lhsIter.row(); }
349 EIGEN_STRONG_INLINE Index col()
const {
return m_lhsIter.col(); }
351 EIGEN_STRONG_INLINE
operator bool()
const {
return m_lhsIter; }
363 Flags = XprType::Flags
367 : m_functor(
xpr.functor()),
368 m_lhsImpl(
xpr.lhs()),
372 EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
375 inline Index nonZerosEstimate()
const {
376 return m_lhsImpl.nonZerosEstimate();
380 const BinaryOp m_functor;
381 evaluator<Lhs> m_lhsImpl;
382 evaluator<Rhs> m_rhsImpl;
391template<
typename Derived>
392template<
typename OtherDerived>
393EIGEN_STRONG_INLINE Derived &
394SparseMatrixBase<Derived>::operator-=(
const SparseMatrixBase<OtherDerived> &other)
396 return derived() = derived() - other.derived();
399template<
typename Derived>
400template<
typename OtherDerived>
401EIGEN_STRONG_INLINE Derived &
402SparseMatrixBase<Derived>::operator+=(
const SparseMatrixBase<OtherDerived>& other)
404 return derived() = derived() + other.derived();
407template<
typename Derived>
408template<
typename OtherDerived>
409Derived& SparseMatrixBase<Derived>::operator+=(
const DiagonalBase<OtherDerived>& other)
411 call_assignment_no_alias(derived(), other.derived(), internal::add_assign_op<Scalar>());
415template<
typename Derived>
416template<
typename OtherDerived>
417Derived& SparseMatrixBase<Derived>::operator-=(
const DiagonalBase<OtherDerived>& other)
419 call_assignment_no_alias(derived(), other.derived(), internal::sub_assign_op<Scalar>());
423template<
typename Derived>
424template<
typename OtherDerived>
425EIGEN_STRONG_INLINE
const typename SparseMatrixBase<Derived>::template CwiseProductDenseReturnType<OtherDerived>::Type
426SparseMatrixBase<Derived>::cwiseProduct(
const MatrixBase<OtherDerived> &other)
const
428 return typename CwiseProductDenseReturnType<OtherDerived>::Type(derived(), other.derived());
Definition CwiseBinaryOp.h:150
Generic expression where a coefficient-wise binary operator is applied to two expressions.
Definition CwiseBinaryOp.h:85
An InnerIterator allows to loop over the element of any matrix expression.
Definition CoreIterators.h:34
EIGEN_STRONG_INLINE Index index() const
Definition CoreIterators.h:52
Pseudo expression representing a solving operation.
Definition Solve.h:63
Base class of any sparse matrices or sparse expressions.
Definition SparseMatrixBase.h:34
Definition SparseCwiseBinaryOp.h:55
const unsigned int RowMajorBit
for a matrix, this means that the storage order is row-major.
Definition Constants.h:61
The type used to identify a general sparse storage.
Definition Constants.h:493
Definition Constants.h:525
Definition Constants.h:528
Definition CoreEvaluators.h:52
Definition CoreEvaluators.h:101
Definition CoreEvaluators.h:82
Definition XprHelper.h:107
Definition BinaryFunctors.h:59
Definition ForwardDeclarations.h:17