Skip to main content

BitSliceBase

Struct BitSliceBase 

Source
pub struct BitSliceBase<const NBITS: usize, Repr, Ptr, Perm = Dense, Len = Dynamic>
where Repr: Representation<NBITS>, Ptr: AsPtr<Type = u8>, Perm: PermutationStrategy<NBITS>, Len: Length,
{ /* private fields */ }
Expand description

A generalized representation for packed small bit integer encodings over a contiguous span of memory.

Think of this as a Rust slice, but supporting integer elements with fewer than 8-bits. The borrowed representations BitSlice and MutBitSlice consist of just a pointer and a length and are therefore just 16-bytes in size and amenable to the niche optimization.

§Parameters

  • NBITS: The number of bits occupied by each entry in the vector.

  • Repr: The storage representation for each collection of 8-bits. This representation defines the domain of the encoding (i.e., range of realized values) as well as how this domain is mapped into NBITS bits.

  • Ptr: The storage type for the contiguous memory. Possible representations are:

    • diskann_quantization::bits::SlicePtr<'_, u8>: For immutable views.
    • diskann_quantization::bits::MutSlicePtr<'_, u8>: For mutable views.
    • Box<[u8]>: For standalone vectors.
  • Perm: By default, this type uses a dense storage strategy where the least significant bit of the value at index i occurs directly after the most significant bit of the value at index i-1.

    Different permutations can be used to enable faster distance computations between compressed vectors and full-precision vectors by enabling faster SIMD unpacking.

  • Len: The representation for the length of the vector. This may only be one of the two families of types:

    • diskann_quantization::bits::Dynamic: For instances with a run-time length.
    • diskann_quantization::bits::Static<N>: For instances with a compile-time known length of N.

§Examples

§Canonical Bit Slice

The canonical BitSlice stores unsigned integers of NBITS densely in memory. That is, for a type BitSliceBase<3, Unsigned, _>, the layout is as follows:

|<--LSB-- byte 0 --MSB--->|<--LSB-- byte 1 --MSB--->|
| a0 a1 a2 b0 b1 b2 c0 c1 | c2 d0 d1 d2 e0 e1 e2 f0 |
|<-- A -->|<-- B ->|<--- C -->|<-- D ->|<-- E ->|<- F

An example is shown below:

use diskann_quantization::bits::{BoxedBitSlice, Unsigned};
// Create a new boxed bit-slice with capacity for 10 dimensions.
let mut x = BoxedBitSlice::<3, Unsigned>::new_boxed(10);
assert_eq!(x.len(), 10);
// The number of bytes in the canonical representation is computed by
// ceil((len * NBITS) / 8);
assert_eq!(x.bytes(), 4);

// Assign values.
x.set(0, 1).unwrap(); // assign the value 1 to index 0
x.set(1, 5).unwrap(); // assign the value 5 to index 1
assert_eq!(x.get(0).unwrap(), 1); // retrieve the value at index 0
assert_eq!(x.get(1).unwrap(), 5); // retrieve the value at index 1

// Assigning out-of-bounds will result in an error.
let err = x.set(1, 10).unwrap_err();
assert!(matches!(diskann_quantization::bits::SetError::EncodingError, err));
// The old value is left untouched.
assert_eq!(x.get(1).unwrap(), 5);

// `BoxedBitSlice` allows itself to be consumed, returning the underlying storage.
let y = x.into_inner();
assert_eq!(y.len(), BoxedBitSlice::<3, Unsigned>::bytes_for(10));

The above example demonstrates a boxed bit slice - a type that owns its underlying memory. However, this is not always ergonomic when interfacing with data stores. For this, the viewing interface can be used.

use diskann_quantization::bits::{MutBitSlice, Unsigned};

let mut x: Vec<u8> = vec![0; 4];
let mut slice = MutBitSlice::<3, Unsigned>::new(x.as_mut_slice(), 10).unwrap();
assert_eq!(slice.len(), 10);
assert_eq!(slice.bytes(), 4);

// The slice reference behaves just like boxed slice.
slice.set(0, 5).unwrap();
assert_eq!(slice.get(0).unwrap(), 5);

// Note - if the number of bytes required for the provided dimensions does not match
// the length of the provided span, than slice construction will return an error.
let err = MutBitSlice::<3, Unsigned>::new(x.as_mut_slice(), 11).unwrap_err();
assert_eq!(err.to_string(), "input span has length 4 bytes but expected 5");

Implementations§

Source§

impl<const NBITS: usize, Repr, Ptr, Perm, Len> BitSliceBase<NBITS, Repr, Ptr, Perm, Len>
where Repr: Representation<NBITS>, Ptr: AsPtr<Type = u8>, Perm: PermutationStrategy<NBITS>, Len: Length,

Source

pub fn bytes_for(count: usize) -> usize

Return the exact number of bytes required to store count values.

Source

pub unsafe fn new_unchecked<Pre, Count>(precursor: Pre, count: Count) -> Self
where Count: Into<Len>, Pre: Precursor<Ptr>,

Construct a new BitSlice without checking preconditions.

§Safety

Requires the following to avoid undefined behavior:

  • precursor.precursor_len() == Self::bytes_for(<Count as Into<Len>>::into(count).value()).

This is checked in debug builds.

Source

pub fn new<Pre, Count>( precursor: Pre, count: Count, ) -> Result<Self, ConstructionError>
where Count: Into<Len>, Pre: Precursor<Ptr>,

Construct a new BitSlice from the precursor capable of holding count encoded elements of size `NBITS.

§Requirements

The number of bytes pointed to by the precursor must be equal to the number of bytes required by the layout. That is:

  • precursor.precursor_len() == Self::bytes_for(<Count as Into<Len>>::into(count).value()).
Source

pub fn len(&self) -> usize

Return the number of elements contained in the slice.

Source

pub fn is_empty(&self) -> bool

Return whether or not the slice is empty.

Source

pub fn bytes(&self) -> usize

Return the number of bytes occupied by this slice.

Source

pub fn get(&self, i: usize) -> Result<i64, GetError>

Return the value at logical index i.

Source

pub unsafe fn get_unchecked(&self, i: usize) -> i64

Return the value at logical index i.

§Safety

Argument i must be in bounds: 0 <= i < self.len().

Source

pub fn set(&mut self, i: usize, value: i64) -> Result<(), SetError>
where Ptr: AsMutPtr<Type = u8>,

Encode and assign value to logical index i.

Source

pub unsafe fn set_unchecked(&mut self, i: usize, encoded: u8)
where Ptr: AsMutPtr<Type = u8>,

Assign value to logical index i.

§Safety

Argument i must be in bounds: 0 <= i < self.len().

Source

pub fn domain(&self) -> Repr::Domain

Return the domain of acceptable values.

Source

pub fn as_ptr(&self) -> *const u8

Return a pointer to the beginning of the memory associated with this slice.

§NOTE

The memory span underlying this instances is valid for self.bytes(), not necessarily self.len().

Source§

impl<const NBITS: usize, Repr, Perm, Len> BitSliceBase<NBITS, Repr, Poly<[u8], GlobalAllocator>, Perm, Len>
where Repr: Representation<NBITS>, Perm: PermutationStrategy<NBITS>, Len: Length,

Source

pub fn new_boxed<Count>(count: Count) -> Self
where Count: Into<Len>,

Construct a new owning BitSlice capable of holding Count logical values. The slice is initialized in a valid but undefined state.

§Example
use diskann_quantization::bits::{BoxedBitSlice, Unsigned};
let mut x = BoxedBitSlice::<3, Unsigned>::new_boxed(4);
x.set(0, 0).unwrap();
x.set(1, 2).unwrap();
x.set(2, 4).unwrap();
x.set(3, 6).unwrap();

assert_eq!(x.get(0).unwrap(), 0);
assert_eq!(x.get(1).unwrap(), 2);
assert_eq!(x.get(2).unwrap(), 4);
assert_eq!(x.get(3).unwrap(), 6);
Source§

impl<const NBITS: usize, Repr, Perm, Len, A> BitSliceBase<NBITS, Repr, Poly<[u8], A>, Perm, Len>
where Repr: Representation<NBITS>, Perm: PermutationStrategy<NBITS>, Len: Length, A: AllocatorCore,

Source

pub fn new_in<Count>(count: Count, allocator: A) -> Result<Self, AllocatorError>
where Count: Into<Len>,

Construct a new owning BitSlice capable of holding Count logical values using the provided allocator.

The slice is initialized in a valid but undefined state.

§Example
use diskann_quantization::{
    alloc::GlobalAllocator,
    bits::{BoxedBitSlice, Unsigned}
};
let mut x = BoxedBitSlice::<3, Unsigned>::new_in(4, GlobalAllocator).unwrap();
x.set(0, 0).unwrap();
x.set(1, 2).unwrap();
x.set(2, 4).unwrap();
x.set(3, 6).unwrap();

assert_eq!(x.get(0).unwrap(), 0);
assert_eq!(x.get(1).unwrap(), 2);
assert_eq!(x.get(2).unwrap(), 4);
assert_eq!(x.get(3).unwrap(), 6);
Source

pub fn into_inner(self) -> Poly<[u8], A>

Consume self and return the boxed allocation.

Trait Implementations§

Source§

impl<const NBITS: usize, Repr, Ptr, Perm, Len> Clone for BitSliceBase<NBITS, Repr, Ptr, Perm, Len>
where Repr: Representation<NBITS> + Clone, Ptr: AsPtr<Type = u8> + Clone, Perm: PermutationStrategy<NBITS> + Clone, Len: Length + Clone,

Source§

fn clone(&self) -> BitSliceBase<NBITS, Repr, Ptr, Perm, Len>

Returns a duplicate 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<T> CompressInto<&[T], BitSliceBase<1, Binary, MutSlicePtr<'_, u8>>> for BinaryQuantizer
where T: PartialOrd + Default,

Source§

fn compress_into( &self, from: &[T], into: MutBitSlice<'_, 1, Binary>, ) -> Result<(), Self::Error>

Compress the source vector into a binary representation.

This works by mapping positive numbers (as defined by v > T::default()) to 1 and negative numbers (as defined by v <= T::default()) to -1.

§Panics

Panics if from.len() != into.len().

Source§

type Error = Infallible

Errors that may occur during compression.
Source§

type Output = ()

An output type resulting from compression.
Source§

impl<const NBITS: usize, T, Perm> CompressInto<&[T], BitSliceBase<NBITS, Unsigned, MutSlicePtr<'_, u8>, Perm>> for ScalarQuantizer
where T: Copy + Into<f32>, Unsigned: Representation<NBITS>, Perm: PermutationStrategy<NBITS>,

Source§

fn compress_into( &self, from: &[T], into: MutBitSlice<'_, NBITS, Unsigned, Perm>, ) -> Result<(), Self::Error>

Compress the input vector from into the bitslice into.

This method does not compute compensation coefficients required for fast inner product computations. If only L2 distances is desired, this method can be slightly faster.

§Error

Returns an error if the input contains NaN.

§Panics

Panics if:

  • from.len() != self.dim(): Vector to be compressed must have the same dimensionality as the quantizer.
  • into.len() != self.dim(): Compressed vector must have the same dimensionality as the quantizer.
Source§

type Error = InputContainsNaN

Errors that may occur during compression.
Source§

type Output = ()

An output type resulting from compression.
Source§

impl<const NBITS: usize, Repr, Ptr, Perm, Len> Debug for BitSliceBase<NBITS, Repr, Ptr, Perm, Len>
where Repr: Representation<NBITS> + Debug, Ptr: AsPtr<Type = u8> + Debug, Perm: PermutationStrategy<NBITS> + Debug, Len: Length + Debug,

Source§

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

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

impl<'a, Ptr> From<&'a BitSliceBase<8, Unsigned, Ptr>> for &'a [u8]
where Ptr: AsPtr<Type = u8>,

Source§

fn from(slice: &'a BitSliceBase<8, Unsigned, Ptr>) -> Self

Converts to this type from the input type.
Source§

impl PureDistanceFunction<&[f32], BitSliceBase<1, Unsigned, SlicePtr<'_, u8>>, Result<MathematicalValue<f32>, UnequalLengths>> for InnerProduct

Compute the inner product between x and y.

Returns an error if the arguments have different lengths.

Source§

impl PureDistanceFunction<&[f32], BitSliceBase<2, Unsigned, SlicePtr<'_, u8>>, Result<MathematicalValue<f32>, UnequalLengths>> for InnerProduct

Compute the inner product between x and y.

Returns an error if the arguments have different lengths.

Source§

impl PureDistanceFunction<&[f32], BitSliceBase<3, Unsigned, SlicePtr<'_, u8>>, Result<MathematicalValue<f32>, UnequalLengths>> for InnerProduct

Compute the inner product between x and y.

Returns an error if the arguments have different lengths.

Source§

impl PureDistanceFunction<&[f32], BitSliceBase<4, Unsigned, SlicePtr<'_, u8>>, Result<MathematicalValue<f32>, UnequalLengths>> for InnerProduct

Compute the inner product between x and y.

Returns an error if the arguments have different lengths.

Source§

impl PureDistanceFunction<&[f32], BitSliceBase<5, Unsigned, SlicePtr<'_, u8>>, Result<MathematicalValue<f32>, UnequalLengths>> for InnerProduct

Compute the inner product between x and y.

Returns an error if the arguments have different lengths.

Source§

impl PureDistanceFunction<&[f32], BitSliceBase<6, Unsigned, SlicePtr<'_, u8>>, Result<MathematicalValue<f32>, UnequalLengths>> for InnerProduct

Compute the inner product between x and y.

Returns an error if the arguments have different lengths.

Source§

impl PureDistanceFunction<&[f32], BitSliceBase<7, Unsigned, SlicePtr<'_, u8>>, Result<MathematicalValue<f32>, UnequalLengths>> for InnerProduct

Compute the inner product between x and y.

Returns an error if the arguments have different lengths.

Source§

impl PureDistanceFunction<&[f32], BitSliceBase<8, Unsigned, SlicePtr<'_, u8>>, Result<MathematicalValue<f32>, UnequalLengths>> for InnerProduct

Compute the inner product between x and y.

Returns an error if the arguments have different lengths.

Source§

impl PureDistanceFunction<BitSliceBase<1, Binary, SlicePtr<'_, u8>>, BitSliceBase<1, Binary, SlicePtr<'_, u8>>, Result<MathematicalValue<u32>, UnequalLengths>> for Hamming

Compute the hamming distance between x and y.

Returns an error if the arguments have different lengths.

Source§

impl PureDistanceFunction<BitSliceBase<1, Unsigned, SlicePtr<'_, u8>>, BitSliceBase<1, Unsigned, SlicePtr<'_, u8>>, Result<MathematicalValue<u32>, UnequalLengths>> for InnerProduct

Compute the squared L2 distance between x and y.

Source§

impl PureDistanceFunction<BitSliceBase<1, Unsigned, SlicePtr<'_, u8>>, BitSliceBase<1, Unsigned, SlicePtr<'_, u8>>, Result<MathematicalValue<u32>, UnequalLengths>> for SquaredL2

Compute the squared L2 distance between x and y.

Source§

impl PureDistanceFunction<BitSliceBase<2, Unsigned, SlicePtr<'_, u8>>, BitSliceBase<2, Unsigned, SlicePtr<'_, u8>>, Result<MathematicalValue<u32>, UnequalLengths>> for InnerProduct

Compute the squared L2 distance between x and y.

Source§

impl PureDistanceFunction<BitSliceBase<2, Unsigned, SlicePtr<'_, u8>>, BitSliceBase<2, Unsigned, SlicePtr<'_, u8>>, Result<MathematicalValue<u32>, UnequalLengths>> for SquaredL2

Compute the squared L2 distance between x and y.

Source§

impl PureDistanceFunction<BitSliceBase<3, Unsigned, SlicePtr<'_, u8>>, BitSliceBase<3, Unsigned, SlicePtr<'_, u8>>, Result<MathematicalValue<u32>, UnequalLengths>> for InnerProduct

Compute the squared L2 distance between x and y.

Source§

impl PureDistanceFunction<BitSliceBase<3, Unsigned, SlicePtr<'_, u8>>, BitSliceBase<3, Unsigned, SlicePtr<'_, u8>>, Result<MathematicalValue<u32>, UnequalLengths>> for SquaredL2

Compute the squared L2 distance between x and y.

Source§

impl PureDistanceFunction<BitSliceBase<4, Unsigned, SlicePtr<'_, u8>>, BitSliceBase<4, Unsigned, SlicePtr<'_, u8>>, Result<MathematicalValue<u32>, UnequalLengths>> for InnerProduct

Compute the squared L2 distance between x and y.

Source§

impl PureDistanceFunction<BitSliceBase<4, Unsigned, SlicePtr<'_, u8>>, BitSliceBase<4, Unsigned, SlicePtr<'_, u8>>, Result<MathematicalValue<u32>, UnequalLengths>> for SquaredL2

Compute the squared L2 distance between x and y.

Source§

impl PureDistanceFunction<BitSliceBase<4, Unsigned, SlicePtr<'_, u8>, BitTranspose>, BitSliceBase<1, Unsigned, SlicePtr<'_, u8>>, Result<MathematicalValue<u32>, UnequalLengths>> for InnerProduct

Source§

impl PureDistanceFunction<BitSliceBase<5, Unsigned, SlicePtr<'_, u8>>, BitSliceBase<5, Unsigned, SlicePtr<'_, u8>>, Result<MathematicalValue<u32>, UnequalLengths>> for InnerProduct

Compute the squared L2 distance between x and y.

Source§

impl PureDistanceFunction<BitSliceBase<5, Unsigned, SlicePtr<'_, u8>>, BitSliceBase<5, Unsigned, SlicePtr<'_, u8>>, Result<MathematicalValue<u32>, UnequalLengths>> for SquaredL2

Compute the squared L2 distance between x and y.

Source§

impl PureDistanceFunction<BitSliceBase<6, Unsigned, SlicePtr<'_, u8>>, BitSliceBase<6, Unsigned, SlicePtr<'_, u8>>, Result<MathematicalValue<u32>, UnequalLengths>> for InnerProduct

Compute the squared L2 distance between x and y.

Source§

impl PureDistanceFunction<BitSliceBase<6, Unsigned, SlicePtr<'_, u8>>, BitSliceBase<6, Unsigned, SlicePtr<'_, u8>>, Result<MathematicalValue<u32>, UnequalLengths>> for SquaredL2

Compute the squared L2 distance between x and y.

Source§

impl PureDistanceFunction<BitSliceBase<7, Unsigned, SlicePtr<'_, u8>>, BitSliceBase<7, Unsigned, SlicePtr<'_, u8>>, Result<MathematicalValue<u32>, UnequalLengths>> for InnerProduct

Compute the squared L2 distance between x and y.

Source§

impl PureDistanceFunction<BitSliceBase<7, Unsigned, SlicePtr<'_, u8>>, BitSliceBase<7, Unsigned, SlicePtr<'_, u8>>, Result<MathematicalValue<u32>, UnequalLengths>> for SquaredL2

Compute the squared L2 distance between x and y.

Source§

impl PureDistanceFunction<BitSliceBase<8, Unsigned, SlicePtr<'_, u8>>, BitSliceBase<8, Unsigned, SlicePtr<'_, u8>>, Result<MathematicalValue<u32>, UnequalLengths>> for InnerProduct

Compute the squared L2 distance between x and y.

Source§

impl PureDistanceFunction<BitSliceBase<8, Unsigned, SlicePtr<'_, u8>>, BitSliceBase<8, Unsigned, SlicePtr<'_, u8>>, Result<MathematicalValue<u32>, UnequalLengths>> for SquaredL2

Compute the squared L2 distance between x and y.

Source§

impl<'this, const NBITS: usize, Repr, Ptr, Perm, Len> Reborrow<'this> for BitSliceBase<NBITS, Repr, Ptr, Perm, Len>
where Repr: Representation<NBITS>, Ptr: AsPtr<Type = u8>, Perm: PermutationStrategy<NBITS>, Len: Length,

Source§

type Target = BitSliceBase<NBITS, Repr, SlicePtr<'this, u8>, Perm, Len>

Source§

fn reborrow(&'this self) -> Self::Target

Borrow self into a generalized reference type and reborrow
Source§

impl<'this, const NBITS: usize, Repr, Ptr, Perm, Len> ReborrowMut<'this> for BitSliceBase<NBITS, Repr, Ptr, Perm, Len>
where Repr: Representation<NBITS>, Ptr: AsMutPtr<Type = u8>, Perm: PermutationStrategy<NBITS>, Len: Length,

Source§

type Target = BitSliceBase<NBITS, Repr, MutSlicePtr<'this, u8>, Perm, Len>

Source§

fn reborrow_mut(&'this mut self) -> Self::Target

Mutably borrow self into a generalized reference type and reborrow.
Source§

impl<A> Target2<A, Result<MathematicalValue<u32>, UnequalLengths>, BitSliceBase<1, Unsigned, SlicePtr<'_, u8>>, BitSliceBase<1, Unsigned, SlicePtr<'_, u8>>> for InnerProduct
where A: Architecture,

Compute the inner product between bitvectors x and y.

Returns an error if the arguments have different lengths.

Source§

fn run( self, _: A, x: BitSlice<'_, N, Unsigned, Dense>, y: BitSlice<'_, N, Unsigned, Dense>, ) -> MathematicalResult<u32>

Run the operation with the provided Architecture.
Source§

impl<A> Target2<A, Result<MathematicalValue<u32>, UnequalLengths>, BitSliceBase<1, Unsigned, SlicePtr<'_, u8>>, BitSliceBase<1, Unsigned, SlicePtr<'_, u8>>> for SquaredL2
where A: Architecture,

Compute the squared L2 distance between bitvectors x and y.

Returns an error if the arguments have different lengths.

Source§

fn run( self, _: A, x: BitSlice<'_, N, Unsigned, Dense>, y: BitSlice<'_, N, Unsigned, Dense>, ) -> MathematicalResult<u32>

Run the operation with the provided Architecture.
Source§

impl<A> Target2<A, Result<MathematicalValue<u32>, UnequalLengths>, BitSliceBase<4, Unsigned, SlicePtr<'_, u8>, BitTranspose>, BitSliceBase<1, Unsigned, SlicePtr<'_, u8>>> for InnerProduct
where A: Architecture,

The strategy is to compute the inner product <x, y> by decomposing the problem into groups of 64-dimensions.

For each group, we load the 64-bits of y into a word bits. And the four 64-bit words of the group in x in b0, b1, b2, and b3`.

Note that bit i in b0 is bit-0 of the i-th value in ths group. Likewise, bit i in b1 is bit-1 of the same word.

This means that we can compute the partial inner product for this group as

(bits & b0).count_ones()                // Contribution of bit 0
    + 2 * (bits & b1).count_ones()      // Contribution of bit 1
    + 4 * (bits & b2).count_ones()      // Contribution of bit 2
    + 8 * (bits & b3).count_ones()      // Contribution of bit 3

We process as many full groups as we can.

To handle the remainder, we need to be careful about acessing y because BitSlice only guarantees the validity of reads at the byte level. That is - we cannot assume that a full 64-bit read is valid.

The bit-tranposed x, on the other hand, guarantees allocations in blocks of 4 * 64-bits, so it can be treated as normal.

Source§

fn run( self, _: A, x: BitSlice<'_, N, Unsigned, BitTranspose>, y: BitSlice<'_, N, Unsigned, Dense>, ) -> MathematicalResult<u32>

Run the operation with the provided Architecture.
Source§

impl<A> Target2<A, Result<MathematicalValue<u32>, UnequalLengths>, BitSliceBase<8, Unsigned, SlicePtr<'_, u8>>, BitSliceBase<8, Unsigned, SlicePtr<'_, u8>>> for InnerProduct
where A: Architecture, InnerProduct: for<'a> Target2<A, MathematicalValue<f32>, &'a [u8], &'a [u8]>,

Compute the inner product between x and y.

Returns an error if the arguments have different lengths.

§Implementation Notes

This can directly invoke the methods implemented in vector because BitSlice<'_, 8, Unsigned> is isomorphic to &[u8].

Source§

fn run( self, arch: A, x: BitSlice<'_, N, Unsigned, Dense>, y: BitSlice<'_, N, Unsigned, Dense>, ) -> MathematicalResult<u32>

Run the operation with the provided Architecture.
Source§

impl<A> Target2<A, Result<MathematicalValue<u32>, UnequalLengths>, BitSliceBase<8, Unsigned, SlicePtr<'_, u8>>, BitSliceBase<8, Unsigned, SlicePtr<'_, u8>>> for SquaredL2
where A: Architecture, SquaredL2: for<'a> Target2<A, MathematicalValue<f32>, &'a [u8], &'a [u8]>,

Compute the squared L2 distance between x and y.

Returns an error if the arguments have different lengths.

§Implementation Notes

This can directly invoke the methods implemented in vector because BitSlice<'_, 8, Unsigned> is isomorphic to &[u8].

Source§

fn run( self, arch: A, x: BitSlice<'_, N, Unsigned, Dense>, y: BitSlice<'_, N, Unsigned, Dense>, ) -> MathematicalResult<u32>

Run the operation with the provided Architecture.
Source§

impl Target2<Neon, Result<MathematicalValue<f32>, UnequalLengths>, &[f32], BitSliceBase<1, Unsigned, SlicePtr<'_, u8>>> for InnerProduct

Source§

fn run( self, arch: Neon, x: &[f32], y: BitSlice<'_, N, Unsigned, Dense>, ) -> MathematicalResult<f32>

Run the operation with the provided Architecture.
Source§

impl Target2<Neon, Result<MathematicalValue<f32>, UnequalLengths>, &[f32], BitSliceBase<2, Unsigned, SlicePtr<'_, u8>>> for InnerProduct

Source§

fn run( self, arch: Neon, x: &[f32], y: BitSlice<'_, N, Unsigned, Dense>, ) -> MathematicalResult<f32>

Run the operation with the provided Architecture.
Source§

impl Target2<Neon, Result<MathematicalValue<f32>, UnequalLengths>, &[f32], BitSliceBase<3, Unsigned, SlicePtr<'_, u8>>> for InnerProduct

Source§

fn run( self, arch: Neon, x: &[f32], y: BitSlice<'_, N, Unsigned, Dense>, ) -> MathematicalResult<f32>

Run the operation with the provided Architecture.
Source§

impl Target2<Neon, Result<MathematicalValue<f32>, UnequalLengths>, &[f32], BitSliceBase<4, Unsigned, SlicePtr<'_, u8>>> for InnerProduct

Source§

fn run( self, arch: Neon, x: &[f32], y: BitSlice<'_, N, Unsigned, Dense>, ) -> MathematicalResult<f32>

Run the operation with the provided Architecture.
Source§

impl Target2<Neon, Result<MathematicalValue<f32>, UnequalLengths>, &[f32], BitSliceBase<5, Unsigned, SlicePtr<'_, u8>>> for InnerProduct

Source§

fn run( self, arch: Neon, x: &[f32], y: BitSlice<'_, N, Unsigned, Dense>, ) -> MathematicalResult<f32>

Run the operation with the provided Architecture.
Source§

impl Target2<Neon, Result<MathematicalValue<f32>, UnequalLengths>, &[f32], BitSliceBase<6, Unsigned, SlicePtr<'_, u8>>> for InnerProduct

Source§

fn run( self, arch: Neon, x: &[f32], y: BitSlice<'_, N, Unsigned, Dense>, ) -> MathematicalResult<f32>

Run the operation with the provided Architecture.
Source§

impl Target2<Neon, Result<MathematicalValue<f32>, UnequalLengths>, &[f32], BitSliceBase<7, Unsigned, SlicePtr<'_, u8>>> for InnerProduct

Source§

fn run( self, arch: Neon, x: &[f32], y: BitSlice<'_, N, Unsigned, Dense>, ) -> MathematicalResult<f32>

Run the operation with the provided Architecture.
Source§

impl Target2<Neon, Result<MathematicalValue<f32>, UnequalLengths>, &[f32], BitSliceBase<8, Unsigned, SlicePtr<'_, u8>>> for InnerProduct

Source§

fn run( self, arch: Neon, x: &[f32], y: BitSlice<'_, N, Unsigned, Dense>, ) -> MathematicalResult<f32>

Run the operation with the provided Architecture.
Source§

impl Target2<Neon, Result<MathematicalValue<u32>, UnequalLengths>, BitSliceBase<2, Unsigned, SlicePtr<'_, u8>>, BitSliceBase<2, Unsigned, SlicePtr<'_, u8>>> for InnerProduct

Source§

fn run( self, arch: Neon, x: BitSlice<'_, N, Unsigned, Dense>, y: BitSlice<'_, N, Unsigned, Dense>, ) -> MathematicalResult<u32>

Run the operation with the provided Architecture.
Source§

impl Target2<Neon, Result<MathematicalValue<u32>, UnequalLengths>, BitSliceBase<2, Unsigned, SlicePtr<'_, u8>>, BitSliceBase<2, Unsigned, SlicePtr<'_, u8>>> for SquaredL2

Source§

fn run( self, arch: Neon, x: BitSlice<'_, N, Unsigned, Dense>, y: BitSlice<'_, N, Unsigned, Dense>, ) -> MathematicalResult<u32>

Run the operation with the provided Architecture.
Source§

impl Target2<Neon, Result<MathematicalValue<u32>, UnequalLengths>, BitSliceBase<3, Unsigned, SlicePtr<'_, u8>>, BitSliceBase<3, Unsigned, SlicePtr<'_, u8>>> for InnerProduct

Source§

fn run( self, arch: Neon, x: BitSlice<'_, N, Unsigned, Dense>, y: BitSlice<'_, N, Unsigned, Dense>, ) -> MathematicalResult<u32>

Run the operation with the provided Architecture.
Source§

impl Target2<Neon, Result<MathematicalValue<u32>, UnequalLengths>, BitSliceBase<3, Unsigned, SlicePtr<'_, u8>>, BitSliceBase<3, Unsigned, SlicePtr<'_, u8>>> for SquaredL2

Source§

fn run( self, arch: Neon, x: BitSlice<'_, N, Unsigned, Dense>, y: BitSlice<'_, N, Unsigned, Dense>, ) -> MathematicalResult<u32>

Run the operation with the provided Architecture.
Source§

impl Target2<Neon, Result<MathematicalValue<u32>, UnequalLengths>, BitSliceBase<4, Unsigned, SlicePtr<'_, u8>>, BitSliceBase<4, Unsigned, SlicePtr<'_, u8>>> for InnerProduct

Source§

fn run( self, arch: Neon, x: BitSlice<'_, N, Unsigned, Dense>, y: BitSlice<'_, N, Unsigned, Dense>, ) -> MathematicalResult<u32>

Run the operation with the provided Architecture.
Source§

impl Target2<Neon, Result<MathematicalValue<u32>, UnequalLengths>, BitSliceBase<4, Unsigned, SlicePtr<'_, u8>>, BitSliceBase<4, Unsigned, SlicePtr<'_, u8>>> for SquaredL2

Source§

fn run( self, arch: Neon, x: BitSlice<'_, N, Unsigned, Dense>, y: BitSlice<'_, N, Unsigned, Dense>, ) -> MathematicalResult<u32>

Run the operation with the provided Architecture.
Source§

impl Target2<Neon, Result<MathematicalValue<u32>, UnequalLengths>, BitSliceBase<5, Unsigned, SlicePtr<'_, u8>>, BitSliceBase<5, Unsigned, SlicePtr<'_, u8>>> for InnerProduct

Source§

fn run( self, arch: Neon, x: BitSlice<'_, N, Unsigned, Dense>, y: BitSlice<'_, N, Unsigned, Dense>, ) -> MathematicalResult<u32>

Run the operation with the provided Architecture.
Source§

impl Target2<Neon, Result<MathematicalValue<u32>, UnequalLengths>, BitSliceBase<5, Unsigned, SlicePtr<'_, u8>>, BitSliceBase<5, Unsigned, SlicePtr<'_, u8>>> for SquaredL2

Source§

fn run( self, arch: Neon, x: BitSlice<'_, N, Unsigned, Dense>, y: BitSlice<'_, N, Unsigned, Dense>, ) -> MathematicalResult<u32>

Run the operation with the provided Architecture.
Source§

impl Target2<Neon, Result<MathematicalValue<u32>, UnequalLengths>, BitSliceBase<6, Unsigned, SlicePtr<'_, u8>>, BitSliceBase<6, Unsigned, SlicePtr<'_, u8>>> for InnerProduct

Source§

fn run( self, arch: Neon, x: BitSlice<'_, N, Unsigned, Dense>, y: BitSlice<'_, N, Unsigned, Dense>, ) -> MathematicalResult<u32>

Run the operation with the provided Architecture.
Source§

impl Target2<Neon, Result<MathematicalValue<u32>, UnequalLengths>, BitSliceBase<6, Unsigned, SlicePtr<'_, u8>>, BitSliceBase<6, Unsigned, SlicePtr<'_, u8>>> for SquaredL2

Source§

fn run( self, arch: Neon, x: BitSlice<'_, N, Unsigned, Dense>, y: BitSlice<'_, N, Unsigned, Dense>, ) -> MathematicalResult<u32>

Run the operation with the provided Architecture.
Source§

impl Target2<Neon, Result<MathematicalValue<u32>, UnequalLengths>, BitSliceBase<7, Unsigned, SlicePtr<'_, u8>>, BitSliceBase<7, Unsigned, SlicePtr<'_, u8>>> for InnerProduct

Source§

fn run( self, arch: Neon, x: BitSlice<'_, N, Unsigned, Dense>, y: BitSlice<'_, N, Unsigned, Dense>, ) -> MathematicalResult<u32>

Run the operation with the provided Architecture.
Source§

impl Target2<Neon, Result<MathematicalValue<u32>, UnequalLengths>, BitSliceBase<7, Unsigned, SlicePtr<'_, u8>>, BitSliceBase<7, Unsigned, SlicePtr<'_, u8>>> for SquaredL2

Source§

fn run( self, arch: Neon, x: BitSlice<'_, N, Unsigned, Dense>, y: BitSlice<'_, N, Unsigned, Dense>, ) -> MathematicalResult<u32>

Run the operation with the provided Architecture.
Source§

impl<const N: usize> Target2<Scalar, Result<MathematicalValue<f32>, UnequalLengths>, &[f32], BitSliceBase<N, Unsigned, SlicePtr<'_, u8>>> for InnerProduct

Source§

fn run( self, _: Scalar, x: &[f32], y: BitSlice<'_, N, Unsigned, Dense>, ) -> MathematicalResult<f32>

A fallback implementation that uses scaler indexing to retrieve values from the corresponding BitSlice.

Source§

impl Target2<Scalar, Result<MathematicalValue<u32>, UnequalLengths>, BitSliceBase<2, Unsigned, SlicePtr<'_, u8>>, BitSliceBase<2, Unsigned, SlicePtr<'_, u8>>> for InnerProduct

Compute the inner product between x and y.

Returns an error if the arguments have different lengths.

§Performance

This function uses a generic implementation and therefore is not very fast.

Source§

fn run( self, _: Scalar, x: BitSlice<'_, N, Unsigned, Dense>, y: BitSlice<'_, N, Unsigned, Dense>, ) -> MathematicalResult<u32>

Run the operation with the provided Architecture.
Source§

impl Target2<Scalar, Result<MathematicalValue<u32>, UnequalLengths>, BitSliceBase<2, Unsigned, SlicePtr<'_, u8>>, BitSliceBase<2, Unsigned, SlicePtr<'_, u8>>> for SquaredL2

Compute the squared L2 distance between x and y.

Returns an error if the arguments have different lengths.

§Performance

This function uses a generic implementation and therefore is not very fast.

Source§

fn run( self, _: Scalar, x: BitSlice<'_, N, Unsigned, Dense>, y: BitSlice<'_, N, Unsigned, Dense>, ) -> MathematicalResult<u32>

Run the operation with the provided Architecture.
Source§

impl Target2<Scalar, Result<MathematicalValue<u32>, UnequalLengths>, BitSliceBase<3, Unsigned, SlicePtr<'_, u8>>, BitSliceBase<3, Unsigned, SlicePtr<'_, u8>>> for InnerProduct

Compute the inner product between x and y.

Returns an error if the arguments have different lengths.

§Performance

This function uses a generic implementation and therefore is not very fast.

Source§

fn run( self, _: Scalar, x: BitSlice<'_, N, Unsigned, Dense>, y: BitSlice<'_, N, Unsigned, Dense>, ) -> MathematicalResult<u32>

Run the operation with the provided Architecture.
Source§

impl Target2<Scalar, Result<MathematicalValue<u32>, UnequalLengths>, BitSliceBase<3, Unsigned, SlicePtr<'_, u8>>, BitSliceBase<3, Unsigned, SlicePtr<'_, u8>>> for SquaredL2

Compute the squared L2 distance between x and y.

Returns an error if the arguments have different lengths.

§Performance

This function uses a generic implementation and therefore is not very fast.

Source§

fn run( self, _: Scalar, x: BitSlice<'_, N, Unsigned, Dense>, y: BitSlice<'_, N, Unsigned, Dense>, ) -> MathematicalResult<u32>

Run the operation with the provided Architecture.
Source§

impl Target2<Scalar, Result<MathematicalValue<u32>, UnequalLengths>, BitSliceBase<4, Unsigned, SlicePtr<'_, u8>>, BitSliceBase<4, Unsigned, SlicePtr<'_, u8>>> for InnerProduct

Compute the inner product between x and y.

Returns an error if the arguments have different lengths.

§Performance

This function uses a generic implementation and therefore is not very fast.

Source§

fn run( self, _: Scalar, x: BitSlice<'_, N, Unsigned, Dense>, y: BitSlice<'_, N, Unsigned, Dense>, ) -> MathematicalResult<u32>

Run the operation with the provided Architecture.
Source§

impl Target2<Scalar, Result<MathematicalValue<u32>, UnequalLengths>, BitSliceBase<4, Unsigned, SlicePtr<'_, u8>>, BitSliceBase<4, Unsigned, SlicePtr<'_, u8>>> for SquaredL2

Compute the squared L2 distance between x and y.

Returns an error if the arguments have different lengths.

§Performance

This function uses a generic implementation and therefore is not very fast.

Source§

fn run( self, _: Scalar, x: BitSlice<'_, N, Unsigned, Dense>, y: BitSlice<'_, N, Unsigned, Dense>, ) -> MathematicalResult<u32>

Run the operation with the provided Architecture.
Source§

impl Target2<Scalar, Result<MathematicalValue<u32>, UnequalLengths>, BitSliceBase<5, Unsigned, SlicePtr<'_, u8>>, BitSliceBase<5, Unsigned, SlicePtr<'_, u8>>> for InnerProduct

Compute the inner product between x and y.

Returns an error if the arguments have different lengths.

§Performance

This function uses a generic implementation and therefore is not very fast.

Source§

fn run( self, _: Scalar, x: BitSlice<'_, N, Unsigned, Dense>, y: BitSlice<'_, N, Unsigned, Dense>, ) -> MathematicalResult<u32>

Run the operation with the provided Architecture.
Source§

impl Target2<Scalar, Result<MathematicalValue<u32>, UnequalLengths>, BitSliceBase<5, Unsigned, SlicePtr<'_, u8>>, BitSliceBase<5, Unsigned, SlicePtr<'_, u8>>> for SquaredL2

Compute the squared L2 distance between x and y.

Returns an error if the arguments have different lengths.

§Performance

This function uses a generic implementation and therefore is not very fast.

Source§

fn run( self, _: Scalar, x: BitSlice<'_, N, Unsigned, Dense>, y: BitSlice<'_, N, Unsigned, Dense>, ) -> MathematicalResult<u32>

Run the operation with the provided Architecture.
Source§

impl Target2<Scalar, Result<MathematicalValue<u32>, UnequalLengths>, BitSliceBase<6, Unsigned, SlicePtr<'_, u8>>, BitSliceBase<6, Unsigned, SlicePtr<'_, u8>>> for InnerProduct

Compute the inner product between x and y.

Returns an error if the arguments have different lengths.

§Performance

This function uses a generic implementation and therefore is not very fast.

Source§

fn run( self, _: Scalar, x: BitSlice<'_, N, Unsigned, Dense>, y: BitSlice<'_, N, Unsigned, Dense>, ) -> MathematicalResult<u32>

Run the operation with the provided Architecture.
Source§

impl Target2<Scalar, Result<MathematicalValue<u32>, UnequalLengths>, BitSliceBase<6, Unsigned, SlicePtr<'_, u8>>, BitSliceBase<6, Unsigned, SlicePtr<'_, u8>>> for SquaredL2

Compute the squared L2 distance between x and y.

Returns an error if the arguments have different lengths.

§Performance

This function uses a generic implementation and therefore is not very fast.

Source§

fn run( self, _: Scalar, x: BitSlice<'_, N, Unsigned, Dense>, y: BitSlice<'_, N, Unsigned, Dense>, ) -> MathematicalResult<u32>

Run the operation with the provided Architecture.
Source§

impl Target2<Scalar, Result<MathematicalValue<u32>, UnequalLengths>, BitSliceBase<7, Unsigned, SlicePtr<'_, u8>>, BitSliceBase<7, Unsigned, SlicePtr<'_, u8>>> for InnerProduct

Compute the inner product between x and y.

Returns an error if the arguments have different lengths.

§Performance

This function uses a generic implementation and therefore is not very fast.

Source§

fn run( self, _: Scalar, x: BitSlice<'_, N, Unsigned, Dense>, y: BitSlice<'_, N, Unsigned, Dense>, ) -> MathematicalResult<u32>

Run the operation with the provided Architecture.
Source§

impl Target2<Scalar, Result<MathematicalValue<u32>, UnequalLengths>, BitSliceBase<7, Unsigned, SlicePtr<'_, u8>>, BitSliceBase<7, Unsigned, SlicePtr<'_, u8>>> for SquaredL2

Compute the squared L2 distance between x and y.

Returns an error if the arguments have different lengths.

§Performance

This function uses a generic implementation and therefore is not very fast.

Source§

fn run( self, _: Scalar, x: BitSlice<'_, N, Unsigned, Dense>, y: BitSlice<'_, N, Unsigned, Dense>, ) -> MathematicalResult<u32>

Run the operation with the provided Architecture.
Source§

impl<const NBITS: usize, Repr, Ptr, Perm, Len> Copy for BitSliceBase<NBITS, Repr, Ptr, Perm, Len>
where Repr: Representation<NBITS> + Copy, Ptr: AsPtr<Type = u8> + Copy, Perm: PermutationStrategy<NBITS> + Copy, Len: Length + Copy,

Auto Trait Implementations§

§

impl<const NBITS: usize, Repr, Ptr, Perm, Len> Freeze for BitSliceBase<NBITS, Repr, Ptr, Perm, Len>
where Ptr: Freeze, Len: Freeze,

§

impl<const NBITS: usize, Repr, Ptr, Perm, Len> RefUnwindSafe for BitSliceBase<NBITS, Repr, Ptr, Perm, Len>
where Ptr: RefUnwindSafe, Len: RefUnwindSafe, Repr: RefUnwindSafe, Perm: RefUnwindSafe,

§

impl<const NBITS: usize, Repr, Ptr, Perm, Len> Send for BitSliceBase<NBITS, Repr, Ptr, Perm, Len>
where Ptr: Send, Len: Send, Repr: Send, Perm: Send,

§

impl<const NBITS: usize, Repr, Ptr, Perm, Len> Sync for BitSliceBase<NBITS, Repr, Ptr, Perm, Len>
where Ptr: Sync, Len: Sync, Repr: Sync, Perm: Sync,

§

impl<const NBITS: usize, Repr, Ptr, Perm, Len> Unpin for BitSliceBase<NBITS, Repr, Ptr, Perm, Len>
where Ptr: Unpin, Len: Unpin, Repr: Unpin, Perm: Unpin,

§

impl<const NBITS: usize, Repr, Ptr, Perm, Len> UnsafeUnpin for BitSliceBase<NBITS, Repr, Ptr, Perm, Len>
where Ptr: UnsafeUnpin, Len: UnsafeUnpin,

§

impl<const NBITS: usize, Repr, Ptr, Perm, Len> UnwindSafe for BitSliceBase<NBITS, Repr, Ptr, Perm, Len>
where Ptr: UnwindSafe, Len: UnwindSafe, Repr: UnwindSafe, Perm: 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> ByRef<T> for T

Source§

fn by_ref(&self) -> &T

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> Generator<T> for T
where T: Clone,

Source§

fn generate(&mut self) -> T

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

Source§

impl<T> AsyncFriendly for T
where T: Send + Sync + 'static,