mlkernels.util module

mlkernels.util.expand[source]

Expand a sequence to the same element repeated twice if there is only one element.

Parameters

xs (tuple or list) – Sequence to expand.

Returns

xs * 2 or xs.

Return type

tuple or list

mlkernels.util.num_elements[source]

Determine the number of elements in an input.

Deals with scalars, vectors, matrices, and batches of matrices.

Parameters

x (tensor) – Input.

Returns

Number of elements.

Return type

int

mlkernels.util.uprank[source]

Ensure that the rank of x is 2.

Parameters

x (tensor) – Tensor to ensure the rank of.

Returns

x with rank at least 2.

Return type

tensor