File-Backed Dataset Sources #
Typed NPY and CSV sources for supervised and labeled datasets. This module owns the boundary
between external files and TorchLean tensors; importing Data.SampleStream does not pull
in these parsers.
Require that every path exists, adding hint to a missing-file error when supplied.
Instances For
Require one named data file to exist.
Example:
-- A missing fixture should fail with a sentence the reader can act on.
def checkFixtures : IO Unit :=
Data.requireFile "cifar10_images" "input tensor" "data/cifar_x.npy"
(hint := "run: python3 NN/Examples/Data/generate_small_data.py")
Instances For
Require paired supervised input and target files to exist.
Instances For
Read an .npy row count from its header while checking all trailing dimensions.
For shape (N, d₁, ..., dₖ), this returns N exactly when the trailing shape is tailShape.
The payload is not read; the subsequent full or prefix load checks its required byte range.
Instances For
Validate untrusted flat payload length before crossing into total tensor code.
Tensor.from itself is intentionally total; only external metadata can fail.
Instances For
How a file's physical shape is matched against the requested tensor shape.
- exact : TensorShapeMatch
Require every physical dimension to equal the requested dimension.
- leadingPrefix : TensorShapeMatch
Permit a larger first dimension and read its requested prefix.
Instances For
Instances For
Instances For
Load an arbitrary-rank tensor from a .npy file under an explicit shape-matching policy.
With exact, every dimension must match. With leadingPrefix, rank and trailing dimensions must
still match, while the file may contain more entries on its first axis. Prefix loading requires a
C-order NPY file because the requested values must form one contiguous prefix.
Instances For
File Sources #
The definitions below load tensors by path and expected dimensions, then build supervised or
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 encodings inferred from source-path extensions.
- npy : FileFormat
NumPy
.npy, supporting numeric C-order arrays decoded by TorchLean's NPY reader. - csv : FileFormat
Numeric CSV table. CSV sources are interpreted as 2D tensors
[rows, cols].
Instances For
Instances For
Infer the supported file encoding from a source path.
Instances For
Load a numeric CSV table as a tensor.
Supported shapes:
[rows, cols]: ordinary numeric table,[n]: either one column withnrows or one row withncolumns.
Instances For
Load a Float tensor from a path and expected dimensions.
Instances For
Load a tensor from NPY or numeric CSV.
The expected result type supplies both the scalar type and shape. File metadata is checked before the tensor is returned.
Two files representing supervised data:
inputPathmust contain shape(sampleCount, input...),targetPathmust contain shape(sampleCount, target...).
- sampleCount : ℕ
Number of samples along the leading batch axis.
- input : Shape
Shape of one input sample.
- target : Shape
Shape of one target sample.
- inputPath : System.FilePath
Path to the batched input tensor.
- targetPath : System.FilePath
Path to the batched target tensor.
- csvOptions : CsvOptions
CSV parsing options, ignored for NPY sources.
Instances For
Describe paired input and target tensor files. Encodings are inferred from their extensions.
Example:
-- Shapes are per sample; `sampleCount` says how many leading rows of the files this run uses.
def source : Data.SupervisedSource :=
Data.SupervisedSource.fromFiles
(inputPath := "data/inputs.npy") (targetPath := "data/targets.npy")
(sampleCount := 64) (input := [16]) (target := [1])
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.
Two files representing labeled classification data:
inputPathmust contain shape(sampleCount, input...),labelPathmust contain shape(sampleCount,)and integer-valued class labels.
- sampleCount : ℕ
Number of samples along the leading batch axis.
- input : Shape
Shape of one input sample.
- classCount : ℕ
Number of classes for one-hot targets.
- inputPath : System.FilePath
Path to the batched input tensor.
- labelPath : System.FilePath
Path to the label vector.
- csvOptions : CsvOptions
CSV parsing options, ignored for NPY sources.
Instances For
Describe input and class-label tensor files. Encodings are inferred from their extensions.
Instances For
Load a labeled classification dataset by slicing the leading batch axis and one-hot encoding labels.
CSV label vectors may be stored as one column or one row; NPY label vectors have shape [n].
Single-table supervised CSV source.
Use this when one CSV row contains both input and target columns:
x1, ..., x_inputWidth, y1, ..., y_targetWidth.
- path : System.FilePath
CSV file path.
- inputWidth : ℕ
Number of input feature columns.
- targetWidth : ℕ
Number of target columns.
- csvOptions : CsvOptions
CSV parsing options.
Instances For
Describe one CSV table whose rows contain input columns followed by target columns.
Instances For
Load a single-table supervised CSV source.