comparison src/ls-mat5.cc @ 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 e1edf0ba3bcb
children fd0a3ac60b0e
comparison
equal deleted inserted replaced
11516:53edbf95fbb6 11517:da8e32c99969
2077 { 2077 {
2078 if (tc.is_complex_type ()) 2078 if (tc.is_complex_type ())
2079 { 2079 {
2080 const SparseComplexMatrix m = tc.sparse_complex_matrix_value (); 2080 const SparseComplexMatrix m = tc.sparse_complex_matrix_value ();
2081 octave_idx_type nc = m.cols (); 2081 octave_idx_type nc = m.cols ();
2082 octave_idx_type nnz = m.nzmax (); // Yes its nzmax 2082 octave_idx_type nnz = m.nnz ();
2083 2083
2084 ret += 16 + save_mat5_array_length (m.data (), nnz, save_as_floats); 2084 ret += 16 + save_mat5_array_length (m.data (), nnz, save_as_floats);
2085 if (nnz > 1) 2085 if (nnz > 1)
2086 ret += PAD (nnz * sizeof (int32_t)); 2086 ret += PAD (nnz * sizeof (int32_t));
2087 if (nc > 0) 2087 if (nc > 0)
2089 } 2089 }
2090 else 2090 else
2091 { 2091 {
2092 const SparseMatrix m = tc.sparse_matrix_value (); 2092 const SparseMatrix m = tc.sparse_matrix_value ();
2093 octave_idx_type nc = m.cols (); 2093 octave_idx_type nc = m.cols ();
2094 octave_idx_type nnz = m.nzmax (); 2094 octave_idx_type nnz = m.nnz ();
2095 2095
2096 ret += 16 + save_mat5_array_length (m.data (), nnz, save_as_floats); 2096 ret += 16 + save_mat5_array_length (m.data (), nnz, save_as_floats);
2097 if (nnz > 1) 2097 if (nnz > 1)
2098 ret += PAD (nnz * sizeof (int32_t)); 2098 ret += PAD (nnz * sizeof (int32_t));
2099 if (nc > 0) 2099 if (nc > 0)
2443 } 2443 }
2444 else if (tc.is_sparse_type ()) 2444 else if (tc.is_sparse_type ())
2445 { 2445 {
2446 if (tc.is_complex_type ()) 2446 if (tc.is_complex_type ())
2447 { 2447 {
2448 SparseComplexMatrix m = tc.sparse_complex_matrix_value (); 2448 const SparseComplexMatrix m = tc.sparse_complex_matrix_value ();
2449 octave_idx_type nnz = m.nnz (); 2449 octave_idx_type nnz = m.nnz ();
2450 octave_idx_type nzmax = m.nzmax ();
2451 octave_idx_type nc = m.cols (); 2450 octave_idx_type nc = m.cols ();
2452 2451
2453 write_mat5_sparse_index_vector (os, m.ridx (), nzmax); 2452 write_mat5_sparse_index_vector (os, m.ridx (), nnz);
2454 write_mat5_sparse_index_vector (os, m.cidx (), nc + 1); 2453 write_mat5_sparse_index_vector (os, m.cidx (), nc + 1);
2455 2454
2456 NDArray buf (dim_vector (nnz, 1)); 2455 NDArray buf (dim_vector (nnz, 1));
2457 2456
2458 for (octave_idx_type i = 0; i < nnz; i++) 2457 for (octave_idx_type i = 0; i < nnz; i++)
2465 2464
2466 write_mat5_array (os, buf, save_as_floats); 2465 write_mat5_array (os, buf, save_as_floats);
2467 } 2466 }
2468 else 2467 else
2469 { 2468 {
2470 SparseMatrix m = tc.sparse_matrix_value (); 2469 const SparseMatrix m = tc.sparse_matrix_value ();
2471 octave_idx_type nnz = m.nnz (); 2470 octave_idx_type nnz = m.nnz ();
2472 octave_idx_type nzmax = m.nzmax ();
2473 octave_idx_type nc = m.cols (); 2471 octave_idx_type nc = m.cols ();
2474 2472
2475 write_mat5_sparse_index_vector (os, m.ridx (), nzmax); 2473 write_mat5_sparse_index_vector (os, m.ridx (), nnz);
2476 write_mat5_sparse_index_vector (os, m.cidx (), nc + 1); 2474 write_mat5_sparse_index_vector (os, m.cidx (), nc + 1);
2477 2475
2478 // FIXME 2476 // FIXME
2479 // Is there a way to easily do without this buffer 2477 // Is there a way to easily do without this buffer
2480 NDArray buf (dim_vector (nnz, 1)); 2478 NDArray buf (dim_vector (nnz, 1));