diff options
author | Gael Guennebaud <g.gael@free.fr> | 2014-10-06 16:11:26 +0200 |
---|---|---|
committer | Gael Guennebaud <g.gael@free.fr> | 2014-10-06 16:11:26 +0200 |
commit | d44d432baa142fdbe17f9d3abeab2c7629e199b8 (patch) | |
tree | e36ed1b2515d9d307925fa30ef4e389b279d1ed1 /Eigen | |
parent | 893bfcf95fd7aaa49747f029bac708a02a1526cd (diff) |
Re-enable products with triangular views of sparse matrices: we simply have to treat them as a sparse matrix.
Diffstat (limited to 'Eigen')
-rw-r--r-- | Eigen/src/Core/TriangularMatrix.h | 8 | ||||
-rw-r--r-- | Eigen/src/SparseCore/ConservativeSparseSparseProduct.h | 2 | ||||
-rw-r--r-- | Eigen/src/SparseCore/SparseDenseProduct.h | 12 | ||||
-rw-r--r-- | Eigen/src/SparseCore/SparseProduct.h | 13 |
4 files changed, 31 insertions, 4 deletions
diff --git a/Eigen/src/Core/TriangularMatrix.h b/Eigen/src/Core/TriangularMatrix.h index 36bbd46e1..263d54485 100644 --- a/Eigen/src/Core/TriangularMatrix.h +++ b/Eigen/src/Core/TriangularMatrix.h @@ -247,7 +247,7 @@ template<typename _MatrixType, unsigned int _Mode> class TriangularView inline const AdjointReturnType adjoint() const { return AdjointReturnType(m_matrix.adjoint()); } - typedef TriangularView<Transpose<MatrixType>,TransposeMode> TransposeReturnType; + typedef TriangularView<typename MatrixType::TransposeReturnType,TransposeMode> TransposeReturnType; /** \sa MatrixBase::transpose() */ EIGEN_DEVICE_FUNC inline TransposeReturnType transpose() @@ -255,11 +255,13 @@ template<typename _MatrixType, unsigned int _Mode> class TriangularView EIGEN_STATIC_ASSERT_LVALUE(MatrixType) return TransposeReturnType(m_matrix.const_cast_derived().transpose()); } + + typedef TriangularView<const typename MatrixType::ConstTransposeReturnType,TransposeMode> ConstTransposeReturnType; /** \sa MatrixBase::transpose() const */ EIGEN_DEVICE_FUNC - inline const TransposeReturnType transpose() const + inline const ConstTransposeReturnType transpose() const { - return TransposeReturnType(m_matrix.transpose()); + return ConstTransposeReturnType(m_matrix.transpose()); } template<typename Other> diff --git a/Eigen/src/SparseCore/ConservativeSparseSparseProduct.h b/Eigen/src/SparseCore/ConservativeSparseSparseProduct.h index 19d9eaa42..a30522ff7 100644 --- a/Eigen/src/SparseCore/ConservativeSparseSparseProduct.h +++ b/Eigen/src/SparseCore/ConservativeSparseSparseProduct.h @@ -141,6 +141,8 @@ struct conservative_sparse_sparse_product_selector<Lhs,Rhs,ResultType,ColMajor,C typedef SparseMatrix<typename ResultType::Scalar,ColMajor,typename ResultType::Index> ColMajorMatrixAux; typedef typename sparse_eval<ColMajorMatrixAux,ResultType::RowsAtCompileTime,ResultType::ColsAtCompileTime>::type ColMajorMatrix; + // If the result is tall and thin (in the extreme case a column vector) + // then it is faster to sort the coefficients inplace instead of transposing twice. // FIXME, the following heuristic is probably not very good. if(lhs.rows()>=rhs.cols()) { diff --git a/Eigen/src/SparseCore/SparseDenseProduct.h b/Eigen/src/SparseCore/SparseDenseProduct.h index ed3cb1990..5aea11425 100644 --- a/Eigen/src/SparseCore/SparseDenseProduct.h +++ b/Eigen/src/SparseCore/SparseDenseProduct.h @@ -147,6 +147,11 @@ struct generic_product_impl<Lhs, Rhs, SparseShape, DenseShape, ProductType> }; template<typename Lhs, typename Rhs, int ProductType> +struct generic_product_impl<Lhs, Rhs, SparseTriangularShape, DenseShape, ProductType> + : generic_product_impl<Lhs, Rhs, SparseShape, DenseShape, ProductType> +{}; + +template<typename Lhs, typename Rhs, int ProductType> struct generic_product_impl<Lhs, Rhs, DenseShape, SparseShape, ProductType> { template<typename Dest> @@ -158,12 +163,17 @@ struct generic_product_impl<Lhs, Rhs, DenseShape, SparseShape, ProductType> RhsNested rhsNested(rhs); dst.setZero(); - // transpoe everything + // transpose everything Transpose<Dest> dstT(dst); internal::sparse_time_dense_product(rhsNested.transpose(), lhsNested.transpose(), dstT, typename Dest::Scalar(1)); } }; +template<typename Lhs, typename Rhs, int ProductType> +struct generic_product_impl<Lhs, Rhs, DenseShape, SparseTriangularShape, ProductType> + : generic_product_impl<Lhs, Rhs, DenseShape, SparseShape, ProductType> +{}; + template<typename LhsT, typename RhsT, bool NeedToTranspose> struct sparse_dense_outer_product_evaluator { diff --git a/Eigen/src/SparseCore/SparseProduct.h b/Eigen/src/SparseCore/SparseProduct.h index ae707376a..c62386ed1 100644 --- a/Eigen/src/SparseCore/SparseProduct.h +++ b/Eigen/src/SparseCore/SparseProduct.h @@ -33,6 +33,7 @@ SparseMatrixBase<Derived>::operator*(const SparseMatrixBase<OtherDerived> &other namespace internal { +// sparse * sparse template<typename Lhs, typename Rhs, int ProductType> struct generic_product_impl<Lhs, Rhs, SparseShape, SparseShape, ProductType> { @@ -48,6 +49,18 @@ struct generic_product_impl<Lhs, Rhs, SparseShape, SparseShape, ProductType> } }; +// sparse * sparse-triangular +template<typename Lhs, typename Rhs, int ProductType> +struct generic_product_impl<Lhs, Rhs, SparseShape, SparseTriangularShape, ProductType> + : public generic_product_impl<Lhs, Rhs, SparseShape, SparseShape, ProductType> +{}; + +// sparse-triangular * sparse +template<typename Lhs, typename Rhs, int ProductType> +struct generic_product_impl<Lhs, Rhs, SparseTriangularShape, SparseShape, ProductType> + : public generic_product_impl<Lhs, Rhs, SparseShape, SparseShape, ProductType> +{}; + template<typename Lhs, typename Rhs, int Options> struct evaluator<SparseView<Product<Lhs, Rhs, Options> > > : public evaluator<typename Product<Lhs, Rhs, DefaultProduct>::PlainObject>::type |