changeset 7400:f9df7f7520e7

[project @ 2008-01-18 08:25:24 by jwe]
author jwe
date Fri, 18 Jan 2008 08:25:24 +0000
parents c1a3d6c7d2fb
children 270f28cfa7a0
files liboctave/CMatrix.cc liboctave/ChangeLog liboctave/dMatrix.cc
diffstat 3 files changed, 47 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/liboctave/CMatrix.cc	Fri Jan 18 07:37:35 2008 +0000
+++ b/liboctave/CMatrix.cc	Fri Jan 18 08:25:24 2008 +0000
@@ -2750,6 +2750,14 @@
   1.9270852604185938e-9,
 };
 
+static void
+solve_singularity_warning (double rcond)
+{
+  (*current_liboctave_warning_handler) 
+    ("singular matrix encountered in expm calculation, rcond = %g",
+     rcond);
+}
+
 ComplexMatrix
 ComplexMatrix::expm (void) const
 {
@@ -2843,6 +2851,9 @@
 
   if (sqpow > 0)
     {
+      if (sqpow > 1023)
+	sqpow = 1023;
+
       double scale_factor = 1.0;
       for (octave_idx_type i = 0; i < sqpow; i++)
 	scale_factor *= 2.0;
@@ -2889,8 +2900,12 @@
 
   // Compute pade approximation = inverse (dpp) * npp.
 
-  retval = dpp.solve (npp);
-	
+  double rcond;
+  retval = dpp.solve (npp, info, rcond, solve_singularity_warning);
+
+  if (info < 0)
+    return retval;
+
   // Reverse preconditioning step 3: repeated squaring.
 
   while (sqpow)
--- a/liboctave/ChangeLog	Fri Jan 18 07:37:35 2008 +0000
+++ b/liboctave/ChangeLog	Fri Jan 18 08:25:24 2008 +0000
@@ -1,3 +1,15 @@
+2008-01-18  John W. Eaton  <jwe@octave.org>
+
+	* dMatrix.cc (solve_singularity_warning): New function.
+	(Matrix::expm): Pass pointer to solve_singularity_warning to
+	Matrix::solve method.  Exit early if Matrix::solve fails.
+	Limit sqpow value to avoid overflowing scale factor.
+	* CMatrix.cc (solve_singularity_warning): New function.
+	(ComplexMatrix::expm): Pass pointer to solve_singularity_warning to
+	ComplexMatrix::solve method.  Exit early if ComplexMatrix::solve fails.
+	Limit sqpow value to avoid overflowing scale factor.
+	From Marco Caliari <mcaliari@math.unipd.it>.
+
 2008-01-10  Kim Hansen  <kimhanse@gmail.com>
 
 	* Sparse.cc: New tests for slicing of sparse matrices.
--- a/liboctave/dMatrix.cc	Fri Jan 18 07:37:35 2008 +0000
+++ b/liboctave/dMatrix.cc	Fri Jan 18 08:25:24 2008 +0000
@@ -2378,6 +2378,14 @@
   1.9270852604185938e-9,
 };
 
+static void
+solve_singularity_warning (double rcond)
+{
+  (*current_liboctave_warning_handler) 
+    ("singular matrix encountered in expm calculation, rcond = %g",
+     rcond);
+}
+
 Matrix
 Matrix::expm (void) const
 {
@@ -2463,10 +2471,13 @@
   
   if (sqpow > 0)
     {
+      if (sqpow > 1023)
+	sqpow = 1023;
+
       double scale_factor = 1.0;
       for (octave_idx_type i = 0; i < sqpow; i++)
 	scale_factor *= 2.0;
-  
+
       m = m / scale_factor;
     }
   
@@ -2509,8 +2520,12 @@
   
   // Compute pade approximation = inverse (dpp) * npp.
 
-  retval = dpp.solve (npp, info);
-  
+  double rcond;
+  retval = dpp.solve (npp, info, rcond, solve_singularity_warning);
+
+  if (info < 0)
+    return retval;
+
   // Reverse preconditioning step 3: repeated squaring.
   
   while (sqpow)