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

Filling Symmetric Sparse Matrix

Tags: sparse matrix, filling, symmetric sparse matrix, filling, symmetric sparse matrix, filling, symmetric
(comma "," separated)
ennetws
Registered Member
Posts
1
Karma
0

Filling Symmetric Sparse Matrix

Fri Feb 26, 2010 10:23 pm
Hello,

Is their a better way to fill a sparse matrix that is known to be symmetric. Right now I'm using something like this:

Code: Select all
// M is an Eigen::DynamicSparseMatrix<double>
M.coeffRef(i,j) -= value;
M.coeffRef(j,i) -= value;

// Finally 'mat' is the SparseMatrix I use
Eigen::SparseMatrix<double> mat(M);

Thanks for your amazing work on Eigen! :)
baltcode
Registered Member
Posts
12
Karma
0

Re: Filling Symmetric Sparse Matrix

Fri Mar 05, 2010 10:57 pm
This is what I do:

[code]
// Eigen::SparseMatrix<float,1> M;

//fill it out
M.startFill();
for (i=0;i<N;i++) {
// loop some j
M.fill(i,j) = value;
}
M = M + Eigen::SparseMatrix<float,1>(M.transpose());
[\code]

I am not sure which one is faster. Is there another way to do this?
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: Filling Symmetric Sparse Matrix

Tue Mar 09, 2010 7:27 pm
ideally, if you know your matrix is symmetric, you should only fill one half (the upper or lower triangular part), and then use the selfadjointView API to view and use it as a symmetric/selfadjoint matrix.

Unfortunately I'm pretty sure that for the sparse module, the seladjointView API is very incomplete. But the goal is to have this working:

// fill the upper part of a
c = a.selfadjointView<Upper>() * b;

maybe the above already works with b a dense vector/matrix, I don't remember...


Bookmarks



Who is online

Registered users: abc72656, Bing [Bot], daret, Google [Bot], Sogou [Bot], Yahoo [Bot]