Struct NDArray

Source
pub struct NDArray<T> {
    pub shape: Shape,
    pub size: usize,
    pub rank: usize,
    pub values: Vec<T>,
}

Fields§

§shape: Shape§size: usize§rank: usize§values: Vec<T>

Implementations§

Source§

impl<T: Default + Clone + Debug + PartialEq> NDArray<T>

Source

pub fn rank(&self) -> usize

Gets the rank of the current array

Source

pub fn shape(&self) -> &Shape

Returns the shape dimensions of the array

Source

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

Get the generic values stored in the array

Source

pub fn size(&self) -> usize

Get the current calculated size of the contigous array

Source

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

Get generic value from provided indices

Source

pub fn idx(&self, index: usize) -> &T

Get generic value from provided indices

Source

pub fn set_rank(&mut self, new_rank: usize)

Lets you change the rank of the current ndarray

Source

pub fn new(shape: Vec<usize>) -> Result<NDArray<T>, String>

Create instance of NDArray, provide shape dimensions as parameter

Source

pub fn array(shape: Vec<usize>, values: Vec<T>) -> Result<NDArray<T>, String>

Create instance of NDArray, provide shape dimensions and array values as parameter

Source

pub fn fill(shape: Vec<usize>, value: T) -> Result<NDArray<T>, String>

Fill ndarray with values

Source

pub fn reshape(&mut self, shape_vals: Vec<usize>) -> Result<(), String>

Reshape dimensions of array to new shape. Shape must match current size

Source

pub fn index(&self, indices: Vec<usize>) -> Result<usize, String>

Get contigous index of array using provided indices as parameter

Source

pub fn indices(&self, index: usize) -> Result<Vec<usize>, String>

Get indices from provided contigous index as parameter

Source

pub fn set_idx(&mut self, idx: usize, value: T) -> Result<(), String>

Set index and generic value, index must be within size of array

Source

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

Set generic value using provided indices. Indices must match rank of array

Source

pub fn rows(&self, index: usize) -> Result<Vec<T>, String>

Get rows dimension associated with multi dimensional array

Source

pub fn cols(&self, index: usize) -> Result<Vec<T>, String>

Get column dimension associated with multi dimensional array

Source

pub fn axis(&self, axis: usize, index: usize) -> Result<NDArray<T>, String>

Get values from a specific axis/slice

Source

pub fn axis_indices( &self, axis: usize, indices: Vec<usize>, ) -> Result<NDArray<T>, String>

Get mutiple axis values with provided indices

Source

pub fn drop_axis(&self, axis: usize, index: usize) -> Result<NDArray<T>, String>

Drop specified axis of ndarray

Source

pub fn batch(&self, batch_size: usize) -> Result<Vec<NDArray<T>>, String>

Batch ndarray in specified amount of chunks of rows, cols etc.

Source

pub fn value_indices(&self, value: T) -> Vec<usize>

Source

pub fn indice_query(&self, indices: Vec<usize>) -> Result<NDArray<T>, String>

Source

pub fn split( &self, axis: usize, percentage: f64, ) -> Result<(NDArray<T>, NDArray<T>), String>

Trait Implementations§

Source§

impl AggregateOps for NDArray<f64>

Source§

fn avg(&self) -> f64

Take the average of all elements in ndarray structure

Source§

fn length(&self) -> f64

Computes the length or magnitude of vector

Source§

fn square(&self) -> Result<NDArray<f64>, String>

Raise all elements to the second power

Source§

fn sum(&self) -> Result<NDArray<f64>, String>

sum all elements in ndarray structure

Source§

fn abs(&self) -> Result<NDArray<f64>, String>

Get the absolute value of each element in ndarray

Source§

fn sort(&self) -> Vec<f64>

Sort values in ndarray on specific axis

Source§

fn unique(&self) -> Vec<f64>

Get unique values in ndarray

Source§

fn mean(&self, axis: usize) -> Result<Vec<f64>, String>

Calculate the mean of values along a specific axis

Source§

fn stdev(&self, axis: usize) -> Result<Vec<f64>, String>

Calculate the mean of values along a specific axis

Source§

fn stdev_sample(&self, axis: usize) -> Result<Vec<f64>, String>

Calculate the mean of values along a specific axis

Source§

impl BinaryOps for NDArray<f64>

Source§

fn mult(&self, other: NDArray<f64>) -> Result<NDArray<f64>, String>

Multiply an ndarray by another

Source§

fn add(&self, value: NDArray<f64>) -> Result<NDArray<f64>, String>

Add two NDArray’s and get resulting NDArray instance

Source§

fn subtract(&self, value: NDArray<f64>) -> Result<NDArray<f64>, String>

Subtract values in NDArray instances

Source§

fn dot(&self, input: NDArray<f64>) -> Result<NDArray<f64>, String>

Perform dot product of current NDArray on another NDArray instance

Source§

fn scale_add(&self, value: NDArray<f64>) -> Result<NDArray<f64>, String>

Add values by scalar for current NDArray instance

Source§

fn scale_mult(&self, value: NDArray<f64>) -> Result<NDArray<f64>, String>

Elementwise multiplication of ndarray

Source§

fn save(&self, filepath: &str) -> Result<()>

Save instance of NDArray to json file with serialized values

Source§

fn load(filepath: &str) -> Result<NDArray<f64>>

Load Instance of saved NDarray, serialize to NDArray structure

Source§

impl<T: Clone> Clone for NDArray<T>

Source§

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

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for NDArray<T>

Source§

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

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

impl<'de, T> Deserialize<'de> for NDArray<T>
where T: Deserialize<'de>,

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<T: PartialEq> PartialEq for NDArray<T>

Source§

fn eq(&self, other: &NDArray<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl ScalarOps for NDArray<f64>

Source§

fn scalar_subtract(&self, scalar: f64) -> Result<NDArray<f64>, String>

Subtract all values in ndarray by scalar

Source§

fn scalar_add(&self, scalar: f64) -> Result<NDArray<f64>, String>

Add all values in ndarray by scalar

Source§

fn scalar_mult(&self, scalar: f64) -> Result<NDArray<f64>, String>

Multiply all values in ndarray by scalar

Source§

fn scalar_div(&self, scalar: f64) -> Result<NDArray<f64>, String>

Divide all values in ndarray by scalar

Source§

impl<T> Serialize for NDArray<T>
where T: Serialize,

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl UnaryOps for NDArray<f64>

Source§

fn transpose(self) -> Result<NDArray<f64>, String>

Tranpose current NDArray instance, works only on rank 2 values

Source§

fn permute(self, indice_order: Vec<usize>) -> Result<NDArray<f64>, String>

Permute indices of NDArray. Can be used to peform transposes/contraction on rank 3 or higher values.

Source§

fn norm(&self, p: usize) -> Result<NDArray<f64>, String>

L2 norm can also be x^t x

Source§

fn signum(&self) -> Result<NDArray<f64>, String>

Adds values based on x < 0 < 1

Source§

fn sum_axis(&self, axis: usize) -> Result<NDArray<f64>, String>

Sum values along a specified axis

Source§

fn select_axis( &self, axis: usize, indices: Vec<usize>, ) -> Result<NDArray<f64>, String>

Select specific indices from an axis

Source§

fn apply( &self, loss_func: fn(value: f64) -> f64, ) -> Result<NDArray<f64>, String>

Apply loss function on values in ndarray

Source§

fn argmax(&self, axis: usize) -> NDArray<f64>

Get’s the maximum values index along a specified axis

Source§

fn argmin(&self, axis: usize) -> Result<NDArray<f64>, String>

Get’s the minimum values index along a specified axis

Source§

fn nonzero(&self) -> NDArray<f64>

Retrieve all non zero elements in an ndarray

Source§

impl<T> StructuralPartialEq for NDArray<T>

Auto Trait Implementations§

§

impl<T> Freeze for NDArray<T>

§

impl<T> RefUnwindSafe for NDArray<T>
where T: RefUnwindSafe,

§

impl<T> Send for NDArray<T>
where T: Send,

§

impl<T> Sync for NDArray<T>
where T: Sync,

§

impl<T> Unpin for NDArray<T>
where T: Unpin,

§

impl<T> UnwindSafe for NDArray<T>
where T: UnwindSafe,

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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,