
Ublas : 
From: Gunter Winkler (guwi17_at_[hidden])
Date: 20050503 08:19:19
On Tuesday 03 May 2005 14:38, Michael Stevens wrote:
> I think I see what Max wants: An 'equality' that uses a uBLAS "matrix
> expressions".
> Gunters suggests norm_inf(AB) seems to fit the bill perfectly. In user
> code I think
> if (norm_inf(AB) == 0)
> .. equal
>
> is nice linear algebra expression.
>
> Has two small drawbacks.
> a) norm_inf(AB) !=0 does not short circuit
> b) Requires operator instead of operator == for elements. Only an issue if
> you store non algebraic elements!
If I want it better I can write a few lines of code (row major version):
bool real_equal(const spm_t& A, const spm_t& B) {
typedef spm_t::const_iterator1 i1_t;
typedef spm_t::const_iterator2 i2_t;
for (i1_t i1 = A.begin1(); i1 != A.end1(); ++i1) {
for (i2_t i2 = i1.begin(); i2 != i1.end(); ++i2)
if ( (*i2) != B(i2.index1(), i2.index2()) ) return false;
}
return true;
}
HTH
mfg
Gunter