Boost logo

Ublas :

Subject: [ublas] iterators and mpreal
From: Isaia Nisoli (isaia.nisoli_at_[hidden])
Date: 2011-05-25 07:38:33


Hi,

I’m using an old version of the Boost.Library UBLAS (1.42) and I’m
programming a linear algebra program where the matrix entries are mpreals.

I give you some contest: I define two special types

typedef mpreal APFloat;
typedef boost::numeric::ublas::vector Vector;
typedef boost::numeric::ublas::matrix BMatrixND;

now I define a class

class srmatrix
{
private:
APFloat error;
public:
SMatrixND A;
//Constructor
srmatrix(const rpartition &,const APFloat &);
srmatrix(const SMatrixND &B,const APFloat &errore){A=B;error=errore;};
//Member Function
APFloat L1Norm();
};

while the constructor for the class works fine, I get some big problem with
L1Norm()
The fact is that the program compiles fine, but at runtime, even if I don’t
call the function L1Norm(), I get the following error
../init2.c:52: MPFR assertion failed: p >= 2 && p >1))

APFloat srmatrix::L1Norm()
{
mpreal::set_default_prec(bitprecision);
int size=A.size2();
Vector Norms(size);
for (int i=0; i< size; i++)
{
Norms(i)=APFloat(0);
}
APFloat temp(0);
APFloat locmax(0);

for (it1 i1 = A.begin1(); i1 != A.end1(); ++i1)
{
int rowindex=0;
int colindex=0;
for (it2 i2 = i1.begin(); i2 != i1.end(); ++i2)
{
rowindex=i2.index1();
colindex=i2.index2();
Norms(colindex)+=abs(*i2);
}
}

for (int i=0;i< size;i++)
{
temp=Norms(i);
if (locmax<temp){locmax=temp;}
}
return locmax;

}

With search and try I found that the problem arises from the iterator *i2.
Even much simpler code like

APFloat srmatrix::L1Norm()
{

for (it1 i1 = A.begin1(); i1 != A.end1(); ++i1)
{
int rowindex=0;
int colindex=0;
for (it2 i2 = i1.begin(); i2 != i1.end(); ++i2)
{
cout << *i2 << endl;
}
}
}

gives the same problem.
I really cannot understand where the problem lies… the real problem is that,
since I’m working with sparse matrices I made a strong use of iterators in
the whole of my program, so if dereferencing an iterator gives rise to a
problem I’m in a really bad situation :-)

I’ve discovered that if I access the matrix by A(rowindex,colindex) the
problem does not occur.
The real problem is that accessing the matrix this way is way much slower
than using iterators.
I also tried with the new libboost 1.46.1 and the wrapper for mpreal.
But I still get the same error at runtime.

        Isaia

--
View this message in context: http://boost.2283326.n4.nabble.com/iterators-and-mpreal-tp3549454p3549454.html
Sent from the Boost - uBLAS mailing list archive at Nabble.com.