changeset 8527:6b074f37e8d7

reshape: improve error message
author John W. Eaton <jwe@octave.org>
date Thu, 15 Jan 2009 16:59:15 -0500
parents 17e0ad741fac
children 06e1667d7492
files liboctave/Array.cc liboctave/Sparse.cc src/data.cc
diffstat 3 files changed, 23 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/liboctave/Array.cc
+++ b/liboctave/Array.cc
@@ -442,9 +442,14 @@
       if (dimensions.numel () == new_dims.numel ())
 	retval = Array<T> (*this, new_dims);
       else
-	(*current_liboctave_error_handler)
-	  ("reshape: size mismatch (%s != %s)", dimensions.str (),
-	   new_dims.str ());
+	{
+	  std::string dimensions_str = dimensions.str ();
+	  std::string new_dims_str = new_dims.str ();
+
+	  (*current_liboctave_error_handler)
+	    ("reshape: can't reshape %s array to %s array",
+	     dimensions_str.c_str (), new_dims_str.c_str ());
+	}
     }
   else
     retval = *this;
--- a/liboctave/Sparse.cc
+++ b/liboctave/Sparse.cc
@@ -796,9 +796,14 @@
 	    retval.xcidx(k+1) = new_nnz;
 	}
       else
-	(*current_liboctave_error_handler)
-	  ("reshape: size mismatch (%s != %s)", dimensions.str (),
-	   new_dims.str ());
+	{
+	  std::string dimensions_str = dimensions.str ();
+	  std::string new_dims_str = new_dims.str ();
+
+	  (*current_liboctave_error_handler)
+	    ("reshape: can't reshape %s array to %s array",
+	     dimensions_str.c_str (), new_dims_str.c_str ());
+	}
     }
   else
     retval = *this;
--- a/src/data.cc
+++ b/src/data.cc
@@ -4542,7 +4542,13 @@
   if (new_dims.numel () == dims.numel ())
     retval = (new_dims == dims) ? arg : arg.reshape (new_dims);
   else
-    error ("reshape: size mismatch (%s != %s)", dims.str (), new_dims.str ());
+    {
+      std::string dims_str = dims.str ();
+      std::string new_dims_str = new_dims.str ();
+
+      error ("reshape: can't reshape %s array to %s array",
+	     dims_str.c_str (), new_dims_str.c_str ());
+    }
 
   return retval;
 }