changeset 11468:e1edf0ba3bcb

Yet another single precision matlab file fix
author David Bateman <dbateman@free.fr>
date Sun, 09 Jan 2011 21:24:43 +0100
parents 7aab48b6e903
children c776f063fefe
files src/ChangeLog src/ls-mat5.cc src/ls-utils.cc src/ls-utils.h
diffstat 4 files changed, 49 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Sun Jan 09 14:57:31 2011 -0500
+++ b/src/ChangeLog	Sun Jan 09 21:24:43 2011 +0100
@@ -1,3 +1,12 @@
+2011-01-09  David Bateman  <dbateman@free.fr>
+
+	* ls-mat5.cc (save_mat5_array_length (const float*, octave_idx_type,
+        bool)): Take in to account the short tags for single data elements.
+	(int save_mat5_element_length (const octave_value&, const std::string&,
+	bool, bool)): Declare sparse matrices const to avoid a copy on read.
+	* ls-utils.cc (save_type get_save_type (float, float)): New function.
+	* ls-utils.h  (save_type get_save_type (float, float)): Declare it.
+
 2011-01-09  John W. Eaton  <jwe@octave.org>
 
 	* token.h, token.cc (token::plot_tok_typ): Delete unused enum.
--- a/src/ls-mat5.cc	Sun Jan 09 14:57:31 2011 -0500
+++ b/src/ls-mat5.cc	Sun Jan 09 21:24:43 2011 +0100
@@ -2002,8 +2002,9 @@
       //       size = 4;
       //   }
 
-      // Round nel up to nearest even number of elements
-      return 8 + ((nel + 1) & ~0x1LL) * size;
+      // Round nel up to nearest even number of elements. Take into account
+      // Short tags for 4 byte elements.
+      return PAD ((nel > 0 && nel * size <= 4 ? 4 : 8) + nel * size);
     }
   else
     return 8;
@@ -2076,7 +2077,7 @@
     {
       if (tc.is_complex_type ())
         {
-          SparseComplexMatrix m = tc.sparse_complex_matrix_value ();
+          const SparseComplexMatrix m = tc.sparse_complex_matrix_value ();
           octave_idx_type nc = m.cols ();
           octave_idx_type nnz = m.nzmax (); // Yes its nzmax
 
@@ -2088,7 +2089,7 @@
         }
       else
         {
-          SparseMatrix m = tc.sparse_matrix_value ();
+          const SparseMatrix m = tc.sparse_matrix_value ();
           octave_idx_type nc = m.cols ();
           octave_idx_type nnz = m.nzmax ();
 
@@ -2130,13 +2131,13 @@
     {
       if (tc.is_single_type ())
         {
-          FloatNDArray m = tc.float_array_value ();
+          const FloatNDArray m = tc.float_array_value ();
           ret += save_mat5_array_length (m.fortran_vec (), m.numel (),
                                          save_as_floats);
         }
       else
         {
-          NDArray m = tc.array_value ();
+          const NDArray m = tc.array_value ();
           ret += save_mat5_array_length (m.fortran_vec (), m.numel (),
                                          save_as_floats);
         }
@@ -2154,13 +2155,13 @@
     {
       if (tc.is_single_type ())
         {
-          FloatComplexNDArray m = tc.float_complex_array_value ();
+          const FloatComplexNDArray m = tc.float_complex_array_value ();
           ret += save_mat5_array_length (m.fortran_vec (), m.numel (),
                                          save_as_floats);
         }
       else
         {      
-          ComplexNDArray m = tc.complex_array_value ();
+          const ComplexNDArray m = tc.complex_array_value ();
           ret += save_mat5_array_length (m.fortran_vec (), m.numel (),
                                          save_as_floats);
         }
--- a/src/ls-utils.cc	Sun Jan 09 14:57:31 2011 -0500
+++ b/src/ls-utils.cc	Sun Jan 09 21:24:43 2011 +0100
@@ -58,3 +58,31 @@
 
   return st;
 }
+
+save_type
+get_save_type (float /* max_val */, float /* min_val */)
+{
+  save_type st = LS_FLOAT;
+
+  // Matlab doesn't seem to load the UINT32 type correctly, so let's
+  // avoid it (and the other unsigned types, even though they may not
+  // have the same problem.  And apparently, there are problems with
+  // other smaller types as well.  If we avoid them all, then maybe we
+  // will avoid problems.  Unfortunately, we won't be able to save
+  // space...
+
+  //  if (max_val < 256 && min_val > -1)
+  //    st = LS_U_CHAR;
+  //  else if (max_val < 65536 && min_val > -1)
+  //    st = LS_U_SHORT;
+  //  else if (max_val < 4294967295UL && min_val > -1)
+  //    st = LS_U_INT;
+  //  else if (max_val < 128 && min_val >= -128)
+  //    st = LS_CHAR;
+  //  else if (max_val < 32768 && min_val >= -32768)
+  //    st = LS_SHORT;
+  //  else if (max_val <= 2147483647L && min_val >= -2147483647L)
+  //    st = LS_INT;
+
+  return st;
+}
--- a/src/ls-utils.h	Sun Jan 09 14:57:31 2011 -0500
+++ b/src/ls-utils.h	Sun Jan 09 21:24:43 2011 +0100
@@ -26,4 +26,7 @@
 extern save_type
 get_save_type (double max_val, double min_val);
 
+extern save_type
+get_save_type (float max_val, float min_val);
+
 #endif