This forum has been archived. All content is frozen. Please use KDE Discuss instead.

SparseSparseProduct

Tags: None
(comma "," separated)
joaoruileal
Registered Member
Posts
18
Karma
0
OS

SparseSparseProduct

Mon Nov 17, 2014 6:40 pm
Hello,

I'm trying to adapt the conjugate gradient method so that it can be use with a sparse matrix product:
Code: Select all
typedef Eigen::SparseMatrix<double, Eigen::ColMajor> MatrixType;
const MatrixType& A = getA(); // use a const reference
auto AA = A.transpose() * A; //  Eigen::SparseMatrixBase<Eigen::SparseSparseProduct<Eigen::SparseMatrix<double, 0, int>, Eigen::SparseMatrix<double, 0, int> const&> >

The objective is to eventually add some extra code in order to avoid determining the resulting matrix explicitly but instead do always the following product:
Code: Select all
A.transpose() * A * x

where x is a dense vector.

Therefore, for now, I'm trying to use the type MatrixMatrixType:
Code: Select all
typedef Eigen::TransposeImpl<const MatrixType, Eigen::Sparse> MatrixTType;
typedef Eigen::SparseSparseProduct<MatrixTType, const MatrixType&> MatrixMatrixType;

However inside my code I get the following error:
SparseProduct.h:47:84: error: invalid use of incomplete type ‘struct Eigen::internal::traits<Eigen::TransposeImpl<const Eigen::SparseMatrix<double, 0>, Eigen::Sparse> >’
typename traits<_RhsNested>::Index>::type Index;

So, just to have a complete example that triggers this issue:
Code: Select all
typedef double Scalar;
typedef Eigen::SparseMatrix<Scalar, Eigen::ColMajor> MatrixType;
typedef Eigen::TransposeImpl<const MatrixType, Eigen::Sparse> MatrixTType;
typedef Eigen::SparseSparseProduct<MatrixTType, const MatrixType&> MatrixMatrixType;

MatrixType A(100, 200);
   
MatrixMatrixType AA(A.transpose(), A); // <<<<<<<< Error!

Should I be using something else in the types of SparseSparseProduct?

I would be grateful for any help!
João Leal

P.S.- Edited in order to have a complete example with the issue.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: SparseSparseProduct

Wed Nov 19, 2014 7:38 pm
You must use "Eigen::Transpose<const MatrixType>". However, this will result in (A^T * A) * x instead of A^T * (A * x). So that's probably not the right way to do so. It would be better to implement a true LSCG class properly support preconditioning.


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]