gcc-3.4 patch for ITL + basic_iteration fix

Gunter Winkler <[email protected]> Mon, 25 Apr 2005 09:30:12 +0200
Newsgroups gmane.comp.lib.mtl.devel
Message-ID <[email protected]>
Hallo,

Issue 1:
gcc 3.4 changed name lookup rules, so member functions and variables of a base 
class are not automatically found. Now you have to explicitly name them 
either by prefixing with "this->" or by "using base_type::base_var".
(Chunks 2 and above of the attached patch)

Issue 2: 
when creating an iteration instance with initial solution (b) equal to zero, 
then normb_ is zero and the converged function fails to compute the relative 
error (_resid = r / normb_;). Thus all residual are reported as (quiet) nans. 
I suggest to assign the smallest positive float to normb_ if b = 0. This 
allows the solution of a homogeneous system of equation (if its uniquely 
solvable).
(Chunk 1 of the patch)

@Márcio: Does this patch help with your bicg problem?

mfg
Gunter

_______________________________________________
This list is archived at http://www.osl.iu.edu/MailArchives/mtl-devel/
itl_h_gcc34.diff (text/x-diff, 2.5 KB)
--- /tmp/a11aguwi/itl/itl.h	2002-11-18 12:16:08.000000000 +0100
+++ itl.h	2005-04-21 16:58:24.000000000 +0200
@@ -116,7 +116,7 @@
   
     template <class Vector>
     basic_iteration(const Vector& b, int max_iter_, Real t, Real a = Real(0))
-      : error(0), i(0), normb_(std::abs(itl::two_norm(b))), 
+      : error(0), i(0), normb_(std::max(std::abs(itl::two_norm(b)), std::numeric_limits<Real>::min())), 
 	       max_iter(max_iter_), rtol_(t), atol_(a) { }
   
     basic_iteration(Real nb, int max_iter_, Real t, Real a = Real(0))
@@ -202,6 +202,7 @@
   template <class Real>
   class noisy_iteration : public basic_iteration<Real> {
     typedef basic_iteration<Real> super;
+    typedef noisy_iteration<Real> self;
   public:
   
     template <class Vector>
@@ -209,6 +210,10 @@
 		    Real tol_, Real atol_ = Real(0))
       : super(b, max_iter_, tol_, atol_) { }
 
+    using super::i;
+    using super::max_iter;
+    using super::error;
+
     template <class Vector>
     bool finished(const Vector& r) {
       using std::cout;
@@ -224,7 +229,7 @@
 	error = 1;
 	ret = true;
       }
-      cout << "iteration " << i << ": resid " << resid()
+      cout << "iteration " << i << ": resid " << this->resid()
 	   << endl;
       return ret;
     }
@@ -243,7 +248,7 @@
 	error = 1;
 	ret = true;
       }
-      cout << "iteration " << i << ": resid " << resid()
+      cout << "iteration " << i << ": resid " << this->resid()
 	   << endl;
       return ret;
     }
@@ -262,7 +267,7 @@
 	error = 1;
 	ret = true;
       }
-      cout << "iteration " << i << ": resid " << resid() << endl;
+      cout << "iteration " << i << ": resid " << this->resid() << endl;
       return ret;
     }
   
@@ -270,12 +275,12 @@
       using std::cout;
       using std::endl;
 
-      cout << "finished! error code = " << error << endl;
-      cout << iterations() << " iterations" << endl;
-      cout << resid() << " is actual final residual. " << endl
-	   << resid()/normb() << " is actual relative tolerance achieved. "
+      cout << "finished! error code = " << this->error << endl;
+      cout << this->iterations() << " iterations" << endl;
+      cout << this->resid() << " is actual final residual. " << endl
+	   << this->resid()/this->normb() << " is actual relative tolerance achieved. "
 	   << endl;
-      cout << "Relative tol: " << rtol_ << "  Absolute tol: " << atol_ << endl;
+      cout << "Relative tol: " << this->rtol_ << "  Absolute tol: " << this->atol_ << endl;
       return error;
     }
signature.asc (application/pgp-signature, 189 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)

iD8DBQBCbJyMghsXb/J0PcERArH+AJ4pLoYBKx1KK5IjqBBQVfA1hOghTwCgkJlW
UKHLYjZw40cHoKS6mjeRB6E=
=kKTQ
-----END PGP SIGNATURE-----