Mercurial > hg > octave-avbm
changeset 9829:8fd88cc36fa4
fix loading sparse matrices
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Wed, 18 Nov 2009 13:34:58 +0100 |
parents | b96e9239178e |
children | 6748616e2f8b |
files | liboctave/ChangeLog liboctave/Sparse.h |
diffstat | 2 files changed, 30 insertions(+), 29 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,7 @@ +2009-11-18 Jaroslav Hajek <highegg@gmail.com> + + * Sparse.h (read_sparse_matrix): Fix order of tests and reads. + 2009-11-18 Jaroslav Hajek <highegg@gmail.com> * mx-inlines.cc (mx_inline_any_negative, mx_inline_pow): New loops.
--- a/liboctave/Sparse.h +++ b/liboctave/Sparse.h @@ -616,16 +616,12 @@ a.cidx (0) = 0; for (octave_idx_type i = 0; i < nz; i++) { + itmp = 0; jtmp = 0; is >> itmp; itmp--; - if (itmp < iold) - { - (*current_liboctave_error_handler) - ("invalid sparse matrix: row indices must appear in ascending order in each column"); - is.setstate (std::ios::failbit); - goto done; - } + is >> jtmp; + jtmp--; if (itmp < 0 || itmp >= nr) { @@ -636,20 +632,6 @@ goto done; } - - iold = itmp; - - is >> jtmp; - jtmp--; - - if (jtmp < jold) - { - (*current_liboctave_error_handler) - ("invalid sparse matrix: column indices must appear in ascending order"); - is.setstate (std::ios::failbit); - goto done; - } - if (jtmp < 0 || jtmp >= nc) { (*current_liboctave_error_handler) @@ -659,18 +641,33 @@ goto done; } + if (jtmp < jold) + { + (*current_liboctave_error_handler) + ("invalid sparse matrix: column indices must appear in ascending order"); + is.setstate (std::ios::failbit); + goto done; + } + else if (jtmp > jold) + { + for (octave_idx_type j = jold; j < jtmp; j++) + a.cidx(j+1) = ii; + } + else if (itmp < iold) + { + (*current_liboctave_error_handler) + ("invalid sparse matrix: row indices must appear in ascending order in each column"); + is.setstate (std::ios::failbit); + goto done; + } + + iold = itmp; + jold = jtmp; + tmp = read_fcn (is); if (is) { - if (jold != jtmp) - { - for (octave_idx_type j = jold; j < jtmp; j++) - a.cidx(j+1) = ii; - - jold = jtmp; - iold = 0; - } a.data (ii) = tmp; a.ridx (ii++) = itmp; }