Trait ArrayArithmetic

Source
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()));
§Errors

may returns ArrayError

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());
§Errors

may returns ArrayError

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());
§Errors

may returns ArrayError

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());
§Errors

may returns ArrayError

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()));
§Errors

may returns ArrayError

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()));
§Errors

may returns ArrayError

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()));
§Errors

may returns ArrayError

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()));
§Errors

may returns ArrayError

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()));
§Errors

may returns ArrayError

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()));
§Errors

may returns ArrayError

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()));
§Errors

may returns ArrayError

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()));
§Errors

may returns ArrayError

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()));
§Errors

may returns ArrayError

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());
§Errors

may returns ArrayError

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()));
§Errors

may returns ArrayError

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());
§Errors

may returns ArrayError

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

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

Source§

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

Source§

fn reciprocal(&self) -> Self

Source§

fn positive(&self) -> Self

Source§

fn negative(&self) -> Self

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Implementors§