[Scipy-svn] r4691 - in trunk/scipy/sparse: . tests
scipy-svn at scipy.org
scipy-svn at scipy.org
Fri Sep 5 10:18:43 EDT 2008
Author: wnbell
Date: 2008-09-05 09:18:40 -0500 (Fri, 05 Sep 2008)
New Revision: 4691
Modified:
trunk/scipy/sparse/lil.py
trunk/scipy/sparse/tests/test_base.py
Log:
fixed lil_matrix fancy indexing problem pointed out by RC
Modified: trunk/scipy/sparse/lil.py
===================================================================
--- trunk/scipy/sparse/lil.py 2008-09-05 12:55:38 UTC (rev 4690)
+++ trunk/scipy/sparse/lil.py 2008-09-05 14:18:40 UTC (rev 4691)
@@ -294,18 +294,20 @@
elif not isinstance(x, spmatrix):
x = lil_matrix(x)
- if isspmatrix(x) and index == (slice(None), slice(None)):
- # self[:,:] = other_sparse
- x = lil_matrix(x)
- self.rows = x.rows
- self.data = x.data
- return
-
try:
i, j = index
except (ValueError, TypeError):
raise IndexError, "invalid index"
+ if isspmatrix(x):
+ if (isinstance(i, slice) and (i == slice(None))) and \
+ (isinstance(j, slice) and (j == slice(None))):
+ # self[:,:] = other_sparse
+ x = lil_matrix(x)
+ self.rows = x.rows
+ self.data = x.data
+ return
+
if isscalar(i):
row = self.rows[i]
data = self.data[i]
Modified: trunk/scipy/sparse/tests/test_base.py
===================================================================
--- trunk/scipy/sparse/tests/test_base.py 2008-09-05 12:55:38 UTC (rev 4690)
+++ trunk/scipy/sparse/tests/test_base.py 2008-09-05 14:18:40 UTC (rev 4691)
@@ -1260,6 +1260,12 @@
D = lil_matrix(C)
assert_array_equal(C.A, D.A)
+ def test_fancy_indexing(self):
+ M = arange(25).reshape(5,5)
+ A = lil_matrix( M )
+
+ assert_equal(A[array([1,2,3]),2:3].todense(), M[array([1,2,3]),2:3])
+
def test_point_wise_multiply(self):
l = lil_matrix((4,3))
l[0,0] = 1
More information about the Scipy-svn
mailing list