[Scipy-svn] r3893 - trunk/scipy/sparse
scipy-svn at scipy.org
scipy-svn at scipy.org
Sun Feb 3 14:44:44 EST 2008
Author: wnbell
Date: 2008-02-03 13:44:39 -0600 (Sun, 03 Feb 2008)
New Revision: 3893
Modified:
trunk/scipy/sparse/coo.py
trunk/scipy/sparse/csr.py
trunk/scipy/sparse/dok.py
trunk/scipy/sparse/lil.py
Log:
add nnz properties to all sparse matrices
ensure that coo indices are ints
Modified: trunk/scipy/sparse/coo.py
===================================================================
--- trunk/scipy/sparse/coo.py 2008-02-03 19:25:28 UTC (rev 3892)
+++ trunk/scipy/sparse/coo.py 2008-02-03 19:44:39 UTC (rev 3893)
@@ -121,8 +121,8 @@
except TypeError:
raise TypeError, "invalid input format"
- self.row = array(ij[0],copy=copy)
- self.col = array(ij[1],copy=copy)
+ self.row = array(ij[0],copy=copy,dtype=intc)
+ self.col = array(ij[1],copy=copy,dtype=intc)
self.data = array(obj,copy=copy)
if shape is None:
Modified: trunk/scipy/sparse/csr.py
===================================================================
--- trunk/scipy/sparse/csr.py 2008-02-03 19:25:28 UTC (rev 3892)
+++ trunk/scipy/sparse/csr.py 2008-02-03 19:44:39 UTC (rev 3893)
@@ -117,8 +117,8 @@
self.sort_indices() #lil_matrix needs sorted rows
- rows,data = lil.rows,lil.data
ptr,ind,dat = self.indptr,self.indices,self.data
+ rows, data = lil.rows, lil.data
for n in xrange(self.shape[0]):
start = ptr[n]
Modified: trunk/scipy/sparse/dok.py
===================================================================
--- trunk/scipy/sparse/dok.py 2008-02-03 19:25:28 UTC (rev 3892)
+++ trunk/scipy/sparse/dok.py 2008-02-03 19:44:39 UTC (rev 3893)
@@ -54,26 +54,26 @@
def getnnz(self):
return dict.__len__(self)
+ nnz = property(fget=getnnz)
def __len__(self):
return dict.__len__(self)
def __str__(self):
val = ''
- nnz = self.getnnz()
keys = self.keys()
keys.sort()
#TODO why does dok_matrix wipe out .maxprint?
- if nnz > self.maxprint:
+ if self.nnz > self.maxprint:
for k in xrange(self.maxprint / 2):
key = keys[k]
val += " %s\t%s\n" % (str(key), str(self[key]))
val = val + " : \t :\n"
- for k in xrange(nnz-self.maxprint/2, nnz):
+ for k in xrange(self.nnz - self.maxprint/2, self.nnz):
key = keys[k]
val += " %s\t%s\n" % (str(key), str(self[key]))
else:
- for k in xrange(nnz):
+ for k in xrange(self.nnz):
key = keys[k]
val += " %s\t%s\n" % (str(key), str(self[key]))
return val[:-1]
@@ -536,7 +536,7 @@
def tocoo(self):
""" Return a copy of this matrix in COOrdinate format"""
from coo import coo_matrix
- if self.getnnz() == 0:
+ if self.nnz == 0:
return coo_matrix(self.shape, dtype=self.dtype)
else:
data = asarray(self.values(), dtype=self.dtype)
Modified: trunk/scipy/sparse/lil.py
===================================================================
--- trunk/scipy/sparse/lil.py 2008-02-03 19:25:28 UTC (rev 3892)
+++ trunk/scipy/sparse/lil.py 2008-02-03 19:44:39 UTC (rev 3893)
@@ -126,6 +126,7 @@
def getnnz(self):
return sum([len(rowvals) for rowvals in self.data])
+ nnz = property(fget=getnnz)
def __str__(self):
val = ''
@@ -134,12 +135,6 @@
val += " %s\t%s\n" % (str((i, j)), str(self.data[i][pos]))
return val[:-1]
- #def __repr__(self):
- # format = self.getformat()
- # return "<%dx%d sparse matrix with %d stored "\
- # "elements in %s format>" % \
- # (self.shape + (self.getnnz(), _formats[format][1]))
-
def getrowview(self, i):
"""Returns a view of the 'i'th row (without copying).
"""
More information about the Scipy-svn
mailing list