Trait basic_dsp::ElementaryWrapAroundOps
source · [−]pub trait ElementaryWrapAroundOps<A, T, N, D>where
T: RealNumber,
N: NumberSpace,
D: Domain,
A: GetMetaData<T, N, D>,{
fn add_smaller(&mut self, summand: &A) -> Result<(), ErrorReason>;
fn sub_smaller(&mut self, summand: &A) -> Result<(), ErrorReason>;
fn mul_smaller(&mut self, factor: &A) -> Result<(), ErrorReason>;
fn div_smaller(&mut self, divisor: &A) -> Result<(), ErrorReason>;
}
Expand description
Elementary algebra on types where the argument might contain less data points than self
.
Required Methods
sourcefn add_smaller(&mut self, summand: &A) -> Result<(), ErrorReason>
fn add_smaller(&mut self, summand: &A) -> Result<(), ErrorReason>
Calculates the sum of self + summand
. summand
may be smaller than self
as long
as self.len() % summand.len() == 0
. THe result is the same as it would be if
you would repeat summand
until it has the same length as self
.
It consumes self and returns the result.
Failures
TransRes may report the following ErrorReason
members:
InvalidArgumentLength
:self.points()
isn’t dividable bysummand.points()
VectorMetaDataMustAgree
:self
andsummand
must be in the same domain and number space
Example
use basic_dsp_vector::*;
let mut vector1 = vec!(10.0, 11.0, 12.0, 13.0).to_real_time_vec();
let vector2 = vec!(1.0, 2.0).to_real_time_vec();
vector1.add_smaller(&vector2).expect("Ignoring error handling in examples");
assert_eq!([11.0, 13.0, 13.0, 15.0], vector1[0..]);
sourcefn sub_smaller(&mut self, summand: &A) -> Result<(), ErrorReason>
fn sub_smaller(&mut self, summand: &A) -> Result<(), ErrorReason>
Calculates the sum of self - subtrahend
. subtrahend
may be smaller than self
as long
as self.len() % subtrahend.len() == 0
. THe result is the same as it would be if
you would repeat subtrahend
until it has the same length as self
.
It consumes self and returns the result.
Failures
TransRes may report the following ErrorReason
members:
InvalidArgumentLength
:self.points()
isn’t dividable bysubtrahend.points()
VectorMetaDataMustAgree
:self
andsubtrahend
must be in the same domain and number space
Example
use basic_dsp_vector::*;
let mut vector1 = vec!(10.0, 11.0, 12.0, 13.0).to_real_time_vec();
let vector2 = vec!(1.0, 2.0).to_real_time_vec();
vector1.sub_smaller(&vector2).expect("Ignoring error handling in examples");
assert_eq!([9.0, 9.0, 11.0, 11.0], vector1[0..]);
sourcefn mul_smaller(&mut self, factor: &A) -> Result<(), ErrorReason>
fn mul_smaller(&mut self, factor: &A) -> Result<(), ErrorReason>
Calculates the sum of self - factor
. factor
may be smaller than self
as long
as self.len() % factor.len() == 0
. THe result is the same as it would be if
you would repeat factor
until it has the same length as self
.
It consumes self and returns the result.
Failures
TransRes may report the following ErrorReason
members:
InvalidArgumentLength
:self.points()
isn’t dividable byfactor.points()
VectorMetaDataMustAgree
:self
andfactor
must be in the same domain and number space
Example
use basic_dsp_vector::*;
let mut vector1 = vec!(10.0, 11.0, 12.0, 13.0).to_real_time_vec();
let vector2 = vec!(1.0, 2.0).to_real_time_vec();
vector1.mul_smaller(&vector2).expect("Ignoring error handling in examples");
assert_eq!([10.0, 22.0, 12.0, 26.0], vector1[0..]);
sourcefn div_smaller(&mut self, divisor: &A) -> Result<(), ErrorReason>
fn div_smaller(&mut self, divisor: &A) -> Result<(), ErrorReason>
Calculates the sum of self - divisor
. divisor
may be smaller than self
as long
as self.len() % divisor.len() == 0
. THe result is the same as it would be if
you would repeat divisor
until it has the same length as self
.
It consumes self and returns the result.
Failures
TransRes may report the following ErrorReason
members:
InvalidArgumentLength
:self.points()
isn’t dividable bydivisor.points()
VectorMetaDataMustAgree
:self
anddivisor
must be in the same domain and number space
Example
use basic_dsp_vector::*;
let mut vector1 = vec!(10.0, 12.0, 12.0, 14.0).to_real_time_vec();
let vector2 = vec!(1.0, 2.0).to_real_time_vec();
vector1.div_smaller(&vector2).expect("Ignoring error handling in examples");
assert_eq!([10.0, 6.0, 12.0, 7.0], vector1[0..]);