Skip to content

Commit dc7e0c7

Browse files
committed
Merge pull request scipy#367 from kclawson/bug-fixes
Fix for ticket scipy#1604
2 parents 9ff0cdd + 25972b5 commit dc7e0c7

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,9 @@ 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:
198-
return 0
198+
return self.dtype.type(0)
199199

200200
def _slicetoseq(self, j, shape):
201201
if j.start is not None and j.start < 0:
@@ -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

scipy/sparse/tests/test_base.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1609,6 +1609,11 @@ def test_inplace_ops(self):
16091609

16101610
assert_array_equal(result.todense(), expected.todense())
16111611

1612+
# Ticket 1604.
1613+
A = lil_matrix((1,3), dtype=np.dtype('float64'))
1614+
B = array([0.1,0.1,0.1])
1615+
A[0,:] += B
1616+
assert_array_equal(A[0,:].toarray().squeeze(), B)
16121617

16131618
def test_lil_slice_assignment(self):
16141619
B = lil_matrix((4,3))

0 commit comments

Comments
 (0)