pub trait VecOps {
    fn vec_scale(&mut self, scale: f32) -> &mut Self;
    fn vec_mul(&mut self, other: impl AsRef<[cf32]>) -> &mut Self;
    fn vec_div(&mut self, other: impl AsRef<[cf32]>) -> &mut Self;
    fn vec_conj(&mut self) -> &mut Self;
    fn vec_mirror(&mut self) -> &mut Self;
    fn vec_clone(&mut self, other: impl AsRef<[cf32]>) -> &mut Self;
    fn vec_zero(&mut self) -> &mut Self;
    fn vec_mutate(&mut self, f: impl FnMut(&mut cf32)) -> &mut Self;
    fn vec_add(&mut self, other: impl AsRef<[cf32]>) -> &mut Self;
    fn vec_sub(&mut self, other: impl AsRef<[cf32]>) -> &mut Self;
}
Expand description

This trait is designed to ease operations on complex slices/“vectors” They are not necessarily the most performant way of doing things but they are written in idiomatic and hence safe Rust.

Example

#[macro_use]
 extern crate aether_primitives;
 use aether_primitives::{cf32, vecops::VecOps};

 let mut v = vec![cf32::new(2.0, 2.0); 100];
 let twos = v.clone();
 let ones = vec![cf32::new(1.0, 1.0); 100];

 let correct = vec![cf32::new(1.0, -1.0); 100];

 v.vec_div(&twos)
     .vec_mul(&twos)
     .vec_zero() // zero the vector
     .vec_add(&ones)
     .vec_sub(&twos)
     .vec_clone(&ones)
     .vec_mutate(|c| c.im = -1.0)
     .vec_conj()
     .vec_mirror(); // mirror swaps elements around the midpoint of the array

 // ensure each element's error vector magnitude in relation to the correct complex number is below -80dB
 assert_evm!(&v, &correct, -80.0);

Required Methods

scale this this vector with the given f32

element-wise multiply this vector with the other one

element-wise divide this vector by the other one

conjugate this vector’s elements

swap elements around the midpoint of this slice assumes an even number of elements

copies the contents of other into self (just shortcut for) slice1[a..b].copy_from_slice(slice[c..d])

zero the elements

mutate each of the elements with a function to apply

element-wise add the other slice to this one

element-wise subtract the other slice from this one

Implementations on Foreign Types

Implementors