|
Boost Users : |
From: Franck Perignon (Franck.Perignon_at_[hidden])
Date: 2006-10-09 05:10:52
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<double, row_major,std::vector<double> > DenseMat;
typedef triangular_matrix<double, upper, row_major,
std::vector<double> > 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::mapped_matrix<double,
boost::numeric::ublas::basic_row_major<unsigned int, int>,
boost::numeric::ublas::map_std<unsigned int, double,
std::allocator<std::pair<const unsigned int, double> > > > >'
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
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net