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,
const RealScalar& tolerance)
103 : m_lhs(lhs), m_rhs(rhs), m_tolerance(tolerance), m_conservative(false)
108 SparseSparseProduct pruned(
const Scalar& reference = 0,
const RealScalar& epsilon = NumTraits<RealScalar>::dummy_precision())
const
111 return SparseSparseProduct(m_lhs,m_rhs,abs(reference)*epsilon);
114 template<
typename Dest>
115 void evalTo(Dest& result)
const
118 internal::conservative_sparse_sparse_product_selector<_LhsNested, _RhsNested, Dest>::run(lhs(),rhs(),result);
120 internal::sparse_sparse_product_with_pruning_selector<_LhsNested, _RhsNested, Dest>::run(lhs(),rhs(),result,m_tolerance);
123 EIGEN_STRONG_INLINE Index rows()
const {
return m_lhs.rows(); }
124 EIGEN_STRONG_INLINE Index cols()
const {
return m_rhs.cols(); }
126 EIGEN_STRONG_INLINE
const _LhsNested& lhs()
const {
return m_lhs; }
127 EIGEN_STRONG_INLINE
const _RhsNested& rhs()
const {
return m_rhs; }
132 eigen_assert(m_lhs.cols() == m_rhs.rows());
135 ProductIsValid = _LhsNested::ColsAtCompileTime==
Dynamic
136 || _RhsNested::RowsAtCompileTime==
Dynamic
137 || int(_LhsNested::ColsAtCompileTime)==int(_RhsNested::RowsAtCompileTime),
138 AreVectors = _LhsNested::IsVectorAtCompileTime && _RhsNested::IsVectorAtCompileTime,
139 SameSizes = EIGEN_PREDICATE_SAME_MATRIX_SIZE(_LhsNested,_RhsNested)
144 EIGEN_STATIC_ASSERT(ProductIsValid || !(AreVectors && SameSizes),
145 INVALID_VECTOR_VECTOR_PRODUCT__IF_YOU_WANTED_A_DOT_OR_COEFF_WISE_PRODUCT_YOU_MUST_USE_THE_EXPLICIT_FUNCTIONS)
146 EIGEN_STATIC_ASSERT(ProductIsValid || !(SameSizes && !AreVectors),
147 INVALID_MATRIX_PRODUCT__IF_YOU_WANTED_A_COEFF_WISE_PRODUCT_YOU_MUST_USE_THE_EXPLICIT_FUNCTION)
148 EIGEN_STATIC_ASSERT(ProductIsValid || SameSizes, INVALID_MATRIX_PRODUCT)
153 RealScalar m_tolerance;
158 template<typename Derived>
159 template<typename Lhs, typename Rhs>
160 inline Derived& SparseMatrixBase<Derived>::operator=(const SparseSparseProduct<Lhs,Rhs>& product)
162 product.evalTo(derived());
177 template<
typename Derived>
178 template<
typename OtherDerived>
179 inline const typename SparseSparseProductReturnType<Derived,OtherDerived>::Type
182 return typename SparseSparseProductReturnType<Derived,OtherDerived>::Type(derived(), other.
derived());
187 #endif // EIGEN_SPARSEPRODUCT_H