[−][src]Struct petal_neighbors::VantagePointTree
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]
A: Float + Zero + AddAssign + 'a,
pub fn new<T>(points: T, distance: Distance<A>) -> Result<Self, ArrayError> where
T: Into<CowArray<'a, A, Ix2>>,
[src]
T: Into<CowArray<'a, A, Ix2>>,
Builds a vantage point tree using the given distance metric.
Errors
ArrayError::Empty
ifpoints
is an empty array.ArrayError::NotContiguous
if any row inpoints
is not contiguous in memory.
pub fn euclidean<T>(points: T) -> Result<Self, ArrayError> where
T: Into<CowArray<'a, A, Ix2>>,
[src]
T: Into<CowArray<'a, A, Ix2>>,
Builds a vantage point tree with a euclidean distance metric.
Errors
ArrayError::Empty
ifpoints
is an empty array.ArrayError::NotContiguous
if any row inpoints
is not contiguous in memory.
pub fn query_nearest<S>(&self, needle: &ArrayBase<S, Ix1>) -> (usize, A) where
S: Data<Elem = A>,
[src]
S: Data<Elem = A>,
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]
A: RefUnwindSafe,
impl<'a, A> Send for VantagePointTree<'a, A> where
A: Send + Sync,
[src]
A: Send + Sync,
impl<'a, A> Sync for VantagePointTree<'a, A> where
A: Sync,
[src]
A: Sync,
impl<'a, A> Unpin for VantagePointTree<'a, A> where
A: Unpin,
[src]
A: Unpin,
impl<'a, A> UnwindSafe for VantagePointTree<'a, A> where
A: RefUnwindSafe + UnwindSafe,
[src]
A: RefUnwindSafe + UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,