Trait AmpLike

Source
pub trait AmpLike<F: Field>:
    Send
    + Sync
    + Debug
    + Display
    + AsTree
    + DynClone {
    // Required methods
    fn walk(&self) -> Vec<Amplitude<F>>;
    fn walk_mut(&mut self) -> Vec<&mut Amplitude<F>>;
    fn compute(&self, cache: &[Option<Complex<F>>]) -> Option<Complex<F>>;

    // Provided methods
    fn get_cloned_terms(&self) -> Option<Vec<Box<dyn AmpLike<F>>>> { ... }
    fn real(&self) -> Real<F>
       where Self: Sized + 'static { ... }
    fn imag(&self) -> Imag<F>
       where Self: Sized + 'static { ... }
    fn prod(als: &Vec<Box<dyn AmpLike<F>>>) -> Product<F>
       where Self: Sized + 'static { ... }
    fn sum(als: &Vec<Box<dyn AmpLike<F>>>) -> Sum<F>
       where Self: Sized + 'static { ... }
}
Expand description

This trait is used to implement operations which can be performed on Amplitudes (and other operations themselves). Currently, there are only a limited number of defined operations, namely Real, Imag, and Product. Others may be added in the future, but they should probably only be added through this crate and not externally, since they require several operator overloads to be implemented for nice syntax.

Required Methods§

Source

fn walk(&self) -> Vec<Amplitude<F>>

This method walks through an AmpLike struct and recursively amalgamates a list of Amplitudes contained within. Note that these Amplitudes are owned clones of the interior structures.

Source

fn walk_mut(&mut self) -> Vec<&mut Amplitude<F>>

This method is similar to AmpLike::walk, but returns mutable references rather than clones.

Source

fn compute(&self, cache: &[Option<Complex<F>>]) -> Option<Complex<F>>

Given a cache of complex values calculated from a list of amplitudes, this method will calculate the desired mathematical structure given by the AmpLike and any AmpLikes it contains.

Provided Methods§

Source

fn get_cloned_terms(&self) -> Option<Vec<Box<dyn AmpLike<F>>>>

This method returns clones of any AmpLikes wrapped by the given AmpLike.

Source

fn real(&self) -> Real<F>
where Self: Sized + 'static,

Take the real part of an Amplitude or Amplitude-like struct.

Source

fn imag(&self) -> Imag<F>
where Self: Sized + 'static,

Take the imaginary part of an Amplitude or Amplitude-like struct.

Source

fn prod(als: &Vec<Box<dyn AmpLike<F>>>) -> Product<F>
where Self: Sized + 'static,

Take the product of a Vec of Amplitude-like structs.

Source

fn sum(als: &Vec<Box<dyn AmpLike<F>>>) -> Sum<F>
where Self: Sized + 'static,

Take the sum of a Vec of Amplitude-like structs.

Trait Implementations§

Source§

impl<F: Field + 'static> Add<Amplitude<F>> for Box<dyn AmpLike<F>>

Source§

type Output = Sum<F>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Amplitude<F>) -> Self::Output

Performs the + operation. Read more
Source§

impl<F: Field + 'static> Add<Imag<F>> for Box<dyn AmpLike<F>>

Source§

type Output = Sum<F>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Imag<F>) -> Self::Output

Performs the + operation. Read more
Source§

impl<F: Field + 'static> Add<Product<F>> for Box<dyn AmpLike<F>>

Source§

type Output = Sum<F>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Product<F>) -> Self::Output

Performs the + operation. Read more
Source§

impl<F: Field + 'static> Add<Real<F>> for Box<dyn AmpLike<F>>

Source§

type Output = Sum<F>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Real<F>) -> Self::Output

Performs the + operation. Read more
Source§

impl<F: Field + 'static> Add<Sum<F>> for Box<dyn AmpLike<F>>

Source§

type Output = Sum<F>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Sum<F>) -> Self::Output

Performs the + operation. Read more
Source§

impl<F: Field + 'static> Mul<Amplitude<F>> for Box<dyn AmpLike<F>>

Source§

type Output = Product<F>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Amplitude<F>) -> Self::Output

Performs the * operation. Read more
Source§

impl<F: Field + 'static> Mul<Imag<F>> for Box<dyn AmpLike<F>>

Source§

type Output = Product<F>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Imag<F>) -> Self::Output

Performs the * operation. Read more
Source§

impl<F: Field + 'static> Mul<Product<F>> for Box<dyn AmpLike<F>>

Source§

type Output = Product<F>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Product<F>) -> Self::Output

Performs the * operation. Read more
Source§

impl<F: Field + 'static> Mul<Real<F>> for Box<dyn AmpLike<F>>

Source§

type Output = Product<F>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Real<F>) -> Self::Output

Performs the * operation. Read more

Implementors§

Source§

impl<F: Field> AmpLike<F> for Amplitude<F>

Source§

impl<F: Field> AmpLike<F> for Imag<F>

Source§

impl<F: Field> AmpLike<F> for Product<F>

Source§

impl<F: Field> AmpLike<F> for Real<F>

Source§

impl<F: Field> AmpLike<F> for Sum<F>