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;
20 LhsRowMajor = internal::traits<Lhs>::Flags &
RowMajorBit,
21 RhsRowMajor = internal::traits<Rhs>::Flags &
RowMajorBit,
22 TransposeRhs = (!LhsRowMajor) && RhsRowMajor,
23 TransposeLhs = LhsRowMajor && (!RhsRowMajor)
26 typedef typename internal::conditional<TransposeLhs,
27 SparseMatrix<Scalar,0>,
28 typename internal::nested<Lhs,Rhs::RowsAtCompileTime>::type>::type LhsNested;
30 typedef typename internal::conditional<TransposeRhs,
31 SparseMatrix<Scalar,0>,
32 typename internal::nested<Rhs,Lhs::RowsAtCompileTime>::type>::type RhsNested;
34 typedef SparseSparseProduct<LhsNested, RhsNested> Type;
38 template<
typename LhsNested,
typename RhsNested>
39 struct traits<SparseSparseProduct<LhsNested, RhsNested> >
41 typedef MatrixXpr XprKind;
43 typedef typename remove_all<LhsNested>::type _LhsNested;
44 typedef typename remove_all<RhsNested>::type _RhsNested;
45 typedef typename _LhsNested::Scalar Scalar;
46 typedef typename promote_index_type<typename traits<_LhsNested>::Index,
47 typename traits<_RhsNested>::Index>::type Index;
50 LhsCoeffReadCost = _LhsNested::CoeffReadCost,
51 RhsCoeffReadCost = _RhsNested::CoeffReadCost,
52 LhsFlags = _LhsNested::Flags,
53 RhsFlags = _RhsNested::Flags,
55 RowsAtCompileTime = _LhsNested::RowsAtCompileTime,
56 ColsAtCompileTime = _RhsNested::ColsAtCompileTime,
57 MaxRowsAtCompileTime = _LhsNested::MaxRowsAtCompileTime,
58 MaxColsAtCompileTime = _RhsNested::MaxColsAtCompileTime,
60 InnerSize = EIGEN_SIZE_MIN_PREFER_FIXED(_LhsNested::ColsAtCompileTime, _RhsNested::RowsAtCompileTime),
62 EvalToRowMajor = (RhsFlags & LhsFlags &
RowMajorBit),
66 Flags = (int(LhsFlags | RhsFlags) & HereditaryBits & RemovedBits)
73 typedef Sparse StorageKind;
78 template<
typename LhsNested,
typename RhsNested>
79 class SparseSparseProduct : internal::no_assignment_operator,
80 public SparseMatrixBase<SparseSparseProduct<LhsNested, RhsNested> >
84 typedef SparseMatrixBase<SparseSparseProduct> Base;
85 EIGEN_DENSE_PUBLIC_INTERFACE(SparseSparseProduct)
89 typedef typename internal::traits<SparseSparseProduct>::_LhsNested _LhsNested;
90 typedef typename internal::traits<SparseSparseProduct>::_RhsNested _RhsNested;
94 template<typename Lhs, typename Rhs>
95 EIGEN_STRONG_INLINE SparseSparseProduct(const Lhs& lhs, const Rhs& rhs)
96 : m_lhs(lhs), m_rhs(rhs), m_tolerance(0), m_conservative(true)
101 template<
typename Lhs,
typename Rhs>
102 EIGEN_STRONG_INLINE SparseSparseProduct(
const Lhs& lhs,
const Rhs& rhs, RealScalar tolerance)
103 : m_lhs(lhs), m_rhs(rhs), m_tolerance(tolerance), m_conservative(false)
108 SparseSparseProduct pruned(Scalar reference = 0, RealScalar epsilon = NumTraits<RealScalar>::dummy_precision())
const
110 return SparseSparseProduct(m_lhs,m_rhs,internal::abs(reference)*epsilon);
113 template<
typename Dest>
114 void evalTo(Dest& result)
const
117 internal::conservative_sparse_sparse_product_selector<_LhsNested, _RhsNested, Dest>::run(lhs(),rhs(),result);
119 internal::sparse_sparse_product_with_pruning_selector<_LhsNested, _RhsNested, Dest>::run(lhs(),rhs(),result,m_tolerance);
122 EIGEN_STRONG_INLINE Index rows()
const {
return m_lhs.rows(); }
123 EIGEN_STRONG_INLINE Index cols()
const {
return m_rhs.cols(); }
125 EIGEN_STRONG_INLINE
const _LhsNested& lhs()
const {
return m_lhs; }
126 EIGEN_STRONG_INLINE
const _RhsNested& rhs()
const {
return m_rhs; }
131 eigen_assert(m_lhs.cols() == m_rhs.rows());
134 ProductIsValid = _LhsNested::ColsAtCompileTime==
Dynamic
135 || _RhsNested::RowsAtCompileTime==
Dynamic
136 || int(_LhsNested::ColsAtCompileTime)==int(_RhsNested::RowsAtCompileTime),
137 AreVectors = _LhsNested::IsVectorAtCompileTime && _RhsNested::IsVectorAtCompileTime,
138 SameSizes = EIGEN_PREDICATE_SAME_MATRIX_SIZE(_LhsNested,_RhsNested)
143 EIGEN_STATIC_ASSERT(ProductIsValid || !(AreVectors && SameSizes),
144 INVALID_VECTOR_VECTOR_PRODUCT__IF_YOU_WANTED_A_DOT_OR_COEFF_WISE_PRODUCT_YOU_MUST_USE_THE_EXPLICIT_FUNCTIONS)
145 EIGEN_STATIC_ASSERT(ProductIsValid || !(SameSizes && !AreVectors),
146 INVALID_MATRIX_PRODUCT__IF_YOU_WANTED_A_COEFF_WISE_PRODUCT_YOU_MUST_USE_THE_EXPLICIT_FUNCTION)
147 EIGEN_STATIC_ASSERT(ProductIsValid || SameSizes, INVALID_MATRIX_PRODUCT)
152 RealScalar m_tolerance;
157 template<typename Derived>
158 template<typename Lhs, typename Rhs>
159 inline Derived& SparseMatrixBase<Derived>::operator=(const SparseSparseProduct<Lhs,Rhs>& product)
161 product.evalTo(derived());
176 template<
typename Derived>
177 template<
typename OtherDerived>
178 inline const typename SparseSparseProductReturnType<Derived,OtherDerived>::Type
181 return typename SparseSparseProductReturnType<Derived,OtherDerived>::Type(derived(), other.
derived());
186 #endif // EIGEN_SPARSEPRODUCT_H