changeset 11517:da8e32c99969

Fix for savving of sparse matrices to matlab files when nnz is not equal to nzmax
author David Bateman <dbateman@free.fr>
date Thu, 13 Jan 2011 22:51:09 +0100
parents 53edbf95fbb6
children 141b3fb5cef7
files src/ChangeLog src/ls-mat5.cc
diffstat 2 files changed, 14 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,11 @@
+2011-01-12  David Bateman  <dbateman@free.fr>
+
+	ls-mat5.cc (int save_mat5_element_length (const octave_value&,
+	const std::string&, bool, bool)): For sparse matrices use nnz rather
+	than nzmax.
+	(bool save_mat5_binary_element (std::ostream&, const octave_value&,
+	const std::string&, bool, bool, bool, bool)): ditto.
+
 2011-01-13  John W. Eaton  <jwe@octave.org>
 
 	* base-list.h (class octave_base_list): Provide explicit
--- a/src/ls-mat5.cc
+++ b/src/ls-mat5.cc
@@ -2079,7 +2079,7 @@
         {
           const SparseComplexMatrix m = tc.sparse_complex_matrix_value ();
           octave_idx_type nc = m.cols ();
-          octave_idx_type nnz = m.nzmax (); // Yes its nzmax
+          octave_idx_type nnz = m.nnz ();
 
           ret += 16 + save_mat5_array_length (m.data (), nnz, save_as_floats);
           if (nnz > 1)
@@ -2091,7 +2091,7 @@
         {
           const SparseMatrix m = tc.sparse_matrix_value ();
           octave_idx_type nc = m.cols ();
-          octave_idx_type nnz = m.nzmax ();
+          octave_idx_type nnz = m.nnz ();
 
           ret += 16 + save_mat5_array_length (m.data (), nnz, save_as_floats);
           if (nnz > 1)
@@ -2445,12 +2445,11 @@
     {
       if (tc.is_complex_type ())
         {
-          SparseComplexMatrix m = tc.sparse_complex_matrix_value ();
+          const SparseComplexMatrix m = tc.sparse_complex_matrix_value ();
           octave_idx_type nnz = m.nnz ();
-          octave_idx_type nzmax = m.nzmax ();
           octave_idx_type nc = m.cols ();
 
-          write_mat5_sparse_index_vector (os, m.ridx (), nzmax);
+          write_mat5_sparse_index_vector (os, m.ridx (), nnz);
           write_mat5_sparse_index_vector (os, m.cidx (), nc + 1);
 
           NDArray buf (dim_vector (nnz, 1));
@@ -2467,12 +2466,11 @@
         }
       else
         {
-          SparseMatrix m = tc.sparse_matrix_value ();
+          const SparseMatrix m = tc.sparse_matrix_value ();
           octave_idx_type nnz = m.nnz ();
-          octave_idx_type nzmax = m.nzmax ();
           octave_idx_type nc = m.cols ();
 
-          write_mat5_sparse_index_vector (os, m.ridx (), nzmax);
+          write_mat5_sparse_index_vector (os, m.ridx (), nnz);
           write_mat5_sparse_index_vector (os, m.cidx (), nc + 1);
 
           // FIXME