pub struct InnerProduct;Expand description
Compute the inner-product between vector-like types.
Trait Implementations§
Source§impl Clone for InnerProduct
impl Clone for InnerProduct
Source§fn clone(&self) -> InnerProduct
fn clone(&self) -> InnerProduct
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for InnerProduct
impl Debug for InnerProduct
Source§impl<A, B, To> DistanceFunction<A, B, To> for InnerProductwhere
InnerProduct: PureDistanceFunction<A, B, To>,
impl<A, B, To> DistanceFunction<A, B, To> for InnerProductwhere
InnerProduct: PureDistanceFunction<A, B, To>,
Source§fn evaluate_similarity(&self, a: A, b: B) -> To
fn evaluate_similarity(&self, a: A, b: B) -> To
Source§impl PureDistanceFunction<&[f32], BitSliceBase<1, Unsigned, SlicePtr<'_, u8>>, Result<MathematicalValue<f32>, UnequalLengths>> for InnerProduct
Compute the inner product between x and y.
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.
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.
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.
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.
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.
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.
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.
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, Unsigned, SlicePtr<'_, u8>>, BitSliceBase<1, Unsigned, SlicePtr<'_, u8>>, Result<MathematicalValue<u32>, UnequalLengths>> for InnerProduct
Compute the squared L2 distance between x and y.
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<2, Unsigned, SlicePtr<'_, u8>>, BitSliceBase<2, Unsigned, SlicePtr<'_, u8>>, Result<MathematicalValue<u32>, UnequalLengths>> for InnerProduct
Compute the squared L2 distance between x and y.
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<3, Unsigned, SlicePtr<'_, u8>>, BitSliceBase<3, Unsigned, SlicePtr<'_, u8>>, Result<MathematicalValue<u32>, UnequalLengths>> for InnerProduct
Compute the squared L2 distance between x and y.
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<4, Unsigned, SlicePtr<'_, u8>>, BitSliceBase<4, Unsigned, SlicePtr<'_, u8>>, Result<MathematicalValue<u32>, UnequalLengths>> for InnerProduct
Compute the squared L2 distance between x and y.
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>, BitTranspose>, BitSliceBase<1, Unsigned, SlicePtr<'_, u8>>, Result<MathematicalValue<u32>, UnequalLengths>> for InnerProduct
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.
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<6, Unsigned, SlicePtr<'_, u8>>, BitSliceBase<6, Unsigned, SlicePtr<'_, u8>>, Result<MathematicalValue<u32>, UnequalLengths>> for InnerProduct
Compute the squared L2 distance between x and y.
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<7, Unsigned, SlicePtr<'_, u8>>, BitSliceBase<7, Unsigned, SlicePtr<'_, u8>>, Result<MathematicalValue<u32>, UnequalLengths>> for InnerProduct
Compute the squared L2 distance between x and y.
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<8, Unsigned, SlicePtr<'_, u8>>, BitSliceBase<8, Unsigned, SlicePtr<'_, u8>>, Result<MathematicalValue<u32>, UnequalLengths>> for InnerProduct
Compute the squared L2 distance between x and y.
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<A> Target2<A, Result<MathematicalValue<u32>, UnequalLengths>, BitSliceBase<1, Unsigned, SlicePtr<'_, u8>>, BitSliceBase<1, Unsigned, SlicePtr<'_, u8>>> for InnerProductwhere
A: Architecture,
Compute the inner product between bitvectors x and y.
impl<A> Target2<A, Result<MathematicalValue<u32>, UnequalLengths>, BitSliceBase<1, Unsigned, SlicePtr<'_, u8>>, BitSliceBase<1, Unsigned, SlicePtr<'_, u8>>> for InnerProductwhere
A: Architecture,
Compute the inner product between bitvectors x and y.
Returns an error if the arguments have different lengths.
Source§impl<A> Target2<A, Result<MathematicalValue<u32>, UnequalLengths>, BitSliceBase<4, Unsigned, SlicePtr<'_, u8>, BitTranspose>, BitSliceBase<1, Unsigned, SlicePtr<'_, u8>>> for InnerProductwhere
A: Architecture,
The strategy is to compute the inner product <x, y> by decomposing the problem into
groups of 64-dimensions.
impl<A> Target2<A, Result<MathematicalValue<u32>, UnequalLengths>, BitSliceBase<4, Unsigned, SlicePtr<'_, u8>, BitTranspose>, BitSliceBase<1, Unsigned, SlicePtr<'_, u8>>> for InnerProductwhere
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 3We 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§impl<A> Target2<A, Result<MathematicalValue<u32>, UnequalLengths>, BitSliceBase<8, Unsigned, SlicePtr<'_, u8>>, BitSliceBase<8, Unsigned, SlicePtr<'_, u8>>> for InnerProductwhere
A: Architecture,
InnerProduct: for<'a> Target2<A, MathematicalValue<f32>, &'a [u8], &'a [u8]>,
Compute the inner product between x and y.
impl<A> Target2<A, Result<MathematicalValue<u32>, UnequalLengths>, BitSliceBase<8, Unsigned, SlicePtr<'_, u8>>, BitSliceBase<8, Unsigned, SlicePtr<'_, u8>>> for InnerProductwhere
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§impl<const N: usize> Target2<Scalar, Result<MathematicalValue<f32>, UnequalLengths>, &[f32], BitSliceBase<N, Unsigned, SlicePtr<'_, u8>>> for InnerProductwhere
Unsigned: Representation<N>,
impl<const N: usize> Target2<Scalar, Result<MathematicalValue<f32>, UnequalLengths>, &[f32], BitSliceBase<N, Unsigned, SlicePtr<'_, u8>>> for InnerProductwhere
Unsigned: Representation<N>,
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.
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§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.
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§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.
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§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.
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§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.
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§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.
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.
impl Copy for InnerProduct
Auto Trait Implementations§
impl Freeze for InnerProduct
impl RefUnwindSafe for InnerProduct
impl Send for InnerProduct
impl Sync for InnerProduct
impl Unpin for InnerProduct
impl UnwindSafe for InnerProduct
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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