Trait basic_dsp_vector::ElementaryOps
[−]
[src]
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:
VectorsMustHaveTheSameSize
:self
andsummand
must have the same sizeVectorMetaDataMustAgree
:self
andsummand
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:
VectorsMustHaveTheSameSize
:self
andsubtrahend
must have the same sizeVectorMetaDataMustAgree
:self
andsubtrahend
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:
VectorsMustHaveTheSameSize
:self
andfactor
must have the same sizeVectorMetaDataMustAgree
:self
andfactor
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:
VectorsMustHaveTheSameSize
:self
anddivisor
must have the same sizeVectorMetaDataMustAgree
:self
anddivisor
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..]);
Implementors
impl<T, N, D> ElementaryOps<Identifier<T, N, D>, T, N, D> for Identifier<T, N, D> where
T: RealNumber,
N: NumberSpace,
D: Domain,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,