Skip to content

Commit 25972b5

Browse files
author
Keith Clawson
committed
Ensure that lil_matrix returns data consistent with its dtype.
1 parent 61113c8 commit 25972b5

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

scipy/sparse/compressed.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ def _get_single_element(self,row,col):
378378

379379
if num_matches == 0:
380380
# entry does not appear in the matrix
381-
return 0
381+
return self.dtype.type(0)
382382
elif num_matches == 1:
383383
return self.data[start:end][indxs[0]]
384384
else:

scipy/sparse/lil.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ def _get1(self, i, j):
193193

194194
pos = bisect_left(row, j)
195195
if pos != len(data) and row[pos] == j:
196-
return data[pos]
196+
return self.dtype.type(data[pos])
197197
else:
198198
return self.dtype.type(0)
199199

@@ -328,7 +328,7 @@ def __setitem__(self, index, x):
328328
if isspmatrix(x):
329329
if isinstance(i, slice) and i == slice(None) and \
330330
isinstance(j, slice) and j == slice(None):
331-
x = lil_matrix(x)
331+
x = lil_matrix(x, dtype=self.dtype)
332332
self.rows = x.rows
333333
self.data = x.data
334334
return

0 commit comments

Comments
 (0)