cunumeric.einsum#

cunumeric.einsum(expr: str, *operands: ndarray, out: ndarray | None = None, dtype: np.dtype[Any] | None = None, casting: CastingKind = 'safe', optimize: bool | Literal['greedy', 'optimal'] = True) ndarray#

Evaluates the Einstein summation convention on the operands.

Using the Einstein summation convention, many common multi-dimensional, linear algebraic array operations can be represented in a simple fashion. In implicit mode einsum computes these values.

In explicit mode, einsum provides further flexibility to compute other array operations that might not be considered classical Einstein summation operations, by disabling, or forcing summation over specified subscript labels.

Parameters:
  • subscripts (str) – Specifies the subscripts for summation as comma separated list of subscript labels. An implicit (classical Einstein summation) calculation is performed unless the explicit indicator ‘->’ is included as well as subscript labels of the precise output form.

  • operands (list[array_like]) – These are the arrays for the operation.

  • out (ndarray, optional) – If provided, the calculation is done into this array.

  • dtype (data-type, optional) – If provided, forces the calculation to use the data type specified. Note that you may have to also give a more liberal casting parameter to allow the conversions. Default is None.

  • casting ({'no', 'equiv', 'safe', 'same_kind', 'unsafe'}, optional) –

    Controls what kind of data casting may occur.

    • ’no’ means the data types should not be cast at all.

    • ’equiv’ means only byte-order changes are allowed.

    • ’safe’ means only casts which can preserve values are allowed.

    • ’same_kind’ means only safe casts or casts within a kind, like float64 to float32, are allowed.

    • ’unsafe’ means any data conversions may be done.

    Default is ‘safe’.

  • optimize ({False, True, 'greedy', 'optimal'}, optional) – Controls if intermediate optimization should occur. If False then arrays will be contracted in input order, one at a time. True (the default) will use the ‘greedy’ algorithm. See cunumeric.einsum_path for more information on the available optimization algorithms.

Returns:

output – The calculation based on the Einstein summation convention.

Return type:

ndarray

Notes

For most expressions, only floating-point types are supported.

See also

numpy.einsum

Availability:

Multiple GPUs, Multiple CPUs