data

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 13, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Dataset

type Dataset interface {
	// Len returns the total number of samples.
	Len() int
	// Get returns the input and target tensors for the given index.
	Get(index int) (input, target *tensor.Tensor, err error)
}

Dataset provides random access to individual samples.

type Loader

type Loader struct {
	// contains filtered or unexported fields
}

Loader iterates over a Dataset in batches.

loader := data.NewLoader(ds, data.LoaderConfig{BatchSize: 32, Shuffle: true})
for loader.Next() {
    input, target := loader.Batch()
    // ... training step ...
}
if err := loader.Err(); err != nil { ... }
loader.Reset() // new epoch

func NewLoader

func NewLoader(ds Dataset, cfg LoaderConfig) *Loader

NewLoader creates a Loader for the given dataset and configuration.

func (*Loader) Batch

func (l *Loader) Batch() (input, target *tensor.Tensor)

Batch returns the current batch tensors. Valid only after Next returns true.

func (*Loader) Close

func (l *Loader) Close()

Close stops background workers and releases resources. Safe to call multiple times.

func (*Loader) Err

func (l *Loader) Err() error

Err returns the first error encountered during iteration.

func (*Loader) Next

func (l *Loader) Next() bool

Next advances to the next batch. Returns false when the epoch is exhausted or an error occurred. Check Err() after the loop.

func (*Loader) Reset

func (l *Loader) Reset()

Reset prepares the loader for a new epoch. If Shuffle is enabled, the sample order is randomized.

type LoaderConfig

type LoaderConfig struct {
	BatchSize  int            // samples per batch (required, must be > 0)
	Shuffle    bool           // randomize sample order each epoch
	NumWorkers int            // parallel fetch goroutines (0 = sequential)
	PrefetchN  int            // batches buffered ahead (0 = no prefetch)
	DropLast   bool           // drop incomplete final batch
	Device     *tensor.Device // move batches to this device after stacking (nil = no move)
}

LoaderConfig configures a Loader.

type TensorDataset

type TensorDataset struct {
	// contains filtered or unexported fields
}

TensorDataset wraps pre-loaded input and target tensors. Each sample is a slice along dimension 0.

func NewTensorDataset

func NewTensorDataset(inputs, targets *tensor.Tensor) *TensorDataset

NewTensorDataset creates a dataset from batched tensors. Both tensors must have the same size along dimension 0.

func (*TensorDataset) Get

func (d *TensorDataset) Get(index int) (input, target *tensor.Tensor, err error)

func (*TensorDataset) Len

func (d *TensorDataset) Len() int

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL