Ticket #870 (closed defect: fixed)
dok_matrix can't handle setting unset elements to zero (was: KDtree sparse distance matrix doesn't handle distance=0 case)
| Reported by: | aric | Owned by: | peridot |
|---|---|---|---|
| Priority: | normal | Milestone: | 0.8.0 |
| Component: | scipy.sparse | Version: | devel |
| Keywords: | KDtree sparse distance matrix | Cc: | peridot.faceted@… |
Description
When the distance between two points is zero sparse_distance_matrix() breaks:
>>> import scipy
>>> import scipy.spatial
>>> a=scipy.array([[1,2],[3,4]])
>>> k=scipy.spatial.KDTree(a)
>>> k.sparse_distance_matrix(k,10)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/aric/lib/python/scipy/spatial/kdtree.py", line 628, in sparse_distance_matrix
other.tree, Rectangle(other.maxes, other.mins))
File "/Users/aric/lib/python/scipy/spatial/kdtree.py", line 611, in traverse
result[i,j] = d
File "/Users/aric/lib/python/scipy/sparse/dok.py", line 222, in __setitem__
del self[(i,j)]
KeyError: (0, 0)
A (probably not efficient) fix is to modify line 610 in kdtree.py to check for the zero case
if d<=max_distance and d !=0:
Change History
Note: See
TracTickets for help on using
tickets.
