Functions

This section of the tutorial describes the functions that can be applied to CVXPY expressions. CVXPY uses the function information in this section and the DCP rules to mark expressions with a sign and curvature.

Operators

The infix operators +, -, *, / are treated as functions. + and - are certainly affine functions. * and / are affine in CVXPY because expr1*expr2 is allowed only when one of the expressions is constant and expr1/expr2 is allowed only when expr2 is a scalar constant.

Indexing and Slicing

All non-scalar expressions can be indexed using the syntax expr[i, j]. Indexing is an affine function. The syntax expr[i] can be used as a shorthand for expr[i, 0] when expr is a column vector. Similarly, expr[i] is shorthand for expr[0, i] when expr is a row vector.

Non-scalar Expressions can also be sliced into using the standard Python slicing syntax. For example, expr[i:j:k, r] selects every kth element in column r of expr, starting at row i and ending at row j-1.

Iteration

Expressions are iterable. Iterating over an expression returns indices into the expression in column-major order. If expr is a 2 by 2 matrix, [elem for elem in expr] evaluates to [expr[0, 0], expr[1, 0], expr[0, 1], expr[1, 1]]. The built-in Python sum can be used on expressions because of the support for iteration.

Transpose

The transpose of any expression can be obtained using the syntax expr.T. Transpose is an affine function.

Scalar Functions

These functions resolve to a scalar value.

Elementwise Functions

These functions operate on each element of their argument.

Vector Functions