diff src/ov-cx-sparse.cc @ 7193:cbdee3da62bd

[project @ 2007-11-26 22:20:25 by dbateman]
author dbateman
date Mon, 26 Nov 2007 22:20:25 +0000
parents a1dbe9d80eee
children 8c32f95c2639
line wrap: on
line diff
--- a/src/ov-cx-sparse.cc	Mon Nov 26 21:44:54 2007 +0000
+++ b/src/ov-cx-sparse.cc	Mon Nov 26 22:20:25 2007 +0000
@@ -54,37 +54,45 @@
 {
   octave_base_value *retval = 0;
 
-  int nr = matrix.rows ();
-  int nc = matrix.cols ();
+  if (Vsparse_auto_mutate)
+    {
+      int nr = matrix.rows ();
+      int nc = matrix.cols ();
 
-  // Don't use numel, since it can overflow for very large matrices
-  // Note that for the tests on matrix size, they become approximative
-  // since they involves a cast to double to avoid issues of overflow
-  if (matrix.rows () == 1 && matrix.cols () == 1)
-    {
-      // Const copy of the matrix, so the right version of () operator used
-      const SparseComplexMatrix tmp (matrix);
+      // Don't use numel, since it can overflow for very large matrices
+      // Note that for the tests on matrix size, they become approximative
+      // since they involves a cast to double to avoid issues of overflow
+      if (matrix.rows () == 1 && matrix.cols () == 1)
+	{
+	  // Const copy of the matrix, so the right version of () operator used
+	  const SparseComplexMatrix tmp (matrix);
 
-      Complex c = tmp (0, 0);
+	  Complex c = tmp (0, 0);
 
-      if (imag (c) == 0.0)
-	retval = new octave_scalar (std::real (c));
-      else
-	retval = new octave_complex (c);
+	  if (imag (c) == 0.0)
+	    retval = new octave_scalar (std::real (c));
+	  else
+	    retval = new octave_complex (c);
+	}
+      else if (nr == 0 || nc == 0)
+	retval = new octave_matrix (Matrix (nr, nc));
+      else if (matrix.all_elements_are_real ())
+	if (matrix.cols () > 0 && matrix.rows () > 0 && 
+	    double (matrix.byte_size ()) > double (matrix.rows ()) *
+	    double (matrix.cols ()) * sizeof (double))
+	  retval = new octave_matrix (::real (matrix.matrix_value ()));
+	else
+	  retval = new octave_sparse_matrix (::real (matrix));
+      else if (matrix.cols () > 0 && matrix.rows () > 0 && 
+	       double (matrix.byte_size ()) > double (matrix.rows ()) *
+	       double (matrix.cols ()) * sizeof (Complex))
+	retval = new octave_complex_matrix (matrix.matrix_value ());
     }
-  else if (nr == 0 || nc == 0)
-    retval = new octave_matrix (Matrix (nr, nc));
-  else if (matrix.all_elements_are_real ())
-    if (matrix.cols () > 0 && matrix.rows () > 0 && 
-	double (matrix.byte_size ()) > double (matrix.rows ()) *
-	double (matrix.cols ()) * sizeof (double))
-      retval = new octave_matrix (::real (matrix.matrix_value ()));
-    else
-      retval = new octave_sparse_matrix (::real (matrix));
-  else if (matrix.cols () > 0 && matrix.rows () > 0 && 
-	   double (matrix.byte_size ()) > double (matrix.rows ()) *
-	   double (matrix.cols ()) * sizeof (Complex))
-    retval = new octave_complex_matrix (matrix.matrix_value ());
+  else
+    {
+      if (matrix.all_elements_are_real ())
+	retval = new octave_sparse_matrix (::real (matrix));
+    }
     
   return retval;
 }