[SciPy-dev] matlab5 sparse IO
Nathan Bell
wnbell@gmail....
Thu Jan 3 16:29:32 CST 2008
On Jan 3, 2008 1:36 PM, Stefan van der Walt <stefan@sun.ac.za> wrote:
> This should now be fixed (r3770). Please give it a whirl and let me
> know.
Thanks for clearing this up Stefan.
I see two remaining issues: sorted indices and non-double data types.
MATLAB seems to expect sorted row indices, which can be fixed with a simple:
A = self.arr.tocsc()
A.sort_indices()
I have committed this change to SVN.
When loading 'byte.mat' and 'single.mat' produced by the script below I get:
>> load byte
>> A
A =
1.0e-316 *
(1,1) 0.8322
(2,1) 0
(3,1) 0
(4,1) 0
>> load single
>> A
A =
(1,1) 0.0078
(2,1) 0.0078
(3,1) 0
(4,1) 0
So something is amiss with the data array. It appears to be loading
the data as double precision no matter what dtype is used.
Interestingly, scipy's loadmat() works properly on byte.mat and
single.mat. I'm using MATLAB R2007b (linux,32-bit).
from scipy import *
from scipy.sparse import *
from scipy.io import savemat
indptr = array([0, 4])
indices = array([3, 2, 1, 0])
data = array([ 1., 1., 1., 1.])
A = csc_matrix((data,indices,indptr),shape=(4,1))
savemat('unsorted.mat',{'A' : A }, format='5')
A.sort_indices()
savemat('sorted.mat',{'A' : A }, format='5')
A = A.astype('int8')
savemat('byte.mat',{'A' : A }, format='5')
A = A.astype('f4')
savemat('single.mat',{'A' : A }, format='5')
--
Nathan Bell wnbell@gmail.com
http://graphics.cs.uiuc.edu/~wnbell/
More information about the Scipy-dev
mailing list