10 #ifndef EIGEN_SPARSEPRODUCT_H
11 #define EIGEN_SPARSEPRODUCT_H
15 template<
typename Lhs,
typename Rhs>
16 struct SparseSparseProductReturnType
18 typedef typename internal::traits<Lhs>::Scalar Scalar;
19 typedef typename internal::traits<Lhs>::Index Index;
21 LhsRowMajor = internal::traits<Lhs>::Flags &
RowMajorBit,
22 RhsRowMajor = internal::traits<Rhs>::Flags &
RowMajorBit,
23 TransposeRhs = (!LhsRowMajor) && RhsRowMajor,
24 TransposeLhs = LhsRowMajor && (!RhsRowMajor)
27 typedef typename internal::conditional<TransposeLhs,
28 SparseMatrix<Scalar,0,Index>,
29 typename internal::nested<Lhs,Rhs::RowsAtCompileTime>::type>::type LhsNested;
31 typedef typename internal::conditional<TransposeRhs,
32 SparseMatrix<Scalar,0,Index>,
33 typename internal::nested<Rhs,Lhs::RowsAtCompileTime>::type>::type RhsNested;
35 typedef SparseSparseProduct<LhsNested, RhsNested> Type;
39 template<
typename LhsNested,
typename RhsNested>
40 struct traits<SparseSparseProduct<LhsNested, RhsNested> >
42 typedef MatrixXpr XprKind;
44 typedef typename remove_all<LhsNested>::type _LhsNested;
45 typedef typename remove_all<RhsNested>::type _RhsNested;
46 typedef typename _LhsNested::Scalar Scalar;
47 typedef typename promote_index_type<typename traits<_LhsNested>::Index,
48 typename traits<_RhsNested>::Index>::type Index;
51 LhsCoeffReadCost = _LhsNested::CoeffReadCost,
52 RhsCoeffReadCost = _RhsNested::CoeffReadCost,
53 LhsFlags = _LhsNested::Flags,
54 RhsFlags = _RhsNested::Flags,
56 RowsAtCompileTime = _LhsNested::RowsAtCompileTime,
57 ColsAtCompileTime = _RhsNested::ColsAtCompileTime,
58 MaxRowsAtCompileTime = _LhsNested::MaxRowsAtCompileTime,
59 MaxColsAtCompileTime = _RhsNested::MaxColsAtCompileTime,
61 InnerSize = EIGEN_SIZE_MIN_PREFER_FIXED(_LhsNested::ColsAtCompileTime, _RhsNested::RowsAtCompileTime),
63 EvalToRowMajor = (RhsFlags & LhsFlags &
RowMajorBit),
67 Flags = (int(LhsFlags | RhsFlags) & HereditaryBits & RemovedBits)
74 typedef Sparse StorageKind;
79 template<
typename LhsNested,
typename RhsNested>
80 class SparseSparseProduct : internal::no_assignment_operator,
81 public SparseMatrixBase<SparseSparseProduct<LhsNested, RhsNested> >
85 typedef SparseMatrixBase<SparseSparseProduct> Base;
86 EIGEN_DENSE_PUBLIC_INTERFACE(SparseSparseProduct)
90 typedef typename internal::traits<SparseSparseProduct>::_LhsNested _LhsNested;
91 typedef typename internal::traits<SparseSparseProduct>::_RhsNested _RhsNested;
95 template<typename Lhs, typename Rhs>
96 EIGEN_STRONG_INLINE SparseSparseProduct(const Lhs& lhs, const Rhs& rhs)
97 : m_lhs(lhs), m_rhs(rhs), m_tolerance(0), m_conservative(true)
102 template<
typename Lhs,
typename Rhs>
103 EIGEN_STRONG_INLINE SparseSparseProduct(
const Lhs& lhs,
const Rhs& rhs,
const RealScalar& tolerance)
104 : m_lhs(lhs), m_rhs(rhs), m_tolerance(tolerance), m_conservative(false)
109 SparseSparseProduct pruned(
const Scalar& reference = 0,
const RealScalar& epsilon = NumTraits<RealScalar>::dummy_precision())
const
112 return SparseSparseProduct(m_lhs,m_rhs,abs(reference)*epsilon);
115 template<
typename Dest>
116 void evalTo(Dest& result)
const
119 internal::conservative_sparse_sparse_product_selector<_LhsNested, _RhsNested, Dest>::run(lhs(),rhs(),result);
121 internal::sparse_sparse_product_with_pruning_selector<_LhsNested, _RhsNested, Dest>::run(lhs(),rhs(),result,m_tolerance);
124 EIGEN_STRONG_INLINE Index rows()
const {
return m_lhs.rows(); }
125 EIGEN_STRONG_INLINE Index cols()
const {
return m_rhs.cols(); }
127 EIGEN_STRONG_INLINE
const _LhsNested& lhs()
const {
return m_lhs; }
128 EIGEN_STRONG_INLINE
const _RhsNested& rhs()
const {
return m_rhs; }
133 eigen_assert(m_lhs.cols() == m_rhs.rows());
136 ProductIsValid = _LhsNested::ColsAtCompileTime==
Dynamic
137 || _RhsNested::RowsAtCompileTime==
Dynamic
138 || int(_LhsNested::ColsAtCompileTime)==int(_RhsNested::RowsAtCompileTime),
139 AreVectors = _LhsNested::IsVectorAtCompileTime && _RhsNested::IsVectorAtCompileTime,
140 SameSizes = EIGEN_PREDICATE_SAME_MATRIX_SIZE(_LhsNested,_RhsNested)
145 EIGEN_STATIC_ASSERT(ProductIsValid || !(AreVectors && SameSizes),
146 INVALID_VECTOR_VECTOR_PRODUCT__IF_YOU_WANTED_A_DOT_OR_COEFF_WISE_PRODUCT_YOU_MUST_USE_THE_EXPLICIT_FUNCTIONS)
147 EIGEN_STATIC_ASSERT(ProductIsValid || !(SameSizes && !AreVectors),
148 INVALID_MATRIX_PRODUCT__IF_YOU_WANTED_A_COEFF_WISE_PRODUCT_YOU_MUST_USE_THE_EXPLICIT_FUNCTION)
149 EIGEN_STATIC_ASSERT(ProductIsValid || SameSizes, INVALID_MATRIX_PRODUCT)
154 RealScalar m_tolerance;
159 template<typename Derived>
160 template<typename Lhs, typename Rhs>
161 inline Derived& SparseMatrixBase<Derived>::operator=(const SparseSparseProduct<Lhs,Rhs>& product)
163 product.evalTo(derived());
178 template<
typename Derived>
179 template<
typename OtherDerived>
180 inline const typename SparseSparseProductReturnType<Derived,OtherDerived>::Type
183 return typename SparseSparseProductReturnType<Derived,OtherDerived>::Type(derived(), other.
derived());
188 #endif // EIGEN_SPARSEPRODUCT_H
const unsigned int EvalBeforeNestingBit
Definition: Constants.h:58
const int Dynamic
Definition: Constants.h:21
Base class of any sparse matrices or sparse expressions.
Definition: ForwardDeclarations.h:239
Derived & derived()
Definition: EigenBase.h:34
const ScalarMultipleReturnType operator*(const Scalar &scalar) const
Definition: SparseMatrixBase.h:50
const unsigned int EvalBeforeAssigningBit
Definition: Constants.h:63
const unsigned int RowMajorBit
Definition: Constants.h:53