Struct SelectionDataset
pub struct SelectionDataset<D, I>{
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>
impl<D, I> SelectionDataset<D, I>
pub fn from_indices_checked<S>(
dataset: S,
indices: Vec<usize>,
) -> SelectionDataset<D, I>
pub fn from_indices_checked<S>( dataset: S, indices: Vec<usize>, ) -> SelectionDataset<D, I>
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>
pub fn from_indices_unchecked<S>( dataset: S, indices: Vec<usize>, ) -> SelectionDataset<D, I>
pub fn new_select_all<S>(dataset: S) -> SelectionDataset<D, I>
pub fn new_select_all<S>(dataset: S) -> SelectionDataset<D, I>
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>
pub fn new_shuffled<S, R>(dataset: S, rng_source: R) -> SelectionDataset<D, I>
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)
pub fn shuffle<R>(&mut self, rng_source: R)
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>
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>>
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>
impl<D, I> Clone for SelectionDataset<D, I>
§fn clone(&self) -> SelectionDataset<D, I>
fn clone(&self) -> SelectionDataset<D, I>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more§impl<D, I> Dataset<I> for SelectionDataset<D, I>
impl<D, I> Dataset<I> for SelectionDataset<D, I>
Auto Trait Implementations§
impl<D, I> Freeze for SelectionDataset<D, I>
impl<D, I> RefUnwindSafe for SelectionDataset<D, I>where
I: RefUnwindSafe,
D: RefUnwindSafe,
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>where
D: RefUnwindSafe,
I: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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
impl<T> Pointable for T
§impl<I, T> Windows<I> for Twhere
T: Dataset<I>,
impl<I, T> Windows<I> for Twhere
T: Dataset<I>,
§fn windows(&self, size: usize) -> WindowsIterator<'_, 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
}