[Scipy-svn] r4444 - in trunk/scipy/io: . tests
scipy-svn at scipy.org
scipy-svn at scipy.org
Thu Jun 12 23:08:52 EDT 2008
Author: wnbell
Date: 2008-06-12 22:08:49 -0500 (Thu, 12 Jun 2008)
New Revision: 4444
Modified:
trunk/scipy/io/mmio.py
trunk/scipy/io/tests/test_mmio.py
Log:
fix problem with writing CSR/CSC matrices in MatrixMarket format
Modified: trunk/scipy/io/mmio.py
===================================================================
--- trunk/scipy/io/mmio.py 2008-06-12 22:14:49 UTC (rev 4443)
+++ trunk/scipy/io/mmio.py 2008-06-13 03:08:49 UTC (rev 4444)
@@ -554,16 +554,16 @@
coo = a.tocoo() # convert to COOrdinate format
# write shape spec
- stream.write('%i %i %i\n' % (rows,cols,coo.nnz))
+ stream.write('%i %i %i\n' % (rows, cols, coo.nnz))
fmt = '%%.%dg' % precision
if field == self.FIELD_PATTERN:
- IJV = vstack((a.row, a.col)).T
+ IJV = vstack((coo.row, coo.col)).T
elif field in [ self.FIELD_INTEGER, self.FIELD_REAL ]:
- IJV = vstack((a.row, a.col, a.data)).T
+ IJV = vstack((coo.row, coo.col, coo.data)).T
elif field == self.FIELD_COMPLEX:
- IJV = vstack((a.row, a.col, a.data.real, a.data.imag)).T
+ IJV = vstack((coo.row, coo.col, coo.data.real, coo.data.imag)).T
else:
raise TypeError('Unknown field type %s' % `field`)
Modified: trunk/scipy/io/tests/test_mmio.py
===================================================================
--- trunk/scipy/io/tests/test_mmio.py 2008-06-12 22:14:49 UTC (rev 4443)
+++ trunk/scipy/io/tests/test_mmio.py 2008-06-13 03:08:49 UTC (rev 4444)
@@ -291,5 +291,28 @@
b = mmread(fn).todense()
assert_array_almost_equal(a,b)
+ def test_sparse_formats(self):
+ mats = []
+
+ I = array([0, 0, 1, 2, 3, 3, 3, 4])
+ J = array([0, 3, 1, 2, 1, 3, 4, 4])
+
+ V = array([ 1.0, 6.0, 10.5, 0.015, 250.5, -280.0, 33.32, 12.0 ])
+ mats.append( scipy.sparse.coo_matrix((V,(I,J)),shape=(5,5)) )
+
+ V = array([ 1.0 + 3j, 6.0 + 2j, 10.50 + 0.9j, 0.015 + -4.4j,
+ 250.5 + 0j, -280.0 + 5j, 33.32 + 6.4j, 12.00 + 0.8j])
+ mats.append( scipy.sparse.coo_matrix((V,(I,J)),shape=(5,5)) )
+
+ for mat in mats:
+ expected = mat.todense()
+ for fmt in ['csr','csc','coo']:
+ fn = mktemp()
+ mmwrite(fn, mat.asformat(fmt))
+
+ result = mmread(fn).todense()
+ assert_array_almost_equal(result, expected)
+
+
if __name__ == "__main__":
nose.run(argv=['', __file__])
More information about the Scipy-svn
mailing list