[Scipy-svn] r6946 - in trunk/scipy/sparse: . tests
scipy-svn at scipy.org
scipy-svn at scipy.org
Fri Nov 26 22:36:50 EST 2010
Author: warren.weckesser
Date: 2010-11-26 21:36:50 -0600 (Fri, 26 Nov 2010)
New Revision: 6946
Modified:
trunk/scipy/sparse/dok.py
trunk/scipy/sparse/tests/test_base.py
Log:
BUG: sparse: fixed the resize() method of dok_matrix (ticket #997); thanks to jap for report and patch.
Modified: trunk/scipy/sparse/dok.py
===================================================================
--- trunk/scipy/sparse/dok.py 2010-11-27 00:31:04 UTC (rev 6945)
+++ trunk/scipy/sparse/dok.py 2010-11-27 03:36:50 UTC (rev 6946)
@@ -531,8 +531,9 @@
return self.tocoo().toarray()
def resize(self, shape):
- """ Resize the matrix to dimensions given by 'shape', removing any
- non-zero elements that lie outside.
+ """ Resize the matrix in-place to dimensions given by 'shape'.
+
+ Any non-zero elements that lie outside the new shape are removed.
"""
if not isshape(shape):
raise TypeError("dimensions must be a 2-tuple of positive"
@@ -544,7 +545,7 @@
for (i, j) in self.keys():
if i >= newM or j >= newN:
del self[i, j]
- self.shape = shape
+ self._shape = shape
Modified: trunk/scipy/sparse/tests/test_base.py
===================================================================
--- trunk/scipy/sparse/tests/test_base.py 2010-11-27 00:31:04 UTC (rev 6945)
+++ trunk/scipy/sparse/tests/test_base.py 2010-11-27 03:36:50 UTC (rev 6946)
@@ -1298,6 +1298,21 @@
c = csr_matrix(b)
assert_equal(A.todense(), c.todense())
+ def test_resize(self):
+ """A couple basic tests of the resize() method.
+
+ resize(shape) resizes the array in-place.
+ """
+ a = dok_matrix((5,5))
+ a[:,0] = 1
+ a.resize((2,2))
+ expected1 = array([[1,0],[1,0]])
+ assert_array_equal(a.todense(), expected1)
+ a.resize((3,2))
+ expected2 = array([[1,0],[1,0],[0,0]])
+ assert_array_equal(a.todense(), expected2)
+
+
def test_ticket1160(self):
"""Regression test for ticket #1160."""
a = dok_matrix((3,3))
More information about the Scipy-svn
mailing list