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

SparseMatrix: insertion of (sparse) vector at once.

Tags: None
(comma "," separated)
davidhigh
Registered Member
Posts
18
Karma
0
Hello,

first of all, thanks for updating the sparsematrix stuff in Eigen 3.1-alpha.

I have a sparsematrix for which i can hardly estimate the number of nonzeros per row, however I can set up the matrix row-by-row (from first to last). Therefore I would use a column index and a value vector, fill them in random order, and afterwards sort the two vectors by increasing index number. Alternatively, I could also use a sparse vector here, but would have a similar problem, as I don't know the nonzeros in advance.

(i) Is it then possible to insert the whole vector at once ?
(ii) if not, is it then at least possible to resize the respective row of the sparsematrix on the fly, such that insertion using multiple 'insert'-commands is not all to expensive?
(iii) in the code (if I remember right) before 'insert' stands something like EIGEN_DONT_INLINE. What does that mean. Would it not be more efficient to inline this function.

thanks in advance,
David
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
If your non zeros appears only once, then a good strategy is as follow: fill a std::vector<Triplet> where Triplet is a structure storing the i,j indices and the value. During this fill-in you can easily compute the number of rows, columns, and the number of non-zero per columns into a std::vector<int>. Then you create a rows x columns *column-major* sparse matrix, reserve space with the std::vector<int>, insert the elements in the same order as stored in the std::vector<Triplet>, and you're good to go with sorted, packed SparseMatrix !

For beta1, I plan to add a fill method taking an iterator and doing all this logic for you, so basically you would only have to fill the std::vector<Triplet> and pass it to the fill method that will take care of the rest depending on the target storage order and structure of the input.


Bookmarks



Who is online

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