[Scipy-svn] r2521 - trunk/Lib/sparse
scipy-svn at scipy.org
scipy-svn at scipy.org
Wed Jan 10 08:14:19 CST 2007
Author: wnbell
Date: 2007-01-10 08:14:16 -0600 (Wed, 10 Jan 2007)
New Revision: 2521
Modified:
trunk/Lib/sparse/sparse.py
Log:
Added missing check for indptr dtype and small changes to .transpose()
Modified: trunk/Lib/sparse/sparse.py
===================================================================
--- trunk/Lib/sparse/sparse.py 2007-01-10 13:15:48 UTC (rev 2520)
+++ trunk/Lib/sparse/sparse.py 2007-01-10 14:14:16 UTC (rev 2521)
@@ -812,7 +812,9 @@
"the size of data list"
if (self.rowind.dtype != numpy.intc):
self.rowind = self.rowind.astype(numpy.intc)
+ if (self.indptr.dtype != numpy.intc):
self.indptr = self.indptr.astype(numpy.intc)
+
self.nnz = nnz
self.nzmax = nzmax
self.dtype = self.data.dtype
@@ -852,18 +854,18 @@
def transpose(self, copy=False):
M, N = self.shape
- new = csr_matrix((N, M), nzmax=self.nzmax, dtype=self.dtype)
+
if copy:
- new.data = self.data.copy()
- new.colind = self.rowind.copy()
- new.indptr = self.indptr.copy()
+ data = self.data.copy()
+ colind = self.rowind.copy()
+ indptr = self.indptr.copy()
else:
- new.data = self.data
- new.colind = self.rowind
- new.indptr = self.indptr
- new._check()
- return new
+ data = self.data
+ colind = self.rowind
+ indptr = self.indptr
+ return csr_matrix((data,colind,indptr),(N,M))
+
def conj(self, copy=False):
new = csc_matrix(self.shape, nzmax=self.nzmax, dtype=self.dtype)
if copy:
@@ -1215,7 +1217,9 @@
"the size of data list"
if (self.colind.dtype != numpy.intc):
self.colind = self.colind.astype(numpy.intc)
+ if (self.indptr.dtype != numpy.intc):
self.indptr = self.indptr.astype(numpy.intc)
+
self.nnz = nnz
self.nzmax = nzmax
self.dtype = self.data.dtype
@@ -1235,18 +1239,18 @@
def transpose(self, copy=False):
M, N = self.shape
- new = csc_matrix((N, M), nzmax=self.nzmax, dtype=self.dtype)
+
if copy:
- new.data = self.data.copy()
- new.rowind = self.colind.copy()
- new.indptr = self.indptr.copy()
+ data = self.data.copy()
+ rowind = self.colind.copy()
+ indptr = self.indptr.copy()
else:
- new.data = self.data
- new.rowind = self.colind
- new.indptr = self.indptr
- new._check()
- return new
+ data = self.data
+ rowind = self.colind
+ indptr = self.indptr
+ return csc_matrix((data,rowind,indptr),(N,M))
+
def sum(self, axis=None):
# Override the base class sum method for efficiency in the cases
# axis=1 and axis=None.
More information about the Scipy-svn
mailing list