Skip to content

Commit

Permalink
address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
dschult committed May 8, 2024
1 parent 859e3ee commit 9c4c3ec
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 15 deletions.
7 changes: 3 additions & 4 deletions scipy/sparse/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,11 +338,10 @@ def __str__(self):

A = self.tocoo()


# helper function, outputs "(i,j) v"
def tostr(coords, data):
triples = zip(list(zip(*coords)), data)
return '\n'.join([(' {}\t{}'.format(*t)) for t in triples])
pairs = zip(zip(*coords), data)
return '\n'.join(f' {idx}\t{val}' for idx, val in pairs)

out = repr(self)
if self.nnz == 0:
Expand All @@ -353,7 +352,7 @@ def tostr(coords, data):
half = maxprint // 2
out += tostr(tuple(c[:half] for c in A.coords), A.data[:half])
out += "\n :\t:\n"
half = maxprint - maxprint//2
half = maxprint - half
out += tostr(tuple(c[-half:] for c in A.coords), A.data[-half:])
else:
out += tostr(A.coords, A.data)
Expand Down
11 changes: 0 additions & 11 deletions scipy/sparse/_lil.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,6 @@ def count_nonzero(self):
_getnnz.__doc__ = _spbase._getnnz.__doc__
count_nonzero.__doc__ = _spbase.count_nonzero.__doc__

def __str__(self):
val = repr(self)
if self.nnz == 0:
return val

val += '\n Coords\tValue\n'
for i, row in enumerate(self.rows):
for pos, j in enumerate(row):
val += f" {str((i, j))}\t{str(self.data[i][pos])}\n"
return val[:-1]

def getrowview(self, i):
"""Returns a view of the 'i'th row (without copying).
"""
Expand Down

0 comments on commit 9c4c3ec

Please sign in to comment.