field_einsum

hcipy.field.field_einsum(subscripts, *operands, **kwargs)[source]

Evaluates the Einstein summation convention on the operand fields.

This function uses the same conventions as numpy.einsum(). The input subscript is multiplexed over each position in the grid. The grids of each of the input field operands don’t have to match, but must have the same lengths.

The subscripts must be written as you would for a single position in the grid. The function alters these subscripts to multiplex over the entire grid.

Caution

Some subscripts may yield no exception, even though they would fail for a single point in the grid. The output in these cases can not be trusted.

Parameters:
subscriptsstr

Specifies the subscripts for summation.

operandslist of array_like or Field

These are the arrays or fields for the operation.

out{ndarray, None}, optional

Deprecated. If provided, the calculation is done into this array.

dtype{data-type, None}, optional

Deprecated. If provided, forces the calculation to use the data type specified.

order{‘C’, ‘F’, ‘A’, ‘K’}, optional

Deprecated and ignored. This keyword will be removed in a future version.

casting{‘no’, ‘equiv’, ‘safe’, ‘same_kind’, ‘unsafe’}, optional

Deprecated and ignored. This keyword will be removed in a future version.

optimize{False, True, ‘greedy’, ‘optimal’}, optional

Controls if intermediate optimization should occur. No optimization will occur if False and True will default to the ‘greedy’ algorithm. Also accepts an explicit contraction list from the np.einsum_path function. See np.einsum_path for more details. Default is True.

Returns:
Field

The calculated Field based on the Einstein summation convention.

Raises:
ValueError

If all of the fields don’t have the same grid size. If the number of operands is not equal to the number of subscripts specified.