edmkit 0.0.7__tar.gz → 0.0.8__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,13 +1,13 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: edmkit
3
- Version: 0.0.7
3
+ Version: 0.0.8
4
4
  Summary: Simple EDM (Empirical Dynamic Modeling) library
5
5
  Author: FUJISHIGE TEMMA
6
6
  Author-email: FUJISHIGE TEMMA <tenma.x0@gmail.com>
7
+ Requires-Dist: kdtree-rs>=0.1.0
7
8
  Requires-Dist: numpy>=2.4.3
8
9
  Requires-Dist: scipy>=1.17.1
9
10
  Requires-Dist: tinygrad>=0.11.0
10
- Requires-Dist: usearch>=2.23.0
11
11
  Requires-Python: >=3.13
12
12
  Description-Content-Type: text/markdown
13
13
 
@@ -1,15 +1,15 @@
1
1
  [project]
2
2
  name = "edmkit"
3
- version = "0.0.7"
3
+ version = "0.0.8"
4
4
  description = "Simple EDM (Empirical Dynamic Modeling) library"
5
5
  authors = [{ name = "FUJISHIGE TEMMA", email = "tenma.x0@gmail.com" }]
6
6
  readme = "README.md"
7
7
  requires-python = ">= 3.13"
8
8
  dependencies = [
9
+ "kdtree-rs>=0.1.0",
9
10
  "numpy>=2.4.3",
10
11
  "scipy>=1.17.1",
11
12
  "tinygrad>=0.11.0",
12
- "usearch>=2.23.0",
13
13
  ]
14
14
 
15
15
  [dependency-groups]
@@ -0,0 +1,31 @@
1
+ import numpy as np
2
+ from kdtree import KDTree
3
+
4
+
5
+ def knn(X: np.ndarray, Q: np.ndarray, k: int) -> tuple[np.ndarray, np.ndarray]:
6
+ """Find the k-nearest neighbors of `Q` in `X` using `kdtree.KDTree`.
7
+
8
+ Parameters
9
+ ----------
10
+ X : np.ndarray
11
+ The input data (N, E)
12
+ Q : np.ndarray
13
+ The query points (M, E)
14
+ k : int
15
+ The number of nearest neighbors to find (typically E+1 for simplex projection).
16
+
17
+ Returns
18
+ -------
19
+ distances : np.ndarray
20
+ The distances from each query point in `Q` to its k nearest neighbors in `X` (M, k)
21
+ indices : np.ndarray
22
+ The indices of the k nearest neighbors in `X` for each query point in `Q` (M, k)
23
+ """
24
+
25
+ N = X.shape[0]
26
+
27
+ if N < k:
28
+ raise ValueError(f"Not enough points in X to find {k} neighbors, got N={N}")
29
+
30
+ tree = KDTree(X)
31
+ return tree.query(Q, k=k)
@@ -1,40 +0,0 @@
1
- import numpy as np
2
- from scipy.spatial import KDTree
3
- from usearch.index import Index
4
-
5
-
6
- def knn(X: np.ndarray, Q: np.ndarray, k: int) -> tuple[np.ndarray, np.ndarray]:
7
- """Find the k-nearest neighbors of `Q` in `X` using either `usearch` or `scipy.spatial.KDTree` depending on the size and dimensionality of the data.
8
-
9
- Parameters
10
- ----------
11
- X : np.ndarray
12
- The input data (N, E)
13
- Q : np.ndarray
14
- The query points (M, E)
15
- k : int
16
- The number of nearest neighbors to find (typically E+1 for simplex projection).
17
-
18
- Returns
19
- -------
20
- distances : np.ndarray
21
- The distances from each query point in `Q` to its k nearest neighbors in `X` (M, k)
22
- indices : np.ndarray
23
- The indices of the k nearest neighbors in `X` for each query point in `Q` (M, k)
24
- """
25
-
26
- N, E = X.shape
27
-
28
- if N < k:
29
- raise ValueError(f"Not enough points in X to find {k} neighbors, got N={N}")
30
-
31
- if E >= 15 and N >= 10_000:
32
- index = Index(ndim=E, metric="l2sq")
33
- index.add(np.arange(len(X)), np.ascontiguousarray(X, dtype=np.float32))
34
- matches = index.search(np.ascontiguousarray(Q, dtype=np.float32), k)
35
- distances = np.atleast_2d(np.sqrt(np.asarray(matches.distances)))
36
- indices = np.atleast_2d(np.asarray(matches.keys).astype(np.intp))
37
- return distances, indices
38
- else:
39
- tree = KDTree(X)
40
- return tree.query(Q, k=k)
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes