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

Fast sparse matrix concatenation

Tags: None
(comma "," separated)
atome
Registered Member
Posts
2
Karma
0

Fast sparse matrix concatenation

Thu Apr 28, 2016 2:17 pm
Hi everyone

I am doing a project using OpenCV and Eigen and in a specific part I have to do a concatenation of sparse matrices. I saw in the forum that this question has already been asked and some solutions have been proposed:

- The first one uses middleCols and middleRows to insert the new block but I cannot use this since I have to do vertical and horizontal concatenation in the same matrix.

- The other one get the concatenation using SparseMatrix<float>::InnerIterator, but it is slow and I need faster ways to do it.

P.D. If it helps, I should obtain at the end something like [SparseMatrix A, (zeros) ; (zeros), SparseMatrix B] given A and B.

Any suggestion? Thanks!
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
Currently the best is to do it by hand through a call to reserve(A.nonZeros()+B.nonZeros()) and a iterations over the non-zeros of A (and then B) and calls to insert(it.index()+offset_i,j+offset_j) = it.value() for the insertion. This will translate to fast "push-back".


Bookmarks



Who is online

Registered users: Bing [Bot], Evergrowing, Google [Bot], rockscient