[Scipy-svn] r3610 - in trunk/scipy/sparse: . tests
scipy-svn at scipy.org
scipy-svn at scipy.org
Sun Dec 2 22:31:46 EST 2007
Author: wnbell
Date: 2007-12-02 21:31:42 -0600 (Sun, 02 Dec 2007)
New Revision: 3610
Modified:
trunk/scipy/sparse/sparse.py
trunk/scipy/sparse/tests/test_sparse.py
Log:
fixed CSR/CSC infer shape from data
Modified: trunk/scipy/sparse/sparse.py
===================================================================
--- trunk/scipy/sparse/sparse.py 2007-12-03 03:02:53 UTC (rev 3609)
+++ trunk/scipy/sparse/sparse.py 2007-12-03 03:31:42 UTC (rev 3610)
@@ -542,9 +542,9 @@
self.data = zeros((nzmax,), self.dtype)
self.indices = zeros((nzmax,), intc)
if self.format[-1] == 'r':
- self.indptr = zeros(M+1, intc)
+ self.indptr = zeros(M+1, dtype='intc')
else:
- self.indptr = zeros(N+1,intc)
+ self.indptr = zeros(N+1, dtype='intc')
else:
try:
# Try interpreting it as (data, ij)
@@ -578,11 +578,17 @@
if self.shape is None:
# shape not already set, try to infer dimensions
try:
- M = len(self.indptr) - 1
- N = self.indices.max() + 1
- self.shape = (M,N)
+ first_dim = len(self.indptr) - 1
+ second_dim = self.indices.max() + 1
except:
raise ValueError,'unable to infer matrix dimensions'
+ else:
+ if self.format[-1] == 'r':
+ # row oriented matrix
+ self.shape = (first_dim,second_dim)
+ else:
+ # column oriented matrix
+ self.shape = (second_dim,first_dim)
self.check_format(full_check=False)
Modified: trunk/scipy/sparse/tests/test_sparse.py
===================================================================
--- trunk/scipy/sparse/tests/test_sparse.py 2007-12-03 03:02:53 UTC (rev 3609)
+++ trunk/scipy/sparse/tests/test_sparse.py 2007-12-03 03:31:42 UTC (rev 3610)
@@ -701,7 +701,7 @@
## assert_equal(a.indices.dtype,numpy.dtype('int64'))
## assert_array_equal(a.todense(),b)
- def check_constructor5(self):
+ def check_constructor4(self):
"""using (data, ij) format"""
row = numpy.array([2, 3, 1, 3, 0, 1, 3, 0, 2, 1, 2])
col = numpy.array([0, 1, 0, 0, 1, 1, 2, 2, 2, 2, 1])
@@ -712,7 +712,14 @@
csr = csr_matrix((data,ij),(4,3))
assert_array_equal(arange(12).reshape(4,3),csr.todense())
-
+ def check_constructor5(self):
+ """infer dimensions from arrays"""
+ indptr = array([0,1,3,3])
+ indices = array([0,5,1,2])
+ data = array([1,2,3,4])
+ csr = csr_matrix((data, indices, indptr))
+ assert_array_equal(csr.shape,(3,6))
+
def check_empty(self):
"""Test manipulating empty matrices. Fails in SciPy SVN <= r1768
"""
@@ -788,7 +795,7 @@
assert_array_equal(bsp.indices,[0,2])
assert_array_equal(bsp.indptr,[0,1,2])
- def check_constructor5(self):
+ def check_constructor4(self):
"""using (data, ij) format"""
row = numpy.array([2, 3, 1, 3, 0, 1, 3, 0, 2, 1, 2])
col = numpy.array([0, 1, 0, 0, 1, 1, 2, 2, 2, 2, 1])
@@ -799,6 +806,14 @@
csc = csc_matrix((data,ij),(4,3))
assert_array_equal(arange(12).reshape(4,3),csc.todense())
+ def check_constructor5(self):
+ """infer dimensions from arrays"""
+ indptr = array([0,1,3,3])
+ indices = array([0,5,1,2])
+ data = array([1,2,3,4])
+ csc = csc_matrix((data, indices, indptr))
+ assert_array_equal(csc.shape,(6,3))
+
def check_empty(self):
"""Test manipulating empty matrices. Fails in SciPy SVN <= r1768
"""
More information about the Scipy-svn
mailing list