package nx
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=96d35ce03dfbebd2313657273e24c2e2d20f9e6c7825b8518b69bd1d6ed5870f
sha512=90c5053731d4108f37c19430e45456063e872b04b8a1bbad064c356e1b18e69222de8bfcf4ec14757e71f18164ec6e4630ba770dbcb1291665de5418827d1465
doc/nx.core/Nx_core/Shape/index.html
Module Nx_core.ShapeSource
Concrete shape operations.
Concrete tensor shapes.
A shape is an array of non-negative dimension sizes in row-major order.
The type for concrete shapes.
Basic operations
Strides
c_contiguous_strides shape is the row-major stride vector of shape.
For any zero-size dimension, strides to its left are propagated with zero according to the implementation's canonical rule.
Index conversion
ravel_index indices strides is the linear offset sum_i (indices.(i) * strides.(i)).
Raises Invalid_argument if the array lengths differ.
Note. This function does not perform bounds checks on indices.
unravel_index k shape is the multi-index of k in a C-contiguous layout of shape.
For shape = [||], k must be 0.
For zero-size shapes, only k = 0 is accepted and the result is an array of zeros with the same rank as shape.
Raises Invalid_argument if k is out of bounds for shape.
unravel_index_into k shape dst is like unravel_index but writes indices into dst.
dst must have length Array.length shape.
Raises Invalid_argument if k is out of bounds for shape.
Warning. If dst has the wrong length, array access may raise Invalid_argument via OCaml's bounds checks.
Shape transformations
resolve_neg_one current_shape new_spec resolves a single -1 entry in new_spec using numel current_shape.
Raises Invalid_argument if:
new_speccontains more than one-1.- The inferred size is not integral with the specified dimensions.
- The specification is incompatible with zero-size inference rules.
broadcast a b is the broadcasted shape of a and b using NumPy rules (right alignment; dimensions are compatible iff equal or one is 1).
Raises Invalid_argument if the shapes are not broadcast-compatible.
broadcast_index target_idx source_shape maps a target index to the corresponding index in source_shape under broadcasting.
Dimensions of source_shape equal to 1 map to index 0.
broadcast_index_into target_idx source_shape dst is like broadcast_index but writes into dst.
dst must have length Array.length source_shape.
Formatting
pp formats shapes with the same syntax as to_string.