knn

Crates.ioknn
lib.rsknn
version0.1.3
sourcesrc
created_at2020-05-22 06:27:14.161969
updated_at2020-05-22 08:39:05.617713
descriptionA library to compute KNN.
homepagehttps://github.com/abhicnv007/knn
repositoryhttps://github.com/abhicnv007/knn.git
max_upload_size
id244440
size13,898
Abhishek N V (abhicnv007)

documentation

https://docs.rs/knn

README

Pointcloud

Build Status

A library to find nearest neighbours in rust.

Usage

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

Commit count: 50

cargo fmt