Skip to content

BUG: fix KD Tree node construction #11556

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/whats_new/v0.20.rst
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,9 @@ Neighbors
warning when no neighbors are found for samples. :issue:`9655` by
:user:`Andreas Bjerre-Nielsen <abjer>`.

- Fixed a bug in ``KDTree`` construction that results in faster construction
and querying times. :issue:`11556` by :user:`Jake VanderPlas <jakevdp>`

Feature Extraction

- Fixed a bug in :func:`feature_extraction.image.extract_patches_2d` which would
Expand Down
2 changes: 2 additions & 0 deletions sklearn/neighbors/kd_tree.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ cdef int init_node(BinaryTree tree, ITYPE_t i_node,
for j in range(n_features):
lower_bounds[j] = fmin(lower_bounds[j], data_row[j])
upper_bounds[j] = fmax(upper_bounds[j], data_row[j])

for j in range(n_features):
if tree.dist_metric.p == INF:
rad = fmax(rad, 0.5 * (upper_bounds[j] - lower_bounds[j]))
else:
Expand Down