Struct Array

Source
pub struct Array<T: Copy> {
    pub data: Rc<RefCell<Vec<T>>>,
    pub shape: Shape,
}
Expand description

Array structure

Fields§

§data: Rc<RefCell<Vec<T>>>§shape: Shape

Implementations§

Source§

impl<T: Copy> Array<T>

Source

pub fn new_bounded( data: Vec<T>, shape: Vec<i32>, start: usize, end: usize, ) -> Array<T>

Creates new bounded array

§Arguments
  • data - array elements
  • shape - vector representing array shape
  • start - start offset of array data
  • end - end offset of array data
Source

pub fn new(data: Vec<T>, shape: Vec<i32>) -> Array<T>

Creates new array

§Arguments
  • data - array elements
  • shape - vector representing array shape
Source

pub fn shape(&self) -> &Shape

Returns Shape instance

Source

pub fn get_shape(&self) -> &Vec<i32>

Returns vector representing array shape

Source

pub fn reshape(&mut self, shape: Vec<i32>) -> &Array<T>

Sets array shape

§Arguments
  • shape - vector representing new array shape
Source

pub fn set_shape(&mut self, shape: Vec<i32>)

Sets array shape

§Arguments
  • shape - vector representing new array shape
Source

pub fn set(&self, indices: Vec<usize>, value: T)

Set values on given indices to given value

§Arguments
  • indices - vector of indices
  • value - value to fill it with
§Examples
#[macro_use] extern crate numas;
use numas::array::Array;

let f_array = Array::new(vec![1,2,3,4,5,6,7,8,9], vec![3,3]);
 
// first row
f_array.set(s![0], -1);
assert_eq!(f_array.collect(), vec![-1,-1,-1,4,5,6,7,8,9]);

let s_array = Array::new(vec![1,2,3,4,5,6,7,8,9], vec![3,3]);

// fist two rows
s_array.set(s![0 => 2], -1);
assert_eq!(s_array.collect(), vec![-1,-1,-1,-1,-1,-1,7,8,9]);

let t_array = Array::new(vec![1,2,3,4,5,6,7,8,9], vec![3,3]);

// second row, second column
t_array.set(s![1; 1], -1);
assert_eq!(t_array.collect(), vec![1,2,3,4,-1,6,7,8,9]);

let x_array = Array::new(vec![1,2,3,4,5,6,7,8,9], vec![3,3]);

// last row, two last columns
x_array.set(s![2; 1 => 3], -1);
assert_eq!(x_array.collect(), vec![1,2,3,4,5,6,7,-1,-1]);
Source

pub fn fill(&self, value: T) -> &Array<T>

Fills array with given value

§Arguments
  • value - fill value
Source

pub fn get(&self, indices: Vec<usize>) -> Array<T>

Return new Array from given indices

§Arguments
  • indices - vector of indices
§Examples
#[macro_use] extern crate numas;
use numas::array::Array;

let array = Array::new(vec![1,2,3,4,5,6,7,8,9], vec![3,3]);

// first row
assert_eq!(array.get(s![0]).collect(), vec![1,2,3]);

// fist two rows
assert_eq!(array.get(s![0 => 2]).collect(), vec![1,2,3,4,5,6]);

// second row, second column
assert_eq!(array.get(s![1; 1]).collect(), vec![5]);

// last row, two last columns
assert_eq!(array.get(s![2; 1 => 3]).collect(), vec![8,9]);
Source

pub fn len(&self) -> usize

Returns length of array

Source

pub fn base_len(&self) -> usize

Returns base length of array

Source

pub fn view(&self) -> Array<T>

Creates view into array

Source

pub fn bounded_view( &self, shape: &Vec<i32>, start: usize, end: usize, ) -> Array<T>

Creates bounded view into array

§Arguments
  • shape - vector representing array shape
  • start - start offset of array data
  • end - end offset of array data
Source

pub fn collect(&self) -> Vec<T>

Collects elements of array into vector

Source§

impl<T> Array<T>
where T: Copy + PartialOrd,

Source

pub fn lt(&self, other: &Array<T>) -> Array<u8>

Returns array of 1s and 0s representing truth value of lesser than element wise

§Arguments
  • other - Array to compare with
§Examples
 use numas::array::Array;;

 let first = Array::new(vec![1, 2, 3, 3], vec![4]);
 let second = Array::new(vec![1, 0, 3, 4], vec![4]);

 let less = first.lt(&second);

 assert_eq!(less.collect(), vec![0, 0, 0, 1]);
Source

pub fn le(&self, other: &Array<T>) -> Array<u8>

Returns array of 1s and 0s representing truth value of lesser equal element wise

§Arguments
  • other - Array to compare with
§Examples
 use numas::array::Array;;

 let first = Array::new(vec![1, 2, 3, 3], vec![4]);
 let second = Array::new(vec![1, 0, 3, 4], vec![4]);

 let less_equal = first.le(&second);

 assert_eq!(less_equal.collect(), vec![1, 0, 1, 1]);
Source

pub fn gt(&self, other: &Array<T>) -> Array<u8>

Returns array of 1s and 0s representing truth value of greater than element wise

§Arguments
  • other - Array to compare with with
§Examples
 use numas::array::Array;;

 let first = Array::new(vec![1, 2, 3, 3], vec![4]);
 let second = Array::new(vec![1, 0, 3, 4], vec![4]);

 let greater = first.gt(&second);

 assert_eq!(greater.collect(), vec![0, 1, 0, 0]);
Source

pub fn ge(&self, other: &Array<T>) -> Array<u8>

Returns array of 1s and 0s representing truth value of greater equal element wise

§Arguments
  • other - Array to compare with
§Examples
 use numas::array::Array;;

 let first = Array::new(vec![1, 2, 3, 3], vec![4]);
 let second = Array::new(vec![1, 0, 3, 4], vec![4]);

 let greater_equal = first.ge(&second);

 assert_eq!(greater_equal.collect(), vec![1, 1, 1, 0]);
Source§

impl<T> Array<T>
where T: Copy + PartialEq,

Source

pub fn eq(&self, other: &Array<T>) -> Array<u8>

Returns array of 1s and 0s representing truth value of equality element wise

§Arguments
  • other - Array to comapre with
§Examples
 use numas::array::Array;;

 let first = Array::new(vec![1, 2, 3, 4], vec![4]);
 let second = Array::new(vec![1, 0, 3, 4], vec![4]);

 let equality = first.eq(&second);

 assert_eq!(equality.collect(), vec![1, 0, 1, 1]);
Source

pub fn neq(&self, other: &Array<T>) -> Array<u8>

Returns array of 1s and 0s representing truth value of not equality element wise

§Arguments
  • other - Array to compare with
§Examples
 use numas::array::Array;;

 let first = Array::new(vec![1, 2, 3, 4], vec![4]);
 let second = Array::new(vec![1, 0, 3, 4], vec![4]);

 let not_equality = first.neq(&second);

 assert_eq!(not_equality.collect(), vec![0, 1, 0, 0]);
Source§

impl<T> Array<T>
where T: Copy + Into<f64>,

Source

pub fn sinh(&self) -> Array<f64>

Applies hyperbolic sine on elements from given array and creates new array

Source

pub fn cosh(&self) -> Array<f64>

Applies hyperbolic cosine on elements from given array and creates new array

Source

pub fn tanh(&self) -> Array<f64>

Applies hyperbolic tangent on elements from given array and creates new array

Source

pub fn arcsinh(&self) -> Array<f64>

Applies inverse hyperbolic sine on elements from given array and creates new array

Source

pub fn arccosh(&self) -> Array<f64>

Applies hyperbolic cosine on elements from given array and creates new array

Source

pub fn arctanh(&self) -> Array<f64>

Applies hyperbolic tangent on elements from given array and creates new array

Source§

impl<T> Array<T>
where T: Copy + Into<f64>,

Source

pub fn sin(&self) -> Array<f64>

Applies sine on elements from given array and creates new array

Source

pub fn cos(&self) -> Array<f64>

Applies cosine on elements from given array and creates new array

Source

pub fn tan(&self) -> Array<f64>

Applies tangent on elements from given array and creates new array

Source

pub fn arcsin(&self) -> Array<f64>

Applies inverse sine on elements from given array and creates new array

Source

pub fn arccos(&self) -> Array<f64>

Applies inverse cosine on elements from given array and creates new array

Source

pub fn arctan(&self) -> Array<f64>

Applies inverse tangent on elements from given array and creates new array

Source

pub fn degrees(&self) -> Array<f64>

Converts elements from given array to degrees and creates new array

Source

pub fn radians(&self) -> Array<f64>

Converts elements from given array to radians and creates new array

Source

pub fn deg2rad(&self) -> Array<f64>

Converts elements from given array to degrees and creates new array

Source

pub fn rad2deg(&self) -> Array<f64>

Converts elements from given array to radians and creates new array

Source§

impl<T> Array<T>
where T: Copy + From<u8>,

Source

pub fn sum(&self) -> T
where T: AddAssign,

Returns sums of all elements in array or view

§Examples
 use numas::array::Array;;

 let array = Array::new(vec![1, 2, 3, 4], vec![4]);

 assert_eq!(array.sum(), 10);
Source

pub fn prod(&self) -> T
where T: MulAssign,

Returns product of all elements in array or view

§Examples
 use numas::array::Array;;

 let array = Array::new(vec![1, 2, 3, 4], vec![4]);

 assert_eq!(array.prod(), 24);
Source§

impl<T> Array<T>
where T: Copy + Into<f64>,

Source

pub fn sqrt(&self) -> Array<f64>

Applies square root on elements from given array and creates new array

§Examples
 use numas::array::Array;

 let array = Array::new(vec![4, 9, 16, 25], vec![4]);
 let sqrt_array = array.sqrt();
 let data = sqrt_array.collect();

 assert_eq!(data, vec![2.0, 3.0, 4.0, 5.0]);
Source§

impl<T> Array<T>
where T: Copy + Into<f64>,

Source

pub fn round(&self) -> Array<f64>

Applies rounding on elements from given array and creates new array

§Examples
 use numas::array::Array;

 let array = Array::new(vec![1.4, 1.5, 2.1, 2.6], vec![4]);
 let rounded = array.round();
 let data = rounded.collect();

 assert_eq!(data, vec![1.0, 2.0, 2.0, 3.0]);
Source

pub fn ceil(&self) -> Array<f64>

Applies round ceil on elements from given array and creates new array

§Examples
 use numas::array::Array;

 let array = Array::new(vec![1.4, -1.5, 2.1, 2.6], vec![4]);
 let rounded = array.ceil();
 let data = rounded.collect();

 assert_eq!(data, vec![2.0, -1.0, 3.0, 3.0]);
Source

pub fn floor(&self) -> Array<f64>

Applies round floor on elements from given array and creates new array

§Examples
 use numas::array::Array;

 let array = Array::new(vec![1.4, -1.5, 2.1, 2.6], vec![4]);
 let rounded = array.floor();
 let data = rounded.collect();

 assert_eq!(data, vec![1.0, -2.0, 2.0, 2.0]);
Source

pub fn trunc(&self) -> Array<f64>

Applies truncating on elements from given array and creates new array

§Examples
 use numas::array::Array;

 let array = Array::new(vec![1.4, -1.5, 2.1, 2.6], vec![4]);
 let rounded = array.round();
 let data = rounded.collect();

 assert_eq!(data, vec![1.0, -2.0, 2.0, 3.0]);
Source§

impl<T> Array<T>
where T: Copy + Into<f64>,

Source

pub fn log(&self, base: f64) -> Array<f64>

Applies logarithm with given base on elements from given array and creates new array

Source

pub fn log2(&self) -> Array<f64>

Applies logarithm with base 2 on elements from given array and creates new array

Source

pub fn log10(&self) -> Array<f64>

Applies logarithm with base 10 on elements from given array and creates new array

Source

pub fn loge(&self) -> Array<f64>

Applies natural logarithm on elements from given array and creates new array

Source§

impl<T> Array<T>
where T: Copy + Into<f64>,

Source

pub fn exp(&self) -> Array<f64>

Applies exponential of elements from given array and creates new array

Source

pub fn exp_m1(&self) -> Array<f64>

Applies exponential minus one with base 2 on elements from given array and creates new array

Source

pub fn exp2(&self) -> Array<f64>

Applies exponential of 2 with base 10 on elements from given array and creates new array

Trait Implementations§

Source§

impl<T> Add for &Array<T>
where T: Copy + Add<Output = T>,

Source§

type Output = Array<T>

The resulting type after applying the + operator.
Source§

fn add(self, other: &Array<T>) -> Array<T>

Performs the + operation. Read more
Source§

impl<T> AddAssign for &Array<T>
where T: Copy + Add<Output = T>,

Source§

fn add_assign(&mut self, other: &Array<T>)

Performs the += operation. Read more
Source§

impl<T: Copy> Clone for Array<T>

Source§

fn clone(&self) -> Array<T>

Clones array object

1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug + Copy> Debug for Array<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Div for &Array<T>
where T: Copy + Div<Output = T>,

Source§

type Output = Array<T>

The resulting type after applying the / operator.
Source§

fn div(self, other: &Array<T>) -> Array<T>

Performs the / operation. Read more
Source§

impl<T> DivAssign for &Array<T>
where T: Copy + Div<Output = T>,

Source§

fn div_assign(&mut self, other: &Array<T>)

Performs the /= operation. Read more
Source§

impl<T> Mul for &Array<T>
where T: Copy + Mul<Output = T>,

Source§

type Output = Array<T>

The resulting type after applying the * operator.
Source§

fn mul(self, other: &Array<T>) -> Array<T>

Performs the * operation. Read more
Source§

impl<T> MulAssign for &Array<T>
where T: Copy + Mul<Output = T>,

Source§

fn mul_assign(&mut self, other: &Array<T>)

Performs the *= operation. Read more
Source§

impl<T> Neg for Array<T>
where T: Copy + Neg<Output = T>,

Source§

type Output = Array<T>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Array<T>

Performs the unary - operation. Read more
Source§

impl<T> Sub for &Array<T>
where T: Copy + Sub<Output = T>,

Source§

type Output = Array<T>

The resulting type after applying the - operator.
Source§

fn sub(self, other: &Array<T>) -> Array<T>

Performs the - operation. Read more
Source§

impl<T> SubAssign for &Array<T>
where T: Copy + Sub<Output = T>,

Source§

fn sub_assign(&mut self, other: &Array<T>)

Performs the -= operation. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Array<T>

§

impl<T> !RefUnwindSafe for Array<T>

§

impl<T> !Send for Array<T>

§

impl<T> !Sync for Array<T>

§

impl<T> Unpin for Array<T>

§

impl<T> !UnwindSafe for Array<T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.