pub struct SelectionDataset<D, I>{
pub wrapped: Arc<D>,
pub indices: Vec<usize>,
/* private fields */
}dataset and std 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 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto 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>
impl<D, I> UnsafeUnpin for SelectionDataset<D, I>
impl<D, I> UnwindSafe for SelectionDataset<D, I>
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneExpand for Twhere
T: Clone,
impl<T> CloneExpand for Twhere
T: Clone,
fn __expand_clone_method(&self, _: &Scope) -> T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> TuneInputs for T
impl<T> TuneInputs for T
impl<T> WasmNotSend for Twhere
T: Send,
impl<T> WasmNotSendSync for Twhere
T: WasmNotSend + WasmNotSync,
impl<T> WasmNotSync for Twhere
T: Sync,
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) {
// window is a Result<Vec<I>, DatasetError>
}