Crates.io | knn |
lib.rs | knn |
version | 0.1.3 |
source | src |
created_at | 2020-05-22 06:27:14.161969 |
updated_at | 2020-05-22 08:39:05.617713 |
description | A library to compute KNN. |
homepage | https://github.com/abhicnv007/knn |
repository | https://github.com/abhicnv007/knn.git |
max_upload_size | |
id | 244440 |
size | 13,898 |
A library to find nearest neighbours in rust.
Add this to your Cargo.toml
[dependencies]
knn = "0.1.3"
and use like this
extern crate knn;
use knn::PointCloud;
fn main() {
let manhattan = |p: &[f64;2], q: &[f64;2]| {(q[0] - p[0]).abs() + (q[1] - p[1]).abs()};
let mut pc = PointCloud::new(manhattan);
let coords = vec![[1.0, 1.0], [2.0, 2.0], [10.0, 5.0], [11.0, 15.0]];
for i in 0..coords.len() {
pc.add_point(&coords[i]);
}
let d = pc.get_nearest_n(&[2.1, 2.1], 2);
println!("{:?}", d)
// output :
// [(0.20000000000000018, [2.0, 2.0]), (2.2, [1.0, 1.0])]
}
For updated and detailed docs refer here