Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef EIGEN_SPARSEPRODUCT_H
00026 #define EIGEN_SPARSEPRODUCT_H
00027
00028 template<typename Lhs, typename Rhs>
00029 struct SparseSparseProductReturnType
00030 {
00031 typedef typename internal::traits<Lhs>::Scalar Scalar;
00032 enum {
00033 LhsRowMajor = internal::traits<Lhs>::Flags & RowMajorBit,
00034 RhsRowMajor = internal::traits<Rhs>::Flags & RowMajorBit,
00035 TransposeRhs = (!LhsRowMajor) && RhsRowMajor,
00036 TransposeLhs = LhsRowMajor && (!RhsRowMajor)
00037 };
00038
00039 typedef typename internal::conditional<TransposeLhs,
00040 SparseMatrix<Scalar,0>,
00041 const typename internal::nested<Lhs,Rhs::RowsAtCompileTime>::type>::type LhsNested;
00042
00043 typedef typename internal::conditional<TransposeRhs,
00044 SparseMatrix<Scalar,0>,
00045 const typename internal::nested<Rhs,Lhs::RowsAtCompileTime>::type>::type RhsNested;
00046
00047 typedef SparseSparseProduct<LhsNested, RhsNested> Type;
00048 };
00049
00050 namespace internal {
00051 template<typename LhsNested, typename RhsNested>
00052 struct traits<SparseSparseProduct<LhsNested, RhsNested> >
00053 {
00054 typedef MatrixXpr XprKind;
00055
00056 typedef typename remove_all<LhsNested>::type _LhsNested;
00057 typedef typename remove_all<RhsNested>::type _RhsNested;
00058 typedef typename _LhsNested::Scalar Scalar;
00059 typedef typename promote_index_type<typename traits<_LhsNested>::Index,
00060 typename traits<_RhsNested>::Index>::type Index;
00061
00062 enum {
00063 LhsCoeffReadCost = _LhsNested::CoeffReadCost,
00064 RhsCoeffReadCost = _RhsNested::CoeffReadCost,
00065 LhsFlags = _LhsNested::Flags,
00066 RhsFlags = _RhsNested::Flags,
00067
00068 RowsAtCompileTime = _LhsNested::RowsAtCompileTime,
00069 ColsAtCompileTime = _RhsNested::ColsAtCompileTime,
00070 MaxRowsAtCompileTime = _LhsNested::MaxRowsAtCompileTime,
00071 MaxColsAtCompileTime = _RhsNested::MaxColsAtCompileTime,
00072
00073 InnerSize = EIGEN_SIZE_MIN_PREFER_FIXED(_LhsNested::ColsAtCompileTime, _RhsNested::RowsAtCompileTime),
00074
00075 EvalToRowMajor = (RhsFlags & LhsFlags & RowMajorBit),
00076
00077 RemovedBits = ~(EvalToRowMajor ? 0 : RowMajorBit),
00078
00079 Flags = (int(LhsFlags | RhsFlags) & HereditaryBits & RemovedBits)
00080 | EvalBeforeAssigningBit
00081 | EvalBeforeNestingBit,
00082
00083 CoeffReadCost = Dynamic
00084 };
00085
00086 typedef Sparse StorageKind;
00087 };
00088
00089 }
00090
00091 template<typename LhsNested, typename RhsNested>
00092 class SparseSparseProduct : internal::no_assignment_operator,
00093 public SparseMatrixBase<SparseSparseProduct<LhsNested, RhsNested> >
00094 {
00095 public:
00096
00097 typedef SparseMatrixBase<SparseSparseProduct> Base;
00098 EIGEN_DENSE_PUBLIC_INTERFACE(SparseSparseProduct)
00099
00100 private:
00101
00102 typedef typename internal::traits<SparseSparseProduct>::_LhsNested _LhsNested;
00103 typedef typename internal::traits<SparseSparseProduct>::_RhsNested _RhsNested;
00104
00105 public:
00106
00107 template<typename Lhs, typename Rhs>
00108 EIGEN_STRONG_INLINE SparseSparseProduct(const Lhs& lhs, const Rhs& rhs)
00109 : m_lhs(lhs), m_rhs(rhs)
00110 {
00111 eigen_assert(lhs.cols() == rhs.rows());
00112
00113 enum {
00114 ProductIsValid = _LhsNested::ColsAtCompileTime==Dynamic
00115 || _RhsNested::RowsAtCompileTime==Dynamic
00116 || int(_LhsNested::ColsAtCompileTime)==int(_RhsNested::RowsAtCompileTime),
00117 AreVectors = _LhsNested::IsVectorAtCompileTime && _RhsNested::IsVectorAtCompileTime,
00118 SameSizes = EIGEN_PREDICATE_SAME_MATRIX_SIZE(_LhsNested,_RhsNested)
00119 };
00120
00121
00122
00123 EIGEN_STATIC_ASSERT(ProductIsValid || !(AreVectors && SameSizes),
00124 INVALID_VECTOR_VECTOR_PRODUCT__IF_YOU_WANTED_A_DOT_OR_COEFF_WISE_PRODUCT_YOU_MUST_USE_THE_EXPLICIT_FUNCTIONS)
00125 EIGEN_STATIC_ASSERT(ProductIsValid || !(SameSizes && !AreVectors),
00126 INVALID_MATRIX_PRODUCT__IF_YOU_WANTED_A_COEFF_WISE_PRODUCT_YOU_MUST_USE_THE_EXPLICIT_FUNCTION)
00127 EIGEN_STATIC_ASSERT(ProductIsValid || SameSizes, INVALID_MATRIX_PRODUCT)
00128 }
00129
00130 EIGEN_STRONG_INLINE Index rows() const { return m_lhs.rows(); }
00131 EIGEN_STRONG_INLINE Index cols() const { return m_rhs.cols(); }
00132
00133 EIGEN_STRONG_INLINE const _LhsNested& lhs() const { return m_lhs; }
00134 EIGEN_STRONG_INLINE const _RhsNested& rhs() const { return m_rhs; }
00135
00136 protected:
00137 LhsNested m_lhs;
00138 RhsNested m_rhs;
00139 };
00140
00141 #endif // EIGEN_SPARSEPRODUCT_H