Trait Cosine

Source
pub trait Cosine: Dot + Normalize {
    // Provided methods
    fn cosine(x: &[Self], other: &[Self]) -> f32 { ... }
    fn cosine_fast(x: &[Self], x_norm: f32, y: &[Self]) -> f32 { ... }
    fn cosine_with_norms(
        x: &[Self],
        x_norm: f32,
        y_norm: f32,
        y: &[Self],
    ) -> f32 { ... }
    fn cosine_batch<'a>(
        x: &'a [Self],
        batch: &'a [Self],
        dimension: usize,
    ) -> Box<dyn Iterator<Item = f32> + 'a> { ... }
}
Expand description

Cosine Distance

Provided Methods§

Source

fn cosine(x: &[Self], other: &[Self]) -> f32

Cosine distance between two vectors.

Source

fn cosine_fast(x: &[Self], x_norm: f32, y: &[Self]) -> f32

Fast cosine function, that assumes that the norm of the first vector is already known.

Source

fn cosine_with_norms(x: &[Self], x_norm: f32, y_norm: f32, y: &[Self]) -> f32

Cosine between two vectors, with the L2 norms of both vectors already known.

Source

fn cosine_batch<'a>( x: &'a [Self], batch: &'a [Self], dimension: usize, ) -> Box<dyn Iterator<Item = f32> + 'a>

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl Cosine for f32

Source§

fn cosine_fast(x: &[Self], x_norm: Self, other: &[Self]) -> f32

Source§

fn cosine_with_norms(x: &[Self], x_norm: Self, y_norm: Self, y: &[Self]) -> Self

Source§

fn cosine_batch<'a>( x: &'a [Self], batch: &'a [Self], dimension: usize, ) -> Box<dyn Iterator<Item = f32> + 'a>

Source§

impl Cosine for f64

Source§

impl Cosine for u8

Source§

impl Cosine for bf16

Source§

impl Cosine for f16

Source§

fn cosine_fast(x: &[Self], x_norm: f32, y: &[Self]) -> f32

Implementors§