# HG changeset patch # User David Bateman # Date 1294955469 -3600 # Node ID da8e32c99969ac78226908a2debb7e4799a2916c # Parent 53edbf95fbb60ecfba5aca9fe8b60fb669b8c821 Fix for savving of sparse matrices to matlab files when nnz is not equal to nzmax diff -r 53edbf95fbb6 -r da8e32c99969 src/ChangeLog --- a/src/ChangeLog Thu Jan 13 15:40:14 2011 -0500 +++ b/src/ChangeLog Thu Jan 13 22:51:09 2011 +0100 @@ -1,3 +1,11 @@ +2011-01-12 David Bateman + + 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 * base-list.h (class octave_base_list): Provide explicit diff -r 53edbf95fbb6 -r da8e32c99969 src/ls-mat5.cc --- a/src/ls-mat5.cc Thu Jan 13 15:40:14 2011 -0500 +++ b/src/ls-mat5.cc Thu Jan 13 22:51:09 2011 +0100 @@ -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