From bug-request at octave dot org Thu Dec 29 07:57:47 2005 Subject: Error reading matlab sparse matrix file.... From: David Bateman To: bug at octave dot org Date: Thu, 29 Dec 2005 14:53:27 +0100 This is a multi-part message in MIME format. --------------000401030208060709010104 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit There is an error in reading matlab sparse matrix files when nnz doesn't equal nzmax. The attached patch against the CVS fixes it... D. 2005-12-29 David Bateman * ls-mat5.cc (read_mat5_binary_element): Allow reading of sparse elements when nnz doesn't equal nzmax. -- David Bateman David dot Bateman at motorola dot com Motorola Labs - Paris +33 1 69 35 48 04 (Ph) Parc Les Algorithmes, Commune de St Aubin +33 1 69 35 77 01 (Fax) 91193 Gif-Sur-Yvette FRANCE The information contained in this communication has been classified as: [x] General Business Information [ ] Motorola Internal Use Only [ ] Motorola Confidential Proprietary --------------000401030208060709010104 Content-Type: text/plain; name="patch.mat5-20051229" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="patch.mat5-20051229" *** src/ls-mat5.cc~ 2005-06-15 05:45:49.000000000 +0200 --- src/ls-mat5.cc 2005-12-29 14:47:01.304497205 +0100 *************** *** 403,409 **** bool imag; bool logicalvar; enum arrayclasstype arrayclass; ! FOUR_BYTE_INT nnz; FOUR_BYTE_INT flags; dim_vector dims; int len; --- 403,409 ---- bool imag; bool logicalvar; enum arrayclasstype arrayclass; ! FOUR_BYTE_INT nzmax; FOUR_BYTE_INT flags; dim_vector dims; int len; *************** *** 495,501 **** global = (flags & 0x0400) != 0; // global variable? logicalvar = (flags & 0x0200) != 0; // boolean ? arrayclass = (arrayclasstype)(flags & 0xff); ! read_int (is, swap, nnz); // number of non-zero in sparse // dimensions array subelement { --- 495,501 ---- global = (flags & 0x0400) != 0; // global variable? logicalvar = (flags & 0x0200) != 0; // boolean ? arrayclass = (arrayclasstype)(flags & 0xff); ! read_int (is, swap, nzmax); // max number of non-zero in sparse // dimensions array subelement { *************** *** 587,593 **** int nc = dims(1); SparseMatrix sm; SparseComplexMatrix scm; - NDArray re; int *ridx; int *cidx; double *data; --- 587,592 ---- *************** *** 597,613 **** { scm = SparseComplexMatrix (static_cast (nr), static_cast (nc), ! static_cast (nnz)); ridx = scm.ridx (); cidx = scm.cidx (); ! re = NDArray (dim_vector (static_cast (nnz))); ! data = re.fortran_vec (); } else { sm = SparseMatrix (static_cast (nr), static_cast (nc), ! static_cast (nnz)); ridx = sm.ridx (); cidx = sm.cidx (); data = sm.data (); --- 596,611 ---- { scm = SparseComplexMatrix (static_cast (nr), static_cast (nc), ! static_cast (nzmax)); ridx = scm.ridx (); cidx = scm.cidx (); ! data = 0; } else { sm = SparseMatrix (static_cast (nr), static_cast (nc), ! static_cast (nzmax)); ridx = sm.ridx (); cidx = sm.cidx (); data = sm.data (); *************** *** 624,630 **** tmp_pos = is.tellg (); ! read_mat5_integer_data (is, ridx, nnz, swap, (enum mat5_data_type) type); if (! is || error_state) --- 622,628 ---- tmp_pos = is.tellg (); ! read_mat5_integer_data (is, ridx, nzmax, swap, (enum mat5_data_type) type); if (! is || error_state) *************** *** 662,667 **** --- 660,673 ---- goto data_read_error; } + FOUR_BYTE_INT nnz = cidx[nc]; + NDArray re; + if (imag) + { + re = NDArray (dim_vector (static_cast (nnz))); + data = re.fortran_vec (); + } + tmp_pos = is.tellg (); read_mat5_binary_data (is, data, nnz, swap, (enum mat5_data_type) type, flt_fmt); --------------000401030208060709010104-- ------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web: http://www.octave.org How to fund new projects: http://www.octave.org/funding.html Subscription information: http://www.octave.org/archive.html -------------------------------------------------------------