Struct abd_clam::VecDataset

source ·
pub struct VecDataset<I: Instance, U: Number, M: Instance> { /* private fields */ }
Expand description

A Dataset of a Vec of instances.

This may be used for any data that can fit in memory. It is not recommended for large datasets.

§Type Parameters

  • T: The type of the instances in the Dataset.
  • U: The type of the distance values between instances.
  • M: The type of the metadata associated with each instance.

Implementations§

source§

impl<I: Instance, U: Number> VecDataset<I, U, usize>

source

pub fn new( name: String, data: Vec<I>, metric: fn(_: &I, _: &I) -> U, is_expensive: bool, ) -> Self

Creates a new dataset.

§Arguments
  • name: The name of the dataset.
  • data: The vector of instances.
  • metric: The metric for computing distances between instances.
  • is_expensive: Whether the metric is expensive to compute.
source§

impl<I: Instance, U: Number, M: Instance> VecDataset<I, U, M>

source

pub fn assign_metadata<Mn: Instance>( self, metadata: Vec<Mn>, ) -> Result<VecDataset<I, U, Mn>, String>

Assigns metadata to the dataset.

§Arguments
  • metadata: The metadata to assign to the dataset.
§Returns

The dataset with the metadata assigned.

§Errors
  • If the metadata is not the same length as the dataset.
source

pub fn data(&self) -> &[I]

A reference to the underlying data.

source

pub fn data_owned(self) -> Vec<I>

Moves the underlying data out of the dataset.

source

pub fn metadata(&self) -> &[M]

A reference to the underlying metadata.

source

pub fn metadata_owned(self) -> Vec<M>

Moves the underlying metadata out of the dataset.

source

pub fn metadata_of(&self, index: usize) -> &M

A reference to the metadata of a specific instance.

Trait Implementations§

source§

impl<I: Clone + Instance, U: Clone + Number, M: Clone + Instance> Clone for VecDataset<I, U, M>

source§

fn clone(&self) -> VecDataset<I, U, M>

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl<I: Instance, U: Number, M: Instance> Dataset<I, U> for VecDataset<I, U, M>

source§

fn type_name() -> String

Returns the name of the type of the dataset.
source§

fn name(&self) -> &str

Returns the name of the dataset. This is used to identify the dataset in various places.
source§

fn cardinality(&self) -> usize

Returns the number of instances in the dataset.
source§

fn is_metric_expensive(&self) -> bool

Whether or not the metric is expensive to calculate. Read more
source§

fn metric(&self) -> fn(_: &I, _: &I) -> U

Returns the metric used to calculate distances between instances. Read more
source§

fn set_permuted_indices(&mut self, indices: Option<&[usize]>)

Sets the permutation of indices that was used to reorder the dataset. Read more
source§

fn swap(&mut self, left: usize, right: usize) -> Result<(), String>

Swaps the location of two instances in the dataset. Read more
source§

fn permuted_indices(&self) -> Option<&[usize]>

Returns the permutation of indices that was used to reorder the dataset. Read more
source§

fn permute_instances(&mut self, permutation: &[usize]) -> Result<(), String>

Reorders the internal order of instances by a given permutation of indices. Read more
source§

fn make_shards(self, max_cardinality: usize) -> Vec<Self>

Makes a vector of sharded datasets from the given dataset. Read more
source§

fn save(&self, path: &Path) -> Result<(), String>

Saves the dataset to a file. Read more
source§

fn load( path: &Path, metric: fn(_: &I, _: &I) -> U, is_expensive: bool, ) -> Result<Self, String>

Loads a dataset from a file. Read more
source§

fn original_index(&self, index: usize) -> usize

Get the index before the dataset was reordered. If the dataset was not reordered, this is the identity function.
source§

fn one_to_one(&self, left: usize, right: usize) -> U

Calculates the distance between two indexed instances in the dataset. Read more
source§

fn are_instances_equal(&self, left: usize, right: usize) -> bool

Returns whether or not two indexed instances in the dataset are equal. Read more
source§

fn one_to_many(&self, left: usize, right: &[usize]) -> Vec<U>

Returns a vector of distances. Read more
source§

fn many_to_many(&self, left: &[usize], right: &[usize]) -> Vec<Vec<U>>

Returns a vector of vectors of distances. Read more
source§

fn pairs(&self, index_pairs: &[(usize, usize)]) -> Vec<U>

Returns a vector of distances between the given pairs of indexed instances. Read more
source§

fn pairwise(&self, indices: &[usize]) -> Vec<Vec<U>>

Returns a vector of distances between all pairs of indexed instances. Read more
source§

fn query_to_one(&self, query: &I, index: usize) -> U

Calculates the distance between a query and an indexed instance in the dataset. Read more
source§

fn query_to_many(&self, query: &I, indices: &[usize]) -> Vec<U>

Returns a vector of distances between a query and all indexed instances. Read more
source§

fn choose_unique( &self, n: usize, indices: &[usize], seed: Option<u64>, ) -> Vec<usize>

Chooses a subset of indices that are unique with respect to the metric. Read more
source§

fn median(&self, indices: &[usize]) -> Option<usize>

Calculates the geometric median of a set of indexed instances. Returns a value from the set of indices that is the index of the median in the dataset. Read more
source§

fn linear_knn(&self, query: &I, k: usize) -> Vec<(usize, U)>

Runs linear KNN search on the dataset.
source§

fn par_linear_knn(&self, query: &I, k: usize) -> Vec<(usize, U)>

Runs parallelized linear KNN search on the dataset.
source§

fn linear_rnn(&self, query: &I, radius: U) -> Vec<(usize, U)>

Runs linear RNN search on the dataset.
source§

fn par_linear_rnn(&self, query: &I, radius: U) -> Vec<(usize, U)>

Runs parallelized linear RNN search on the dataset.
source§

impl<I: Debug + Instance, U: Debug + Number, M: Debug + Instance> Debug for VecDataset<I, U, M>

source§

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

Formats the value using the given formatter. Read more
source§

impl<I: Instance, U: Number, M: Instance> Index<usize> for VecDataset<I, U, M>

§

type Output = I

The returned type after indexing.
source§

fn index(&self, index: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more

Auto Trait Implementations§

§

impl<I, U, M> Freeze for VecDataset<I, U, M>

§

impl<I, U, M> RefUnwindSafe for VecDataset<I, U, M>

§

impl<I, U, M> Send for VecDataset<I, U, M>

§

impl<I, U, M> Sync for VecDataset<I, U, M>

§

impl<I, U, M> Unpin for VecDataset<I, U, M>
where I: Unpin, M: Unpin,

§

impl<I, U, M> UnwindSafe for VecDataset<I, U, M>
where I: UnwindSafe, M: UnwindSafe,

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§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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.
§

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,

§

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>,

§

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>,

§

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