Skip to content

Commit 6b3d47e

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 6665d23 commit 6b3d47e

File tree

6 files changed

+11
-7
lines changed

6 files changed

+11
-7
lines changed

DIRECTORY.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@
287287
* [Trie](data_structures/trie/trie.py)
288288
* KD Tree
289289
* [KD Tree Node](data_structures/kd_tree/kd_node.py)
290-
* [Build KD Tree](data_structures/kd_tree/build_kdtree.py)
290+
* [Build KD Tree](data_structures/kd_tree/build_kdtree.py)
291291
* [Nearest Neighbour Search](data_structures/kd_tree/nearest_neighbour_search.py)
292292
* [Hypercibe Points](data_structures/kd_tree/example/hypercube_points.py)
293293
* [Example Usage](data_structures/kd_tree/example/example_usage.py)

data_structures/kd_tree/build_kdtree.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from .kd_node import KDNode
22

3+
34
def build_kdtree(points, depth=0):
45
if not points:
56
return None
@@ -13,7 +14,7 @@ def build_kdtree(points, depth=0):
1314

1415
# Create node and construct subtrees
1516
return KDNode(
16-
point = points[median_idx],
17-
left = build_kdtree(points[:median_idx], depth + 1),
18-
right = build_kdtree(points[median_idx + 1:], depth + 1)
17+
point=points[median_idx],
18+
left=build_kdtree(points[:median_idx], depth + 1),
19+
right=build_kdtree(points[median_idx + 1 :], depth + 1),
1920
)

data_structures/kd_tree/example/example_usage.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414

1515
query_point = np.random.rand(num_dimensions).tolist()
1616

17-
nearest_point, nearest_dist, nodes_visited = nearest_neighbour_search(hypercube_kdtree, query_point)
17+
nearest_point, nearest_dist, nodes_visited = nearest_neighbour_search(
18+
hypercube_kdtree, query_point
19+
)
1820

1921
print(f"Query point: {query_point}")
2022
print(f"Nearest point: {nearest_point}")
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import numpy as np
22

3+
34
def hypercube_points(num_points, hypercube_size, num_dimensions):
45
return hypercube_size * np.random.rand(num_points, num_dimensions)

data_structures/kd_tree/kd_node.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
class KDNode:
2-
def __init__(self, point, left = None, right = None):
2+
def __init__(self, point, left=None, right=None):
33
self.point = point
44
self.left = left
55
self.right = right

data_structures/kd_tree/nearest_neighbour_search.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
def nearest_neighbour_search(root, query_point):
22
nearest_point = None
3-
nearest_dist = float('inf')
3+
nearest_dist = float("inf")
44
nodes_visited = 0
55

66
def search(node, depth=0):

0 commit comments

Comments
 (0)