pub trait ArrayArithmetic<N: Numeric>where
    Self: Sized + Clone,{
Show 16 methods // Required methods fn add(&self, value: &Array<N>) -> Result<Array<N>, ArrayError>; fn reciprocal(&self) -> Result<Array<N>, ArrayError>; fn positive(&self) -> Result<Array<N>, ArrayError>; fn negative(&self) -> Result<Array<N>, ArrayError>; fn multiply(&self, value: &Array<N>) -> Result<Array<N>, ArrayError>; fn divide(&self, value: &Array<N>) -> Result<Array<N>, ArrayError>; fn true_divide(&self, value: &Array<N>) -> Result<Array<N>, ArrayError>; fn floor_divide(&self, value: &Array<N>) -> Result<Array<N>, ArrayError>; fn power(&self, value: &Array<N>) -> Result<Array<N>, ArrayError>; fn float_power(&self, value: &Array<N>) -> Result<Array<N>, ArrayError>; fn subtract(&self, value: &Array<N>) -> Result<Array<N>, ArrayError>; fn mod(&self, value: &Array<N>) -> Result<Array<N>, ArrayError>; fn fmod(&self, value: &Array<N>) -> Result<Array<N>, ArrayError>; fn modf(&self) -> Result<(Array<N>, Array<N>), ArrayError>; fn remainder(&self, value: &Array<N>) -> Result<Array<N>, ArrayError>; fn divmod(&self) -> Result<(Array<N>, Array<N>), ArrayError>;
}
Expand description

ArrayTrait - Array Arithmetic functions

Required Methods§

source

fn add(&self, value: &Array<N>) -> Result<Array<N>, ArrayError>

Add arguments element-wise

Arguments
  • value - other array to perform operations on
Examples
use arr_rs::prelude::*;

let arr = Array::flat(vec![1, 2, 3, 4]);
assert_eq!(Array::flat(vec![3, 4, 5, 6]), arr.add(&Array::single(2).unwrap()));
source

fn reciprocal(&self) -> Result<Array<N>, ArrayError>

Computes reciprocal of array elements

Examples
use arr_rs::prelude::*;

let arr = Array::flat(vec![1., 2., 4., 10.]);
assert_eq!(Array::flat(vec![1., 0.5, 0.25, 0.1]), arr.reciprocal());
source

fn positive(&self) -> Result<Array<N>, ArrayError>

Computes numerical positive of array elements Equivalent to self.clone()

Examples
use arr_rs::prelude::*;

let arr = Array::flat(vec![1., -1.]);
assert_eq!(Array::flat(vec![1., -1.]), arr.positive());
source

fn negative(&self) -> Result<Array<N>, ArrayError>

Computes numerical negative of array elements

Examples
use arr_rs::prelude::*;

let arr = Array::flat(vec![1., -1.]);
assert_eq!(Array::flat(vec![-1., 1.]), arr.negative());
source

fn multiply(&self, value: &Array<N>) -> Result<Array<N>, ArrayError>

Multiply arguments element-wise

Arguments
  • value - other array to perform operations on
Examples
use arr_rs::prelude::*;

let arr = Array::flat(vec![1, 2, 3, 4]);
assert_eq!(Array::flat(vec![2, 4, 6, 8]), arr.multiply(&Array::single(2).unwrap()));
source

fn divide(&self, value: &Array<N>) -> Result<Array<N>, ArrayError>

Divide arguments element-wise

Arguments
  • value - other array to perform operations on
Examples
use arr_rs::prelude::*;

let arr = Array::flat(vec![1., 2., 3., 4.]);
assert_eq!(Array::flat(vec![0.5, 1., 1.5, 2.]), arr.divide(&Array::single(2.).unwrap()));
source

fn true_divide(&self, value: &Array<N>) -> Result<Array<N>, ArrayError>

Divide arguments element-wise alias on divide

Arguments
  • value - other array to perform operations on
Examples
use arr_rs::prelude::*;

let arr = Array::flat(vec![1., 2., 3., 4.]);
assert_eq!(Array::flat(vec![0.5, 1., 1.5, 2.]), arr.true_divide(&Array::single(2.).unwrap()));
source

fn floor_divide(&self, value: &Array<N>) -> Result<Array<N>, ArrayError>

Divide arguments element-wise, returning floor value

Arguments
  • value - other array to perform operations on
Examples
use arr_rs::prelude::*;

let arr = Array::flat(vec![1., 2., 3., 4.]);
assert_eq!(Array::flat(vec![0., 1., 1., 2.]), arr.floor_divide(&Array::single(2.).unwrap()));
source

fn power(&self, value: &Array<N>) -> Result<Array<N>, ArrayError>

Computes integer power of array elements

Arguments
  • value - other array to perform operations on
Examples
use arr_rs::prelude::*;

let arr = Array::flat(vec![1, 2, 3, 4]);
assert_eq!(Array::flat(vec![1, 4, 9, 16]), arr.power(&Array::single(2).unwrap()));
source

fn float_power(&self, value: &Array<N>) -> Result<Array<N>, ArrayError>

Computes float power of array elements

Arguments
  • value - other array to perform operations on
Examples
use arr_rs::prelude::*;

let arr = Array::flat(vec![1, 2, 3, 4]);
assert_eq!(Array::flat(vec![1, 4, 9, 16]), arr.float_power(&Array::single(2).unwrap()));
source

fn subtract(&self, value: &Array<N>) -> Result<Array<N>, ArrayError>

Subtract arguments element-wise

Arguments
  • value - other array to perform operations on
Examples
use arr_rs::prelude::*;

let arr = Array::flat(vec![1, 2, 3, 4]);
assert_eq!(Array::flat(vec![-1, 0, 1, 2]), arr.subtract(&Array::single(2).unwrap()));
source

fn mod(&self, value: &Array<N>) -> Result<Array<N>, ArrayError>

Computes remainder of division element-wise alias on remainder

Arguments
  • value - other array to perform operations on
Examples
use arr_rs::prelude::*;

let arr = Array::flat(vec![1, 2, 3, 4]);
assert_eq!(Array::flat(vec![1, 0, 1, 0]), arr.r#mod(&Array::single(2).unwrap()));
source

fn fmod(&self, value: &Array<N>) -> Result<Array<N>, ArrayError>

Computes remainder of division element-wise

Arguments
  • value - other array to perform operations on
Examples
use arr_rs::prelude::*;

let arr = Array::flat(vec![1, 2, 3, 4]);
assert_eq!(Array::flat(vec![1, 0, 1, 0]), arr.fmod(&Array::single(2).unwrap()));
source

fn modf(&self) -> Result<(Array<N>, Array<N>), ArrayError>

Computes fractional and integral parts of an array, element-wise

Examples
use arr_rs::prelude::*;

let arr = Array::flat(vec![1.5, 2., 3.5]);
assert_eq!(Ok((Array::flat(vec![0.5, 0., 0.5]).unwrap(), Array::flat(vec![1., 2., 3.]).unwrap())), arr.modf());
source

fn remainder(&self, value: &Array<N>) -> Result<Array<N>, ArrayError>

Computes remainder of division element-wise

Arguments
  • value - other array to perform operations on
Examples
use arr_rs::prelude::*;

let arr = Array::flat(vec![1, 2, 3, 4]);
assert_eq!(Array::flat(vec![1, 0, 1, 0]), arr.remainder(&Array::single(2).unwrap()));
source

fn divmod(&self) -> Result<(Array<N>, Array<N>), ArrayError>

Computes integral and fractional parts of an array, element-wise

Examples
use arr_rs::prelude::*;

let arr = Array::flat(vec![1.5, 2., 3.5]);
assert_eq!(Ok((Array::flat(vec![1., 2., 3.]).unwrap(), Array::flat(vec![0.5, 0., 0.5]).unwrap())), arr.divmod());

Implementations on Foreign Types§

source§

impl<N: Numeric> ArrayArithmetic<N> for Result<Array<N>, ArrayError>

source§

fn add(&self, value: &Array<N>) -> Result<Array<N>, ArrayError>

source§

fn reciprocal(&self) -> Result<Array<N>, ArrayError>

source§

fn positive(&self) -> Result<Array<N>, ArrayError>

source§

fn negative(&self) -> Result<Array<N>, ArrayError>

source§

fn multiply(&self, value: &Array<N>) -> Result<Array<N>, ArrayError>

source§

fn divide(&self, value: &Array<N>) -> Result<Array<N>, ArrayError>

source§

fn true_divide(&self, value: &Array<N>) -> Result<Array<N>, ArrayError>

source§

fn floor_divide(&self, value: &Array<N>) -> Result<Array<N>, ArrayError>

source§

fn power(&self, value: &Array<N>) -> Result<Array<N>, ArrayError>

source§

fn float_power(&self, value: &Array<N>) -> Result<Array<N>, ArrayError>

source§

fn subtract(&self, value: &Array<N>) -> Result<Array<N>, ArrayError>

source§

fn mod(&self, value: &Array<N>) -> Result<Array<N>, ArrayError>

source§

fn fmod(&self, value: &Array<N>) -> Result<Array<N>, ArrayError>

source§

fn modf(&self) -> Result<(Array<N>, Array<N>), ArrayError>

source§

fn remainder(&self, value: &Array<N>) -> Result<Array<N>, ArrayError>

source§

fn divmod(&self) -> Result<(Array<N>, Array<N>), ArrayError>

Implementors§