nabla_ml::nab_utils

Struct NabUtils

Source
pub struct NabUtils;

Implementations§

Source§

impl NabUtils

Source

pub fn normalize(array: &mut NDArray)

Normalizes the array values to range [0, 1] using min-max normalization

§Arguments
  • array - The NDArray to normalize in-place
§Example
use nabla_ml::nab_array::NDArray;
use nabla_ml::nab_utils::NabUtils;
 
let mut arr = NDArray::from_vec(vec![1.0, 2.0, 3.0, 4.0, 5.0]);
NabUtils::normalize(&mut arr);
assert_eq!(arr.data(), &[0.0, 0.25, 0.5, 0.75, 1.0]);
Source

pub fn normalize_with_range(array: &mut NDArray, min_val: f64, max_val: f64)

Normalizes the array values using specified min and max values

§Arguments
  • array - The NDArray to normalize in-place
  • min_val - The minimum value in the original range
  • max_val - The maximum value in the original range
§Example
use nabla_ml::nab_array::NDArray;
use nabla_ml::nab_utils::NabUtils;
 
let mut arr = NDArray::from_vec(vec![0.0, 51.0, 102.0, 153.0, 204.0, 255.0]);
NabUtils::normalize_with_range(&mut arr, 0.0, 255.0);
assert_eq!(arr.data(), &[0.0, 0.2, 0.4, 0.6, 0.8, 1.0]);
Source

pub fn load_and_split_dataset( path: &str, train_percent: f64, ) -> Result<((NDArray, NDArray), (NDArray, NDArray))>

Loads a dataset from .nab files and splits it into training and testing sets

§Arguments
  • path - Base path for the .nab files (e.g., “mnist”)
  • train_percent - Percentage of data to use for training (e.g., 80 for 80%)
§Returns

A tuple containing ((train_images, train_labels), (test_images, test_labels))

Source

pub fn csv_to_nab( csv_path: &str, output_path: &str, shape: Vec<usize>, skip_first_column: bool, ) -> Result<()>

Converts CSV data to .nab format

§Arguments
  • csv_path - Path to the CSV file
  • output_path - Path where to save the .nab file
  • shape - Shape of the resulting array (e.g., [60000, 28, 28] for MNIST images)
Source

pub fn display(&self, array: &NDArray) -> String

Displays the array in a formatted way similar to numpy’s print format

§Returns

A string representation of the array

Auto Trait Implementations§

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> 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, 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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V