[Scipy-svn] r3104 - in trunk/Lib/io: . tests
scipy-svn@scip...
scipy-svn@scip...
Wed Jun 13 18:26:50 CDT 2007
Author: wnbell
Date: 2007-06-13 18:26:47 -0500 (Wed, 13 Jun 2007)
New Revision: 3104
Modified:
trunk/Lib/io/mmio.py
trunk/Lib/io/tests/test_mmio.py
Log:
fixed sparse coordinate matrix indices to be base 1 as in the MM standard
added unittest to prevent problem in the future
Modified: trunk/Lib/io/mmio.py
===================================================================
--- trunk/Lib/io/mmio.py 2007-06-13 13:56:32 UTC (rev 3103)
+++ trunk/Lib/io/mmio.py 2007-06-13 23:26:47 UTC (rev 3104)
@@ -333,11 +333,10 @@
assert symm=='general',`symm`
if field in ['real','integer']:
for i in range(entries):
- target.write(format % (a.rowcol(i)+(a.getdata(i),)))
+ target.write(format % (a.row[i]+1,a.col[i]+1,a.data[i]))
elif field=='complex':
for i in range(entries):
- value = a.getdata(i)
- target.write(format % ((a.rowcol(i))+(real(value),imag(value))))
+ target.write(format % (a.row[i]+1,a.col[i]+1,reak(a.data[i]),imag(a.data[i])))
elif field=='pattern':
raise NotImplementedError,`field`
else:
Modified: trunk/Lib/io/tests/test_mmio.py
===================================================================
--- trunk/Lib/io/tests/test_mmio.py 2007-06-13 13:56:32 UTC (rev 3103)
+++ trunk/Lib/io/tests/test_mmio.py 2007-06-13 23:26:47 UTC (rev 3104)
@@ -6,6 +6,7 @@
set_package_path()
from io.mmio import mminfo,mmread,mmwrite
+import scipy
restore_path()
class test_mmio_array(NumpyTestCase):
@@ -151,5 +152,25 @@
b = mmread(fn).todense()
assert_array_almost_equal(a,b)
+ def check_simple_write_read(self):
+ 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 ])
+
+ b = scipy.sparse.coo_matrix((V,(I,J)),dims=(5,5))
+
+ fn = mktemp()
+ mmwrite(fn,b)
+
+ assert_equal(mminfo(fn),(5,5,8,'coordinate','real','general'))
+ a = [[1, 0, 0, 6, 0],
+ [0, 10.5, 0, 0, 0],
+ [0, 0, .015, 0, 0],
+ [0, 250.5, 0, -280, 33.32],
+ [0, 0, 0, 0, 12]]
+ b = mmread(fn).todense()
+ assert_array_almost_equal(a,b)
+
+
if __name__ == "__main__":
NumpyTest().run()
More information about the Scipy-svn
mailing list