Dataset

Struct Dataset 

Source
pub struct Dataset<const COLS: usize, Data: Datapoint<COLS>> { /* private fields */ }
Expand description

A dataset is a collection of datapoints (for more information on this see the Datapoint trait).

They can be constructed in a multitude of ways. Two common ways are:

From a set of datapoints:

use delfi::Dataset;

let dp1 = [0, 2];
let dp2 = [1, 3];
let dp3 = [2, 5];
let dp4 = [3, 8];
let ds = Dataset::from_datapoints([dp1, dp2, dp3, dp4]);

From columns of data:

use delfi::Dataset;

let t = [0, 1, 2, 3];
let x = [2, 3, 5, 8];
let ds = Dataset::from_columns([t, x]);

One can also add labels in a multitude of ways, the simplest being whilst constructing the dataset:

use delfi::Dataset;

let t = [0, 1, 2, 3, 4, 5];
let x = [2, 3, 5, 8, 12, 17];
let ds = Dataset::from_columns([t, x]).with_labels(["time", "length"]);

This is equivalent to using the dataset-macro:

use delfi::dataset;

let t = [0, 1, 2, 3, 4, 5];
let x = [2, 3, 5, 8, 12, 17];
let ds = dataset!{
    "time" => t,
    "length" => x,
};

Implementations§

Source§

impl<const COLS: usize, Data: Datapoint<COLS>> Dataset<COLS, Data>

Source

pub fn new() -> Self

Function for creating new (empty) dataset

Source

pub fn push(&mut self, datapoint: Data)

Push a new row to the dataset

Source

pub fn n_rows(&self) -> usize

Get current number of rows in dataset, which is equal to the number of datapoints, plus 1 if there is a header row

Source

pub fn n_datapoints(&self) -> usize

Get current number of rows in dataset, which is equal to the number of datapoints, plus 1 if there is a header row

Source

pub fn n_columns(&self) -> usize

Get current number of rows in dataset

Source

pub fn get_labels(&self) -> Option<&[String; COLS]>

Get current labels

Source

pub fn set_labels<'a, Labels>(&mut self, labels: Labels)
where Labels: Into<Option<[&'a str; COLS]>>,

Set labels for the given dataset. Constructors return dataset with labels set to None unless otherwise specified.

use delfi::Dataset;

let t = [0, 1, 2, 3, 4, 5];
let x = [2, 3, 5, 8, 12, 17];
let mut dataset = Dataset::from_columns([t, x]);
dataset.set_labels(["time", "length"]);

Labels can also be turned off

dataset.set_labels(None);

They also technically accept labels to be passed via Some(_) (but why would you?):

dataset.set_labels(Some(["time", "length"]));
Source

pub fn with_labels<'a, Labels>(self, labels: Labels) -> Self
where Labels: Into<Option<[&'a str; COLS]>>,

Take dataset, set labels, and return dataset. Useful when constructing datasets.

use delfi::Dataset;

let t = [0, 1, 2, 3, 4, 5];
let x = [2, 3, 5, 8, 12, 17];
let _ = Dataset::from_columns([&t, &x]).with_labels(["time", "length"]);

See set_labels() for detail on possible parameters.

Source

pub fn from_datapoints<IntoIter, Iter>(rows: IntoIter) -> Self
where IntoIter: IntoIterator<Item = Data, IntoIter = Iter>, Iter: Iterator<Item = Data>, Data: Datapoint<COLS>,

Create a dataset from an iterator over datapoints

Source§

impl<const COLS: usize, DataElement: ToString> Dataset<COLS, [DataElement; COLS]>

Source

pub fn from_columns<IntoIter, Iter>(columns: [IntoIter; COLS]) -> Self
where IntoIter: IntoIterator<Item = DataElement, IntoIter = Iter>, Iter: Iterator<Item = DataElement>,

Takes in a set of columns and creates a dataset from these.

§Examples
use delfi::Dataset;

let t = [0, 1, 2, 3, 4, 5];
let x = [2, 3, 5, 8, 12, 17];
let _ = Dataset::from_columns([t, x]);
Source§

impl<const COLS: usize, Data: Datapoint<COLS>> Dataset<COLS, Data>

Source

pub fn save<P: AsRef<Path>>(self, filepath: P) -> Result<(), Error>

Saves a dataset to a given file. The filepath must be valid. Accepts anything path-like.

§Examples
dataset.save("./resources/data/examples/save-short.csv").unwrap();
let directory = std::fs::canonicalize("./resources/data/examples/").unwrap();
let filepath = directory.join("save-long.csv");
dataset.save(&filepath).unwrap();

Trait Implementations§

Source§

impl<const COLS: usize, Data: Clone + Datapoint<COLS>> Clone for Dataset<COLS, Data>

Source§

fn clone(&self) -> Dataset<COLS, Data>

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<const COLS: usize, Data: Debug + Datapoint<COLS>> Debug for Dataset<COLS, Data>

Source§

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

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

impl<const COLS: usize, Data: Datapoint<COLS>> Default for Dataset<COLS, Data>

Default is equivalent to new

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<const COLS: usize, Data> Freeze for Dataset<COLS, Data>

§

impl<const COLS: usize, Data> RefUnwindSafe for Dataset<COLS, Data>
where Data: RefUnwindSafe,

§

impl<const COLS: usize, Data> Send for Dataset<COLS, Data>
where Data: Send,

§

impl<const COLS: usize, Data> Sync for Dataset<COLS, Data>
where Data: Sync,

§

impl<const COLS: usize, Data> Unpin for Dataset<COLS, Data>
where Data: Unpin,

§

impl<const COLS: usize, Data> UnwindSafe for Dataset<COLS, Data>
where Data: 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.