pub struct SelectionDataset<D, I>{
pub wrapped: Arc<D>,
pub indices: Vec<usize>,
/* private fields */
}std and dataset only.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§
Source§impl<D, I> SelectionDataset<D, I>
impl<D, I> SelectionDataset<D, I>
Sourcepub 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.
Sourcepub 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>
Sourcepub 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.
Sourcepub 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.
Sourcepub 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.
Sourcepub 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).
Sourcepub 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§
Source§impl<D, I> Clone for SelectionDataset<D, I>
impl<D, I> Clone for SelectionDataset<D, I>
Source§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 moreSource§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<I, T> Windows<I> for Twhere
T: Dataset<I>,
impl<I, T> Windows<I> for Twhere
T: Dataset<I>,
Source§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
}