github ↗
docs menu

Module Nx_array.Move

Movements.

Movements.

A movement maps the indices of a result to the indices of its argument: the result's element at an index is the argument's element at the mapped index. Movements are plain data, so code that records or lowers them shares one vocabulary, and equal movements, by structural equality, have equal maps. Their arrays are immutable, so a movement once built never changes.

#type range = {
  1. #start : int;
  2. #count : int;
  3. #step : int;
}

The type for the elements start + j·step, j < count, of an axis.

#type window = {
  1. #axis : int;
  2. #size : int;
  3. #step : int;
  4. #dilation : int;
}

The type for windows along axis: window w's element j is the axis's element w·step + j·dilation, j < size.

#type t =
  1. #| Reshape of int iarray
    (*

    Reshape s' has shape s' and the argument's elements in the same C order of indices: element k in C order is the argument's element k in C order.

    *)
  2. #| Broadcast of int iarray
    (*

    Broadcast s' has shape s', which has at least the argument's rank. Aligned from the right, each extent of the argument is 1 or s''s; a new axis or an extent-1 one repeats the argument's elements along it.

    *)
  3. #| Permute of int iarray
    (*

    Permute p has, as its axis i, the argument's axis p.(i), or a new axis of one element where p.(i) < 0. Each axis of the argument that p does not list has one element. The map is a bijection of elements, so it is a view: a permutation of the axes, and a squeeze or an unsqueeze that states which axes go and come.

    *)
  4. #| Slice of range iarray
    (*

    Slice rs keeps the elements rs.(i) of each axis i. A negative step reverses the axis.

    *)
  5. #| Window of window iarray
    (*

    Window ws has, for each window of ws, on strictly increasing axes, its axis replaced by the number of windows, (d - 1 - dilation·(size - 1)) / step + 1 of an axis of extent d, or 0 where dilation·(size - 1) + 1 exceeds d, and a trailing axis of extent size appended, in axis order. The result's element at (…, w, …, j) is the argument's element at (…, w·step + j·dilation, …).

    *)

The type for movements.

#val shape : t -> int iarray -> int iarray

shape m s is the shape of the result of m on an argument of shape s.

Raises Invalid_argument if an extent of s is negative, if s or the result has extents other than 0 whose product exceeds Nx_array.Layout.max_numel, if the result has more than Nx_array.Layout.max_rank axes, or unless:

  • Reshape s': s''s extents are non-negative, their product s's.
  • Broadcast s': s''s extents are non-negative; it has at least s's rank, and each extent of s aligned from the right is 1 or s''s.
  • Permute p: p's entries >= 0 are distinct axes of s, every axis of s it does not list has extent 1, and it has at most Nx_array.Layout.max_rank entries.
  • Slice rs: rs has a range per axis, each with step <> 0 and count >= 0; if count > 0, start and start + (count - 1)·step lie in [0, d) for an axis of extent d.
  • Window ws: each window's axis is an axis of s, after the previous window's; size, step and dilation are at least 1.