package nx
- Overview
- No Docs
You can search for identifiers within the package.
in-package search v0.2.0
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=96d35ce03dfbebd2313657273e24c2e2d20f9e6c7825b8518b69bd1d6ed5870f
sha512=90c5053731d4108f37c19430e45456063e872b04b8a1bbad064c356e1b18e69222de8bfcf4ec14757e71f18164ec6e4630ba770dbcb1291665de5418827d1465
doc/nx.io/Nx_io/index.html
Module Nx_ioSource
Tensor I/O.
Load and save Nx tensors in common formats: images (PNG, JPEG, BMP, TGA), NumPy (.npy, .npz), SafeTensors, and delimited text.
All functions raise Failure on errors.
Packed tensors
Named tensors. Returned by load_npz and load_safetensors.
type packed_dtype = | Dtype : ('a, 'b) Nx.dtype -> packed_dtype(*An existentially packed dtype.
*)
to_typed dtype p is the tensor in p with dtype.
Raises Failure if the packed tensor has a different dtype.
packed_dtype p is the dtype of p.
Images
load_image ?grayscale path loads an image as a uint8 tensor.
grayscale defaults to false. Shape is [h; w] when grayscale is true, [h; w; c] otherwise.
Raises Failure on I/O or decoding errors.
save_image ?overwrite path t writes t to path.
Format is inferred from extension (.png, .jpg, .bmp, .tga). Accepted shapes are [h; w], [h; w; 1], [h; w; 3], and [h; w; 4]. overwrite defaults to true.
Raises Failure on unsupported shape, extension, or I/O errors.
NumPy formats
load_npy path loads a tensor from a .npy file.
Raises Failure on I/O or format errors.
save_npy ?overwrite path t writes t to a .npy file.
overwrite defaults to true.
Raises Failure on I/O errors.
load_npz path loads all tensors from an .npz archive.
Raises Failure on I/O or format errors.
load_npz_entry ~name path loads a single entry from an .npz archive.
Raises Failure if name is missing or the archive is invalid.
save_npz ?overwrite path entries writes named tensors to an .npz archive.
overwrite defaults to true.
Raises Failure on I/O errors.
SafeTensors
load_safetensors path loads all tensors from a SafeTensors file.
Raises Failure on I/O or format errors.
save_safetensors ?overwrite path entries writes named tensors to a SafeTensors file.
overwrite defaults to true.
Raises Failure on I/O errors.
Text format
val load_txt :
?sep:string ->
?comments:string ->
?skiprows:int ->
?max_rows:int ->
string ->
('a, 'b) Nx.dtype ->
('a, 'b) Nx.tload_txt ?sep ?comments ?skiprows ?max_rows path dtype parses delimited text into a tensor.
sep defaults to " ". comments defaults to "#". skiprows defaults to 0. The result is 1D or 2D depending on parsed data.
Raises Failure on I/O or parse errors.
val save_txt :
?sep:string ->
?append:bool ->
?newline:string ->
?header:string ->
?footer:string ->
?comments:string ->
string ->
('a, 'b) Nx.t ->
unitsave_txt ?sep ?append ?newline ?header ?footer ?comments path t writes a scalar, vector, or matrix tensor to delimited text.
sep defaults to " ". append defaults to false. newline defaults to "\n". comments defaults to "# ".
Raises Failure on unsupported dtype/shape or I/O errors.