[][src]Trait basic_dsp_vector::ElementaryOps

pub trait ElementaryOps<A, T: RealNumber, N: NumberSpace, D: Domain> where
    A: GetMetaData<T, N, D>, 
{ fn add(&mut self, summand: &A) -> VoidResult;
fn sub(&mut self, subtrahend: &A) -> VoidResult;
fn mul(&mut self, factor: &A) -> VoidResult;
fn div(&mut self, divisor: &A) -> VoidResult; }

Elementary algebra on types: addition, subtraction, multiplication and division

Required methods

fn add(&mut self, summand: &A) -> VoidResult

Calculates the sum of self + summand. It consumes self and returns the result.

Failures

TransRes may report the following ErrorReason members:

  1. VectorsMustHaveTheSameSize: self and summand must have the same size
  2. VectorMetaDataMustAgree: self and summand must be in the same domain and number space

Example

use basic_dsp_vector::*;
let mut vector1 = vec!(1.0, 2.0).to_real_time_vec();
let vector2 = vec!(10.0, 11.0).to_real_time_vec();
vector1.add(&vector2).expect("Ignoring error handling in examples");
assert_eq!([11.0, 13.0], vector1[0..]);

fn sub(&mut self, subtrahend: &A) -> VoidResult

Calculates the difference of self - subtrahend. It consumes self and returns the result.

Failures

TransRes may report the following ErrorReason members:

  1. VectorsMustHaveTheSameSize: self and subtrahend must have the same size
  2. VectorMetaDataMustAgree: self and subtrahend must be in the same domain and number space

Example

use basic_dsp_vector::*;
let mut vector1 = vec!(1.0, 2.0).to_real_time_vec();
let vector2 = vec!(10.0, 11.0).to_real_time_vec();
vector1.sub(&vector2).expect("Ignoring error handling in examples");
assert_eq!([-9.0, -9.0], vector1[0..]);

fn mul(&mut self, factor: &A) -> VoidResult

Calculates the product of self * factor. It consumes self and returns the result.

Failures

TransRes may report the following ErrorReason members:

  1. VectorsMustHaveTheSameSize: self and factor must have the same size
  2. VectorMetaDataMustAgree: self and factor must be in the same domain and number space

Example

use basic_dsp_vector::*;
let mut vector1 = vec!(1.0, 2.0).to_real_time_vec();
let vector2 = vec!(10.0, 11.0).to_real_time_vec();
vector1.mul(&vector2).expect("Ignoring error handling in examples");
assert_eq!([10.0, 22.0], vector1[0..]);

fn div(&mut self, divisor: &A) -> VoidResult

Calculates the quotient of self / summand. It consumes self and returns the result.

Failures

TransRes may report the following ErrorReason members:

  1. VectorsMustHaveTheSameSize: self and divisor must have the same size
  2. VectorMetaDataMustAgree: self and divisor must be in the same domain and number space

Example

use basic_dsp_vector::*;
let mut vector1 = vec!(10.0, 22.0).to_real_time_vec();
let vector2 = vec!(2.0, 11.0).to_real_time_vec();
vector1.div(&vector2).expect("Ignoring error handling in examples");
assert_eq!([5.0, 2.0], vector1[0..]);
Loading content...

Implementors

impl<S, T, N, D, O, NO, DO> ElementaryOps<O, T, NO, DO> for DspVec<S, T, N, D> where
    S: ToSliceMut<T>,
    T: RealNumber,
    N: NumberSpace,
    D: Domain,
    O: Vector<T> + Index<RangeFull, Output = [T]> + GetMetaData<T, NO, DO>,
    NO: PosEq<N> + NumberSpace,
    DO: PosEq<D> + Domain
[src]

Loading content...