[][src]Struct petal_neighbors::VantagePointTree

pub struct VantagePointTree<'a, A> where
    A: Float
{ /* fields omitted */ }

A data structure for nearest neighbor search in a multi-dimensional space, which is partitioned into two parts for each vantage point: those points closer to the vantage point than a threshold, and those farther.

Implementations

impl<'a, A> VantagePointTree<'a, A> where
    A: Float + Zero + AddAssign + 'a, 
[src]

pub fn new<T>(points: T, distance: Distance<A>) -> Result<Self, ArrayError> where
    T: Into<CowArray<'a, A, Ix2>>, 
[src]

Builds a vantage point tree using the given distance metric.

Errors

  • ArrayError::Empty if points is an empty array.
  • ArrayError::NotContiguous if any row in points is not contiguous in memory.

pub fn euclidean<T>(points: T) -> Result<Self, ArrayError> where
    T: Into<CowArray<'a, A, Ix2>>, 
[src]

Builds a vantage point tree with a euclidean distance metric.

Errors

  • ArrayError::Empty if points is an empty array.
  • ArrayError::NotContiguous if any row in points is not contiguous in memory.

pub fn query_nearest<S>(&self, needle: &ArrayBase<S, Ix1>) -> (usize, A) where
    S: Data<Elem = A>, 
[src]

Finds the nearest neighbor and its distance in the tree.

Examples

use ndarray::{array, aview1};
use petal_neighbors::{VantagePointTree, distance};

let points = array![[1., 1.], [1., 2.], [9., 9.]];
let tree = VantagePointTree::euclidean(points).expect("valid array");
let (index, distance) = tree.query_nearest(&aview1(&[8., 8.]));
assert_eq!(index, 2);  // points[2] is the nearest.
assert!((2_f64.sqrt() - distance).abs() < 1e-8);

Auto Trait Implementations

impl<'a, A> RefUnwindSafe for VantagePointTree<'a, A> where
    A: RefUnwindSafe
[src]

impl<'a, A> Send for VantagePointTree<'a, A> where
    A: Send + Sync
[src]

impl<'a, A> Sync for VantagePointTree<'a, A> where
    A: Sync
[src]

impl<'a, A> Unpin for VantagePointTree<'a, A> where
    A: Unpin
[src]

impl<'a, A> UnwindSafe for VantagePointTree<'a, A> where
    A: RefUnwindSafe + UnwindSafe
[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.