pub struct TensorDataset { /* private fields */ }Expand description
A map-style dataset backed by tensors with a shared first dimension.
Indexed samples are ordinary LibTorch row views and therefore share
storage with the tensors supplied to TensorDataset::new.
Implementations§
Source§impl TensorDataset
impl TensorDataset
Sourcepub fn new(tensors: Vec<Tensor>) -> Result<Self>
pub fn new(tensors: Vec<Tensor>) -> Result<Self>
Creates a tensor dataset whose tensors have the same non-scalar first dimension.
§Errors
Returns RustTorchError::InvalidConfiguration for no tensors and
RustTorchError::InvalidDimensions for a scalar tensor or mismatched
first dimensions.
Sourcepub fn into_replay_safe(self) -> Result<ReplaySafeTensorDataset>
pub fn into_replay_safe(self) -> Result<ReplaySafeTensorDataset>
Deep-copies the backing tensors for exact replay-safe loading.
The returned dataset also deep-copies every fetched row, so callers cannot mutate its private backing storage through a sample view.
§Errors
Returns the preserved LibTorch backend error when allocation or copy fails.
Trait Implementations§
Source§impl Dataset for TensorDataset
impl Dataset for TensorDataset
Source§type Error = RustTorchError
type Error = RustTorchError
An error returned while loading a sample.
Source§fn get_batch(&self, indices: &[usize]) -> Result<Vec<Self::Sample>, Self::Error>
fn get_batch(&self, indices: &[usize]) -> Result<Vec<Self::Sample>, Self::Error>
Loads samples for one index batch. Read more
Source§fn get_batch_with_context(
&self,
indices: &[usize],
context: &WorkerContext,
) -> Result<Vec<Self::Sample>, Self::Error>
fn get_batch_with_context( &self, indices: &[usize], context: &WorkerContext, ) -> Result<Vec<Self::Sample>, Self::Error>
Loads one index batch with cooperative worker lifecycle context. Read more
Auto Trait Implementations§
impl !Sync for TensorDataset
impl Forget for TensorDataset
impl Freeze for TensorDataset
impl RefUnwindSafe for TensorDataset
impl Send for TensorDataset
impl Unpin for TensorDataset
impl UnsafeUnpin for TensorDataset
impl UnwindSafe for TensorDataset
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
Mutably borrows from an owned value. Read more