Dataset Sources #
Typed NPY and CSV sources for supervised and labeled datasets.
Load an N-D tensor from a .npy file, checking the on-disk shape matches dims.
Instances For
Load an N-D tensor from a .npy file, allowing the file to contain more rows on the leading axis.
This is the dataset-loader analogue of taking tensor[:n] in PyTorch. The rank and trailing
dimensions must still match exactly; only the leading dimension may be larger than requested.
We use this for dataset sources rather than the stricter readNpyTensor because an exported
dataset usually has a fixed full size, while local runs often request a bounded prefix. For example,
a CIFAR file may have shape (50000, 3, 32, 32) while an example command asks for n = 80; the
resulting TorchLean tensor has type-level shape
(80, 3, 32, 32).
This is still a checked loader, not an implicit reshape:
- rank must agree;
- all trailing dimensions must agree;
- the file must contain at least the requested number of rows;
- only C-order NPY files can be prefix-loaded efficiently by the low-level parser.
Instances For
Labeled dataset from a batched tensor X : (n, σ) and a label vector y : (n,).
Labels are stored as floats (common when exporting from NumPy); we validate each label is an
integer in [0, classes), then one-hot encode it.
Instances For
Load a supervised dataset from a CSV with inDim + outDim columns per row:
x1, ..., x_inDim, y1, ..., y_outDim.
Instances For
File Sources #
The definitions below describe tensors by path, format, and expected dimensions:
- describe each tensor as a
TensorSource; - load it as a typed TorchLean tensor;
- build supervised/labeled datasets by slicing the leading batch axis, just like PyTorch
TensorDataset.
Policy for external ecosystems:
- NumPy
.npyis the canonical interchange format for numeric tensors. - CSV is supported for small tabular data.
- MATLAB
.mat, PyTorch checkpoints, HDF5, Parquet, and image archives should be converted by a small preparation script into.npytensors plus metadata. The Lean runtime loader intentionally handles a small deterministic interchange format rather than every external binary format.
File formats supported directly by the Lean side unified data-source loader.
- npy : TensorFormat
NumPy
.npy, supporting the subset decoded byreadNpyTensor. - csv : TensorFormat
Numeric CSV table. CSV sources are interpreted as 2D tensors
[rows, cols].
Instances For
Human-facing extension used by messages and examples.
Instances For
Description of one tensor stored on disk.
dims is the expected tensor shape. NPY can load any rank supported by ofList; CSV is treated
as a numeric table and therefore expects dims = [rows, cols].
- path : System.FilePath
Path to the file.
Expected dimensions.
- format : TensorFormat
Direct Lean side format. External formats should be preconverted to
.npy. - csvOptions : CsvOptions
Instances For
Load a numeric CSV table as a tensor.
Supported shapes:
Instances For
Load a Float tensor from a path/format/dimension tuple.
Instances For
Load a Float tensor, allowing NPY files to contain more rows than requested on the leading axis.
TensorSource.loadFloatAs is exact: the file shape must equal dims. This prefix variant is for
dataset-style sources where dims starts with the number of rows requested by the current run. CSV
sources remain exact because CSV has no binary prefix contract; NPY sources use
readNpyTensorPrefix.
Instances For
Load a TensorSource as a Float tensor with the statically reflected shapeOfDims src.dims.
Instances For
Two tensor sources representing supervised data:
- n : ℕ
Number of samples along the leading batch axis.
Per-sample input dimensions.
Per-sample target dimensions.
- x : TensorSource
Source for the batched input tensor.
- y : TensorSource
Source for the batched target tensor.
Instances For
Construct a supervised source from paths using the same file format for x and y.
Instances For
Load a supervised dataset by slicing the leading batch axis from the two tensors.
This is the preferred public loader for regression/operator-learning examples, regardless of
whether the backing files are .npy or small numeric CSV tables.
Instances For
Paired .npy source for supervised regression or operator-learning datasets.
Instances For
Load paired .npy files as concrete Float supervised samples.
This is useful for reporting, custom evaluation loops, and native kernels that need concrete
Float tensors outside the high-level trainer API.
Instances For
Two tensor sources representing labeled classification data:
- n : ℕ
Number of samples along the leading batch axis.
Per-sample input dimensions.
- classes : ℕ
Number of classes for one-hot targets.
- x : TensorSource
Source for the batched input tensor.
- y : TensorSource
Source for the label vector.
Instances For
Construct a labeled source from paths using the same file format for x and y.
Instances For
Load a labeled classification dataset by slicing the leading batch axis and one-hot encoding labels.
For CSV label vectors, store labels as a single-column table with dims = [n, 1] and use a custom
TensorSource if needed; the path constructor above is aimed at .npy label vectors.
Instances For
Single-table supervised CSV source.
Use this when one CSV row contains both input and target columns:
x1, ..., x_inDim, y1, ..., y_outDim.
- path : System.FilePath
CSV file path.
- inDim : ℕ
Number of input feature columns.
- outDim : ℕ
Number of target columns.
- csvOptions : CsvOptions
CSV parsing options.
Instances For
Load a single-table supervised CSV source.