Struct BallTree

Source
pub struct BallTree<T: Float + Send + Sync, D: Distance<T>> { /* private fields */ }
Expand description

Ball tree for efficient nearest neighbor searches

The ball tree partitions data into a set of nested hyperspheres (balls), which allows for efficient nearest neighbor searches, especially in high-dimensional spaces. Each node in the tree represents a ball containing a subset of the points.

§Type Parameters

  • T: Floating point type (f32 or f64)
  • D: Distance metric that implements the Distance trait

Implementations§

Source§

impl<T: Float + Send + Sync + 'static, D: Distance<T> + Send + Sync + 'static> BallTree<T, D>

Source

pub fn new( data: &ArrayView2<'_, T>, leaf_size: usize, distance: D, ) -> SpatialResult<BallTree<T, D>>

Create a new ball tree from the given data points

§Arguments
  • data - 2D array of data points (n_samples x n_features)
  • leaf_size - Maximum number of points in leaf nodes
  • distance - Distance metric to use
§Returns
  • SpatialResult<BallTree<T, D>> - A new ball tree
Source

pub fn query( &self, point: &[T], k: usize, return_distance: bool, ) -> SpatialResult<(Vec<usize>, Option<Vec<T>>)>

Query the k nearest neighbors to the given point

§Arguments
  • point - Query point
  • k - Number of neighbors to find
  • return_distance - Whether to return distances
§Returns
  • SpatialResult<(Vec<usize>, Option<Vec<T>>)> - Indices and optionally distances of the k nearest neighbors
Source

pub fn query_radius( &self, point: &[T], radius: T, return_distance: bool, ) -> SpatialResult<(Vec<usize>, Option<Vec<T>>)>

Find all points within a given radius of the query point

§Arguments
  • point - Query point
  • radius - Radius to search within
  • return_distance - Whether to return distances
§Returns
  • SpatialResult<(Vec<usize>, Option<Vec<T>>)> - Indices and optionally distances of points within radius
Source

pub fn query_radius_tree( &self, other: &BallTree<T, D>, radius: T, ) -> SpatialResult<Vec<(usize, usize)>>

Find all pairs of points from two trees that are within a given radius

§Arguments
  • other - Another ball tree
  • radius - Radius to search within
§Returns
  • SpatialResult<Vec<(usize, usize)>> - Pairs of indices (self_idx, other_idx) within radius
Source

pub fn get_data(&self) -> &Array2<T>

Get the original data points

Source

pub fn get_n_samples(&self) -> usize

Get the number of data points

Source

pub fn get_n_features(&self) -> usize

Get the dimension of data points

Source

pub fn get_leaf_size(&self) -> usize

Get the leaf size

Source§

impl<T: Float + Send + Sync + 'static> BallTree<T, EuclideanDistance<T>>

Source

pub fn with_euclidean_distance( data: &ArrayView2<'_, T>, leaf_size: usize, ) -> SpatialResult<BallTree<T, EuclideanDistance<T>>>

Create a new ball tree with default Euclidean distance metric

§Arguments
  • data - 2D array of data points (n_samples x n_features)
  • leaf_size - Maximum number of points in leaf nodes
§Returns
  • SpatialResult<BallTree<T, EuclideanDistance<T>>> - A new ball tree

Trait Implementations§

Source§

impl<T: Clone + Float + Send + Sync, D: Clone + Distance<T>> Clone for BallTree<T, D>

Source§

fn clone(&self) -> BallTree<T, D>

Returns a duplicate of the value. Read more
1.0.0 · Source§

const fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug + Float + Send + Sync, D: Debug + Distance<T>> Debug for BallTree<T, D>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T, D> Freeze for BallTree<T, D>
where D: Freeze,

§

impl<T, D> RefUnwindSafe for BallTree<T, D>

§

impl<T, D> Send for BallTree<T, D>

§

impl<T, D> Sync for BallTree<T, D>

§

impl<T, D> Unpin for BallTree<T, D>
where D: Unpin, T: Unpin,

§

impl<T, D> UnwindSafe for BallTree<T, D>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V