[SciPy-dev] matlab5 sparse IO
Nathan Bell
wnbell at gmail.com
Wed Jan 2 18:34:45 EST 2008
First let me thank those who have contributed to MATLAB IO in scipy.
I noticed that the Matlab4 sparse writer was a little slow, so I sped
it up using the coo_matrix format. Anyway, I was going to do the same
for the Matlab5 writer, but it seems to be broken. It appears that
the V5 code was a copy/paste of the V4 method, which it shouldn't be.
http://projects.scipy.org/scipy/scipy/browser/trunk/scipy/io/matlab/mio5.py#L662
Looking at the V5 sparse reader:
http://projects.scipy.org/scipy/scipy/browser/trunk/scipy/io/matlab/mio5.py#L349
suggests that the CSC format should be used when writing, but the
present code - even if it worked properly - appears to be writing out
a triplet format (as is done in V4).
I don't fully understand all the magic in the matlab IO code, but I'd
be happy to help whomever maintains it in adding sparse V5 support.
Here's a simple test that currently fails:
from scipy import *
from scipy.sparse import *
from scipy.io import *
from numpy.testing import *
A = csr_matrix([[1.0,0.0,2.0],[0,-3.5,0]])
savemat('test4.mat', { 'A': A }, format='4')
A4 = loadmat('test4.mat')['A']
assert_equal(A.todense(),A4.todense())
savemat('test5.mat', { 'A': A }, format='5')
A5 = loadmat('test5.mat')['A']
assert_equal(A.todense(),A5.todense())
Note that the failure in savemat(... format='5') is currently just a
typo (N is used as a variable and for numpy), but I think there are
more fundamental issues as well.
--
Nathan Bell wnbell at gmail.com
More information about the SciPy-Dev
mailing list