Struct SelectionDataset

pub struct SelectionDataset<D, I>
where D: Dataset<I>, I: Clone + Send + Sync,
{ pub wrapped: Arc<D>, pub indices: Vec<usize>, /* private fields */ }
Expand description

A dataset that selects a subset of indices from an existing dataset.

Indices may appear multiple times, but they must be within the bounds of the original dataset.

Fields§

§wrapped: Arc<D>

The wrapped dataset from which to select indices.

§indices: Vec<usize>

The indices to select from the wrapped dataset.

Implementations§

§

impl<D, I> SelectionDataset<D, I>
where D: Dataset<I>, I: Clone + Send + Sync,

pub fn from_indices_checked<S>( dataset: S, indices: Vec<usize>, ) -> SelectionDataset<D, I>
where S: Into<Arc<D>>,

Creates a new selection dataset with the given dataset and indices.

Checks that all indices are within the bounds of the dataset.

§Arguments
  • dataset - The original dataset to select from.
  • indices - A slice of indices to select from the dataset. These indices must be within the bounds of the dataset.
§Panics

Panics if any index is out of bounds for the dataset.

pub fn from_indices_unchecked<S>( dataset: S, indices: Vec<usize>, ) -> SelectionDataset<D, I>
where S: Into<Arc<D>>,

Creates a new selection dataset with the given dataset and indices without checking bounds.

§Arguments
  • dataset - The original dataset to select from.
  • indices - A vector of indices to select from the dataset.
§Safety

This function does not check if the indices are within the bounds of the dataset.

pub fn new_select_all<S>(dataset: S) -> SelectionDataset<D, I>
where S: Into<Arc<D>>,

Creates a new selection dataset that selects all indices from the dataset.

This allocates a 1-to-1 mapping of indices to the dataset size, essentially functioning as a no-op selection. This is only useful when the dataset will later be shuffled or transformed in place.

§Arguments
  • dataset - The original dataset to select from.
§Returns

A new SelectionDataset that selects all indices from the dataset.

pub fn new_shuffled<S, R>(dataset: S, rng_source: R) -> SelectionDataset<D, I>
where S: Into<Arc<D>>, R: Into<RngSource>,

Creates a new selection dataset with shuffled indices.

Selects every index of the dataset and shuffles them with randomness from the provided random number generator.

§Arguments
  • dataset - The original dataset to select from.
  • rng - A mutable reference to a random number generator.
§Returns

A new SelectionDataset with shuffled indices.

pub fn shuffle<R>(&mut self, rng_source: R)
where R: Into<RngSource>,

Shuffles the indices of the dataset using a mutable random number generator.

This method modifies the dataset in place, shuffling the indices.

§Arguments
  • rng - A mutable reference to a random number generator.

pub fn slice(&self, start: usize, end: usize) -> SelectionDataset<D, I>

Creates a new dataset that is a slice of the current selection dataset.

Slices the selection indices from [start..end].

Independent of future shuffles on the parent, but shares the same wrapped dataset.

§Arguments
  • start - The start of the range.
  • end - The end of the range (exclusive).

pub fn split(&self, num: usize) -> Vec<SelectionDataset<D, I>>

Split into num datasets by slicing the selection indices evenly.

Split is done via slice, so the datasets share the same wrapped dataset.

Independent of future shuffles on the parent, but shares the same wrapped dataset.

§Arguments
  • num - The number of datasets to split into.
§Returns

A vector of SelectionDataset instances, each containing a subset of the indices.

Trait Implementations§

§

impl<D, I> Clone for SelectionDataset<D, I>
where D: Clone + Dataset<I>, I: Clone + Send + Sync,

§

fn clone(&self) -> SelectionDataset<D, I>

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
§

impl<D, I> Dataset<I> for SelectionDataset<D, I>
where D: Dataset<I>, I: Clone + Send + Sync,

§

fn get(&self, index: usize) -> Option<I>

Gets the item at the given index.
§

fn len(&self) -> usize

Gets the number of items in the dataset.
§

fn is_empty(&self) -> bool

Checks if the dataset is empty.
§

fn iter(&self) -> DatasetIterator<'_, I>
where Self: Sized,

Returns an iterator over the dataset.

Auto Trait Implementations§

§

impl<D, I> Freeze for SelectionDataset<D, I>

§

impl<D, I> RefUnwindSafe for SelectionDataset<D, I>

§

impl<D, I> Send for SelectionDataset<D, I>

§

impl<D, I> Sync for SelectionDataset<D, I>

§

impl<D, I> Unpin for SelectionDataset<D, I>
where I: Unpin,

§

impl<D, I> UnwindSafe for SelectionDataset<D, I>

Blanket Implementations§

§

impl<T> Adaptor<()> for T

§

fn adapt(&self)

Adapt the type to be passed to a metric.
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
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.
§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<I, T> Window<I> for T
where T: Dataset<I> + ?Sized,

§

fn window(&self, current: usize, size: NonZero<usize>) -> Option<Vec<I>>

Creates a window of a collection. Read more
§

impl<I, T> Windows<I> for T
where T: Dataset<I>,

§

fn windows(&self, size: usize) -> WindowsIterator<'_, I>

Is empty if the Dataset is shorter than size.

§Panics

Panics if size is 0.

§Examples
use crate::burn_dataset::{
   transform::{Windows, WindowsDataset},
   Dataset, InMemDataset,
};

let items = [1, 2, 3, 4].to_vec();
let dataset = InMemDataset::new(items.clone());

for window in dataset.windows(2) {
 // do sth with window
}
§

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

§

impl<T> WasmNotSendSync for T
where T: WasmNotSend + WasmNotSync,

§

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