TorchLean API

NN.API.Data.Sources

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

      Parse a float-encoded class label as a Nat in [0, classes).

      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:

            1. describe each tensor as a TensorSource;
            2. load it as a typed TorchLean tensor;
            3. build supervised/labeled datasets by slicing the leading batch axis, just like PyTorch TensorDataset.

            Policy for external ecosystems:

            File formats supported directly by the Lean side unified data-source loader.

            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].

                Instances For

                  Load a numeric CSV table as a tensor.

                  Supported shapes:

                  • [rows, cols]: ordinary numeric table,
                  • [n]: either one column with n rows or one row with n columns.
                  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:

                          • x must have shape (n, xDims...),
                          • y must have shape (n, yDims...).
                          • n :

                            Number of samples along the leading batch axis.

                          • xDims : List

                            Per-sample input dimensions.

                          • yDims : List

                            Per-sample target dimensions.

                          • Source for the batched input tensor.

                          • Source for the batched target tensor.

                          Instances For
                            def TorchLean.Data.SupervisedSource.ofPaths (format : TensorFormat) (xPath yPath : System.FilePath) (n : ) (xDims yDims : List ) (csvOptions : CsvOptions := { }) :

                            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:

                                    • x must have shape (n, xDims...),
                                    • y must have shape (n,) and contain integer-valued labels.
                                    • n :

                                      Number of samples along the leading batch axis.

                                    • xDims : List

                                      Per-sample input dimensions.

                                    • classes :

                                      Number of classes for one-hot targets.

                                    • Source for the batched input tensor.

                                    • Source for the label vector.

                                    Instances For
                                      def TorchLean.Data.LabeledSource.ofPaths (format : TensorFormat) (xPath yPath : System.FilePath) (n : ) (xDims : List ) (classes : ) (csvOptions : CsvOptions := { }) :

                                      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.

                                          • CSV file path.

                                          • inDim :

                                            Number of input feature columns.

                                          • outDim :

                                            Number of target columns.

                                          • csvOptions : CsvOptions

                                            CSV parsing options.

                                          Instances For