aboutsummaryrefslogtreecommitdiffhomepage
path: root/Eigen/src/Sparse/SparseProduct.h
diff options
context:
space:
mode:
authorGravatar Gael Guennebaud <g.gael@free.fr>2009-01-14 14:24:10 +0000
committerGravatar Gael Guennebaud <g.gael@free.fr>2009-01-14 14:24:10 +0000
commitc4c70669d165afefe0c68e7bb194ee81b9fba0b5 (patch)
tree37793f68813b629ecc0a3067dc0609d6ea873738 /Eigen/src/Sparse/SparseProduct.h
parentee87f5ee49f23179a07c8486cc9c0ebcf6e947d6 (diff)
Big rewrite in the Sparse module: SparseMatrixBase no longer inherits MatrixBase.
That means a lot of features which were available for sparse matrices via the dense (and super slow) implemention are no longer available. All features which make sense for sparse matrices (aka can be implemented efficiently) will be implemented soon, but don't expect to see an API as rich as for the dense path. Other changes: * no block(), row(), col() anymore. * instead use .innerVector() to get a col or row vector of a matrix. * .segment(), start(), end() will be back soon, not sure for block() * faster cwise product
Diffstat (limited to 'Eigen/src/Sparse/SparseProduct.h')
-rw-r--r--Eigen/src/Sparse/SparseProduct.h68
1 files changed, 44 insertions, 24 deletions
diff --git a/Eigen/src/Sparse/SparseProduct.h b/Eigen/src/Sparse/SparseProduct.h
index 36dfb31ac..b4ba2ee6f 100644
--- a/Eigen/src/Sparse/SparseProduct.h
+++ b/Eigen/src/Sparse/SparseProduct.h
@@ -27,7 +27,7 @@
// sparse product return type specialization
template<typename Lhs, typename Rhs>
-struct ProductReturnType<Lhs,Rhs,SparseProduct>
+struct SparseProductReturnType
{
typedef typename ei_traits<Lhs>::Scalar Scalar;
enum {
@@ -47,12 +47,11 @@ struct ProductReturnType<Lhs,Rhs,SparseProduct>
SparseMatrix<Scalar,0>,
const typename ei_nested<Rhs,Lhs::RowsAtCompileTime>::type>::ret RhsNested;
- typedef Product<LhsNested,
- RhsNested, SparseProduct> Type;
+ typedef SparseProduct<LhsNested, RhsNested> Type;
};
template<typename LhsNested, typename RhsNested>
-struct ei_traits<Product<LhsNested, RhsNested, SparseProduct> >
+struct ei_traits<SparseProduct<LhsNested, RhsNested> >
{
// clean the nested types:
typedef typename ei_cleantype<LhsNested>::type _LhsNested;
@@ -87,30 +86,28 @@ struct ei_traits<Product<LhsNested, RhsNested, SparseProduct> >
};
};
-template<typename LhsNested, typename RhsNested> class Product<LhsNested,RhsNested,SparseProduct> : ei_no_assignment_operator,
- public MatrixBase<Product<LhsNested, RhsNested, SparseProduct> >
+template<typename LhsNested, typename RhsNested>
+class SparseProduct : ei_no_assignment_operator,
+ public SparseMatrixBase<SparseProduct<LhsNested, RhsNested> >
{
public:
- EIGEN_GENERIC_PUBLIC_INTERFACE(Product)
+ EIGEN_GENERIC_PUBLIC_INTERFACE(SparseProduct)
private:
- typedef typename ei_traits<Product>::_LhsNested _LhsNested;
- typedef typename ei_traits<Product>::_RhsNested _RhsNested;
+ typedef typename ei_traits<SparseProduct>::_LhsNested _LhsNested;
+ typedef typename ei_traits<SparseProduct>::_RhsNested _RhsNested;
public:
template<typename Lhs, typename Rhs>
- inline Product(const Lhs& lhs, const Rhs& rhs)
+ inline SparseProduct(const Lhs& lhs, const Rhs& rhs)
: m_lhs(lhs), m_rhs(rhs)
{
ei_assert(lhs.cols() == rhs.rows());
}
- Scalar coeff(int, int) const { ei_assert(false && "eigen internal error"); }
- Scalar& coeffRef(int, int) { ei_assert(false && "eigen internal error"); }
-
inline int rows() const { return m_lhs.rows(); }
inline int cols() const { return m_rhs.cols(); }
@@ -231,28 +228,51 @@ struct ei_sparse_product_selector<Lhs,Rhs,ResultType,RowMajor,RowMajor,ColMajor>
// by ProductReturnType which transform it to (col col *) by evaluating rhs.
+// template<typename Derived>
+// template<typename Lhs, typename Rhs>
+// inline Derived& SparseMatrixBase<Derived>::lazyAssign(const SparseProduct<Lhs,Rhs>& product)
+// {
+// // std::cout << "sparse product to dense\n";
+// ei_sparse_product_selector<
+// typename ei_cleantype<Lhs>::type,
+// typename ei_cleantype<Rhs>::type,
+// typename ei_cleantype<Derived>::type>::run(product.lhs(),product.rhs(),derived());
+// return derived();
+// }
+
template<typename Derived>
template<typename Lhs, typename Rhs>
-inline Derived& MatrixBase<Derived>::lazyAssign(const Product<Lhs,Rhs,SparseProduct>& product)
+inline Derived& SparseMatrixBase<Derived>::operator=(const SparseProduct<Lhs,Rhs>& product)
{
-// std::cout << "sparse product to dense\n";
+// std::cout << "sparse product to sparse\n";
ei_sparse_product_selector<
typename ei_cleantype<Lhs>::type,
typename ei_cleantype<Rhs>::type,
- typename ei_cleantype<Derived>::type>::run(product.lhs(),product.rhs(),derived());
+ Derived>::run(product.lhs(),product.rhs(),derived());
return derived();
}
template<typename Derived>
-template<typename Lhs, typename Rhs>
-inline Derived& SparseMatrixBase<Derived>::operator=(const Product<Lhs,Rhs,SparseProduct>& product)
+template<typename OtherDerived>
+inline const typename SparseProductReturnType<Derived,OtherDerived>::Type
+SparseMatrixBase<Derived>::operator*(const SparseMatrixBase<OtherDerived> &other) const
{
-// std::cout << "sparse product to sparse\n";
- ei_sparse_product_selector<
- typename ei_cleantype<Lhs>::type,
- typename ei_cleantype<Rhs>::type,
- Derived>::run(product.lhs(),product.rhs(),derived());
- return derived();
+ enum {
+ ProductIsValid = Derived::ColsAtCompileTime==Dynamic
+ || OtherDerived::RowsAtCompileTime==Dynamic
+ || int(Derived::ColsAtCompileTime)==int(OtherDerived::RowsAtCompileTime),
+ AreVectors = Derived::IsVectorAtCompileTime && OtherDerived::IsVectorAtCompileTime,
+ SameSizes = EIGEN_PREDICATE_SAME_MATRIX_SIZE(Derived,OtherDerived)
+ };
+ // note to the lost user:
+ // * for a dot product use: v1.dot(v2)
+ // * for a coeff-wise product use: v1.cwise()*v2
+ EIGEN_STATIC_ASSERT(ProductIsValid || !(AreVectors && SameSizes),
+ INVALID_VECTOR_VECTOR_PRODUCT__IF_YOU_WANTED_A_DOT_OR_COEFF_WISE_PRODUCT_YOU_MUST_USE_THE_EXPLICIT_FUNCTIONS)
+ EIGEN_STATIC_ASSERT(ProductIsValid || !(SameSizes && !AreVectors),
+ INVALID_MATRIX_PRODUCT__IF_YOU_WANTED_A_COEFF_WISE_PRODUCT_YOU_MUST_USE_THE_EXPLICIT_FUNCTION)
+ EIGEN_STATIC_ASSERT(ProductIsValid || SameSizes, INVALID_MATRIX_PRODUCT)
+ return typename SparseProductReturnType<Derived,OtherDerived>::Type(derived(), other.derived());
}
#endif // EIGEN_SPARSEPRODUCT_H