Ticket #870 (closed defect: fixed)

Opened 19 months ago

Last modified 19 months ago

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

Changed 19 months ago by wnbell

  • keywords KDtree sparse distance matrix added
  • owner changed from somebody to peridot
  • component changed from Other to scipy.spatial

Changed 19 months ago by peridot

  • status changed from new to closed
  • resolution set to fixed
  • component changed from scipy.spatial to scipy.sparse
  • summary changed from KDtree sparse distance matrix doesn't handle distance=0 case to dok_matrix can't handle setting unset elements to zero (was: KDtree sparse distance matrix doesn't handle distance=0 case)

Changed 19 months ago by peridot

Fixed in r5584

Note: See TracTickets for help on using tickets.