Skip to main content

DataSource

Trait DataSource 

Source
pub trait DataSource: Send + Sync {
    type Sample: Storage + ?Sized;
    type Error: Error + Display + Send + Sync + 'static;

    // Required methods
    fn next_batch(
        &mut self,
        ctx: &mut RuntimeResourceRef<'_>,
        completion: CompletionHandle<(Box<Self::Sample>, Box<Self::Sample>), Self::Error>,
    ) -> ContractResponse<(Box<Self::Sample>, Box<Self::Sample>), Self::Error>;
    fn reset(
        &mut self,
        ctx: &mut RuntimeResourceRef<'_>,
        completion: CompletionHandle<(), Self::Error>,
    ) -> ContractResponse<(), Self::Error>;
    fn on_data_loaded(
        &mut self,
        ctx: &mut RuntimeResourceRef<'_>,
        completion: CompletionHandle<(), Self::Error>,
    ) -> ContractResponse<(), Self::Error>;
}
Expand description

User-facing Contract trait for a data source / data loader.

Required Associated Types§

Source

type Sample: Storage + ?Sized

Sample storage type. One associated type covers both the batch tensor and the optional labels tensor. Implement as [f32] for flat f32 sample batches.

Source

type Error: Error + Display + Send + Sync + 'static

Library-maker-defined error type.

Required Methods§

Source

fn next_batch( &mut self, ctx: &mut RuntimeResourceRef<'_>, completion: CompletionHandle<(Box<Self::Sample>, Box<Self::Sample>), Self::Error>, ) -> ContractResponse<(Box<Self::Sample>, Box<Self::Sample>), Self::Error>

Fetch the next batch. Returns (batch, labels) as boxed Self::Sample slices; the second slot is zero-length for unsupervised sources.

Source

fn reset( &mut self, ctx: &mut RuntimeResourceRef<'_>, completion: CompletionHandle<(), Self::Error>, ) -> ContractResponse<(), Self::Error>

Reset to the beginning of the data stream.

Source

fn on_data_loaded( &mut self, ctx: &mut RuntimeResourceRef<'_>, completion: CompletionHandle<(), Self::Error>, ) -> ContractResponse<(), Self::Error>

One-shot notification signalling the source’s data has finished loading (e.g. dataset download complete).

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§