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

setFromTriplets

Tags: None
(comma "," separated)
n2k
Registered Member
Posts
41
Karma
0

setFromTriplets

Tue Apr 29, 2014 12:46 am
Hi,

I would like to solve a sparse KKT system of the form Ax=b, where A is a sparse block matrix in the form A=[B C^T;C 0].

I already have the B and C matrices stored in the form of independent std::vector<Eigen::Triplet<double>>. What is the most efficient way to assemble A? Of course I could create a new std::vector with all the triplets, but I would like to avoid the copy of the existing vectors of triplets into a new vector (for efficiency).

I've looked in the documentation, and it seems that I cannot call the SparseMatrix::setFromTriplets method more than once, because the content of the sparse matrix is cleared after each call.

Any suggestion?
Thank you!
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: setFromTriplets

Tue Apr 29, 2014 1:00 pm
You can copy B to A, call A.conservativeResize(...), and then call A.reserve(...) [1] with a vector containing the number of nonzeros for each column of C followed by the number of nonzeros for each row of C, and then call A.bottomLeftCorner(...) = C, and A.topRightCorner(...)=C^T.

[1] http://eigen.tuxfamily.org/dox/classEig ... f2487fb596


Bookmarks



Who is online

Registered users: Baidu [Spider], Bing [Bot], Google [Bot], rblackwell