[Scipy-tickets] [SciPy] #870: KDtree sparse distance matrix doesn't handle distance=0 case

SciPy scipy-tickets@scipy....
Mon Feb 16 14:16:27 CST 2009

```#870: KDtree sparse distance matrix doesn't handle distance=0 case
--------------------+-------------------------------------------------------
Reporter:  aric    |       Owner:  somebody
Type:  defect  |      Status:  new
Priority:  normal  |   Milestone:  0.8.0
Component:  Other   |     Version:  devel
Severity:  normal  |    Keywords:
--------------------+-------------------------------------------------------
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:
}}}

--
Ticket URL: <http://scipy.org/scipy/scipy/ticket/870>
SciPy <http://www.scipy.org/>
SciPy is open-source software for mathematics, science, and engineering.
```