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

Vector of .. or vector of pointers to sparse matrices?

Tags: None
(comma "," separated)
Akkawe
Registered Member
Posts
35
Karma
0
OS
Hi there, I'm a newbie, could you clarify this:
in .h:
Code: Select all
SparseMatrix<double> K1;
SparseMatrix<double> K2;
SparseMatrix<double> K3;
vector< SparseMatrix<double> > mA //define vector of SparseMatrix objs

in .cpp
Code: Select all
mA.reserve(3);
mA.push_back(K1);
mA.push_back(K2);
mA.push_back(K3);


Since the Sparse Matrices could be huge, is it better to allocate memory and use a vector of pointers to sparse matrix:
Code: Select all
vector< SparseMatrix<double> *> mA //

How do you think? Is the last code useless?

thanks
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
Hi,

I see two options, 1) you push empty SparseMatrix and directly work with them, 2) you create individual SparseMatrix and then only store a vector of pointers.
Akkawe
Registered Member
Posts
35
Karma
0
OS
ggael wrote:Hi,

I see two options, 1) you push empty SparseMatrix and directly work with them, 2) you create individual SparseMatrix and then only store a vector of pointers.


yes, the code is not complete.
in the last option i would write:
Code: Select all
ma.push_back(new SparseMatrix<double>) //not correct i guess

I don`t understand how Eigen handles the memory.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
I meant that if all you want is to create a std::vector of sparse matrices, and not aggregates existing matrices into a std::vector, then use option 1, otherwise use option 2.
Akkawe
Registered Member
Posts
35
Karma
0
OS
It's clear for me.
Thanks


Bookmarks



Who is online

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