Module dimensions

Module dimensions 

Source
Expand description

Utilities to manipulate Dimensions.

Contains a number of utility functions for manipulating the dimensions of tensors.

§Terminology

Tensors in Easy ML have a shape of type [(Dimension, usize); D], where D is a compile time constant. This type defines a list of dimension names and the lengths along each dimension name. A tensor with some shape will have data ranging from 0 to the length - 1 along each dimension name. Often we want to call methods which only take dimension names in some order, so those dimension names have a type of [Dimension; D]. We also may want to index into a Tensor, which is done by providing the indexes only, with a type of [usize; D].

Dimensions and dimension names in Easy ML APIs are treated like lists, the order of each dimension does make a difference for equality definitions, mathematical operations, and can be a factor for the order of iteration and indexing. However, many high level APIs that are not directly involved with order or indexing require only a dimension name and these are usually less concerned with the order of the dimensions.

Functions§

contains
Checks if the dimension name is in the shape.
elements
Returns the product of the dimension lengths in the provided shape.
is_square
Returns true if the dimensions are all the same length. For 0 or 1 dimensions trivially returns true. For 2 dimensions, this corresponds to a square matrix, and for 3 dimensions, a cube shaped tensor, and so on.
last_index_of
Returns the last index of the dimension name provided, if one is present in the shape.
length_of
Returns the length of the dimension name provided, if one is present in the shape.
names_of
Returns just the dimension names of the shape, in the same order.
position_of
Finds the position of the dimension name in the shape.