Good morning,
Can somebody help me using sparse matrices? Here is my problem:
I have a class, named MySimpleMatrix, whith a private member, mat, of
type MyMat which is a union of
various boost matrices type:
typedef matrix DenseMat;
typedef triangular_matrix TriangMat;
...
typedef mapped_matrix<double> SparseMat;
...
union MyMat{
DenseMat *Dense; TriangMat *Triang;
SymMat *Sym;
SparseMat *Sparse;
BandedMat *Banded;
};
class MySimpleMatrix
{
private:
unsigned int num;
MyMat mat;
...
}
num =1, means mat is a dense, 2 a triangular and so on.
the operator () is overloaded in the following way:
double& MySimpleMatrix::operator () (unsigned int row, unsigned
int col)
{
...
switch(num){
case 1:
return (*mat.Dense)(row,col);
break;
...
case 4:
return (*mat.Sparse)(row,col);
break;
...
}
}
It works for all matrices types, except sparse where it fails with this
message:
error: invalid initialization of non-const reference of type 'double&'
from a temporary of type
'boost::numeric::ublas::sparse_matrix_element,
boost::numeric::ublas::map_std > > > >'
I undersand I need to get a reference to double as a return value, which
is not given by (*mat.Sparse)(row,col), and thus my question is how to
get the good type from mat.sparse to make my operator work??
Thanks,
F.Perignon