Trait arr_rs::traits::math::ArrayMath

source ·
pub trait ArrayMath<N: Numeric>where
    Self: Sized + Clone,{
    // Required methods
    fn power(&self, value: N) -> Result<Array<N>, ArrayError>;
    fn product(&self) -> Result<N, ArrayError>;
    fn sum(&self) -> Result<N, ArrayError>;
    fn cumsum(&self) -> Result<Array<N>, ArrayError>;
}
Expand description

ArrayTrait - Array Math functions

Required Methods§

source

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

Computes power of array elements

Examples
use arr_rs::prelude::*;

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

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

Multiplication of array elements

Examples
use arr_rs::prelude::*;

let arr = Array::flat(vec![1,2,3,4]);
let multiplied = arr.product().unwrap();
assert_eq!(24, multiplied);
source

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

Sum of array elements

Examples
use arr_rs::prelude::*;

let arr = Array::flat(vec![1,2,3,4]);
let sum = arr.sum().unwrap();
assert_eq!(10, sum);
source

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

Cumulative sum of array elements

Examples
use arr_rs::prelude::*;

let arr = Array::flat(vec![1,2,3,4]).unwrap();
let sum = arr.cumsum().unwrap();
assert_eq!(Array::flat(vec![1, 3, 6, 10]).unwrap(), sum);

Implementations on Foreign Types§

source§

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

source§

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

source§

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

source§

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

source§

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

Implementors§

source§

impl<N: Numeric> ArrayMath<N> for Array<N>