A Tensor-Language Interface for Constrained Optimization

Back to code generation

Structure

The input consists of up to five blocks:

Parameters and variables:

Objective function (“min” or “max”):

Common subexpressions (“cse”; optional):

Constraints (“st”; optional):

Einsum

The einsum notation expresses tensor aggregations using index strings. We use the symbol # to denote the beginning of an einsum expression, and the overall pattern is:

The table below shows how to convert common operations from linear algebra into einsum notation. Note, however, that einsum allows more than two operands as well as operands with more than two indices.

OperationLinear algebraEinsum
Elementwise product
Inner product
Outer product
Matrix transpose
Matrix diagonaldiag
Diagonal matrixdiag
Matrix product

Apart from the availability of duplicate indices in the result index string, our use of einsum is equivalent to that of existing frameworks. See numpy.einsum for more information.

Elementwise functions

The following unary and binary functions are applied elementwise to the operand tensor(s):

Non-elementwise functions

The following non-elementwise functions from linear algebra are also available:

Constant symbols

Constants are fixed (i.e. non-input) tensors. Two kinds of constants are permitted:

Shorthand notations

The following shorthands are internally mapped back to other functions.