[SciPy-dev] Please stress-test SVN version pf matlab reader

David Cournapeau cournape@gmail....
Tue Jan 5 23:45:37 CST 2010

On Wed, Jan 6, 2010 at 12:07 PM, David Cournapeau <cournape@gmail.com> wrote:
> Hi Matthew,
> On Wed, Jan 6, 2010 at 11:00 AM, Matthew Brett <matthew.brett@gmail.com> wrote:
>> Hi,
>> For those of you interested in the matlab reader in scipy - a bout of
>> 'flu left me with only enough energy to try and work out the last
>> undocumented bits of the matlab file format.  I _believe_ that the
>> current  SVN version of the reader:
>> import scipy.io as sio
>> a = sio.loadmat('your_matfile_here.mat')
>> should successfully read any non-HDF matlab-written matfile - and this
>> is just to ask if those of you, with mat files lying around, could try
>> out the latest SVN version, and let me know that I am wrong, most
>> usefully with some way of me being able to reproduce the problem.
> That's great news. I have just added the numscons scripts for the new files.
> Funnily enough, I was just toying with sparse matrices, and needed to
> load some sparse matrices. Here is the problem I got with some sparse
> files:
> from scipy.io import loadmat
> loadmat("odepa400.mat")
> This raises an exception:
> Traceback (most recent call last):
>  File "read.py", line 3, in <module>
>    loadmat("odepa400.mat")
>  File "/home/david/local/lib/python2.6/site-packages/scipy/io/matlab/mio.py",
> line 134, in loadmat
>    matfile_dict = MR.get_variables()
>  File "/home/david/local/lib/python2.6/site-packages/scipy/io/matlab/mio5.py",
> line 347, in get_variables
>    res = self.read_var_array(hdr)
>  File "/home/david/local/lib/python2.6/site-packages/scipy/io/matlab/mio5.py",
> line 321, in read_var_array
>    return self._matrix_reader.array_from_header(header, process)
>  File "mio5_utils.pyx", line 584, in
> scipy.io.matlab.mio5_utils.VarReader5.array_from_header
> (scipy/io/matlab/mio5_utils.c:4721)
>  File "mio5_utils.pyx", line 629, in
> scipy.io.matlab.mio5_utils.VarReader5.array_from_header
> (scipy/io/matlab/mio5_utils.c:4370)
>  File "mio5_utils.pyx", line 835, in
> scipy.io.matlab.mio5_utils.VarReader5.read_struct
> (scipy/io/matlab/mio5_utils.c:6774)
>  File "mio5_utils.pyx", line 582, in
> scipy.io.matlab.mio5_utils.VarReader5.read_mi_matrix
> (scipy/io/matlab/mio5_utils.c:3999)
> TypeError: Cannot convert csc_matrix to numpy.ndarray
> (I needed to fix a missing import first)
> The matrix may be found here:
> http://www.cise.ufl.edu/research/sparse/mat/Bai/odepa400.mat (small file)

Ok, I took a look at it, and the problem is caused by the sparse
matrix to be in a struct. The fix is easy, and just consists in
telling read_mi_matrix function not to return a cnp.ndarray (as
array_from_header does not necessarily return a cnp.ndarray).

I don't have matlab handy to add a unit test, but adding it should be easy,



More information about the SciPy-Dev mailing list