alloy::ops

Trait TryDot

source
pub trait TryDot<Rhs: ?Sized = Self> {
    type Error;
    type Output;

    // Required method
    fn try_dot(&self, rhs: &Rhs) -> Result<Self::Output, Self::Error>;

    // Provided method
    unsafe fn dot_unchecked(&self, rhs: &Rhs) -> Self::Output { ... }
}
Expand description

Fallible trait for an algabraic scalar product between two possibly inequal-length sequences of numbers and returns a single value.

This largely exists to enable a safe-ish way to perform a dot product between unsized slices, as this does come up from time-to-time. See Dot for the infallible equivalent. This trait is to TryFrom as Dot is to From.

See Dot Product for more information.

Required Associated Types§

source

type Error

The error to return on failure.

source

type Output

The type to output on success.

Required Methods§

source

fn try_dot(&self, rhs: &Rhs) -> Result<Self::Output, Self::Error>

Attempts to perform a [dot-product] between two possibly different-sized sequences of values.

§Parameters
  • rhs - the other sequence of values to perform the product with

Provided Methods§

source

unsafe fn dot_unchecked(&self, rhs: &Rhs) -> Self::Output

Performs an unguarded [dot-product] between two possibly different-sized sequences of values.

§Parameters
  • rhs - the other sequence of values to perform the product with
§Safety

This function call will be undefined-behavior if try_dot does not yield a value.

Implementations on Foreign Types§

source§

impl TryDot for [f32]

source§

type Error = DotError

source§

type Output = f32

source§

fn try_dot(&self, rhs: &Self) -> Result<Self::Output, Self::Error>

source§

unsafe fn dot_unchecked(&self, rhs: &Self) -> Self::Output

source§

impl TryDot for [f64]

source§

type Error = DotError

source§

type Output = f64

source§

fn try_dot(&self, rhs: &Self) -> Result<Self::Output, Self::Error>

source§

unsafe fn dot_unchecked(&self, rhs: &Self) -> Self::Output

Implementors§

source§

impl<T, U> TryDot<U> for T
where T: Dot<U>,