picos.expressions.exp_affine¶
Implements affine expression types.
Classes
- class picos.expressions.exp_affine.AffineExpression(string, shape=(1, 1), coefficients={})[source]¶
Bases:
ComplexAffineExpression
A multidimensional real affine expression.
- property H¶
The regular transpose of the
AffineExpression
.
- property conj¶
The
AffineExpression
as is.
- property imag[source]¶
A zero of same shape as the
AffineExpression
.
- property isreal¶
Always true for
AffineExpression
instances.
- property real¶
The
AffineExpression
as is.
- class picos.expressions.exp_affine.ComplexAffineExpression(string, shape=(1, 1), coefficients={})[source]¶
Bases:
BiaffineExpression
A multidimensional (complex) affine expression.
Base class for the real
AffineExpression
.- __abs__()[source]¶
Denote the default norm of the expression.
The norm used depends on the expression’s domain. It is
the absolute value of a real scalar,
the modulus of a complex scalar,
the Euclidean norm of a vector, and
the Frobenius norm of a matrix.
- __or__(other)[source]¶
Denote the scalar product with another expression on the right.
For (complex) vectors
and
this is the dot product
For (complex) matrices
and
this is the Frobenius inner product
Note
Write
(A|B)
instead ofA|B
for the scalar product ofA
andB
to obtain correct operator binding within a larger expression context.
- scipy_sparse_matrix_form(varOffsetMap, *, offset=0, padding=0, dense_b=False)[source]¶
Like
sparse_matrix_form
but returns SciPy types.See
sparse_matrix_form
for details and arguments.- Returns tuple(scipy.sparse.csc_matrix)
A pair
(A, b)
of SciPy sparse matrices in CSC format representing the matrixand the column vector
. (If
dense_b=True
, thenb
is returned as a 1-DNumPy array
instead.)- Raises
ModuleNotFoundError – If the optional dependency
scipy
is not installed.
- sparse_matrix_form(varOffsetMap, *, offset=0, padding=0, dense_b=False)[source]¶
Return a representation suited for embedding in constraint matrices.
This computes a sparse matrix
and a sparse column vector
such that
represents the vectorized expression, where
is a vertical concatenation of a number of variables, including those that appear in the expression. The size and ordering of
is given through
varOffsetMap
, which maps PICOS variables to their starting position within.
If the optional parameters
offset
andpadding
are given, then bothand
are padded with zero rows from above and below, respectively.
This method is used by PICOS internally to assemble constraint matrices.
- Parameters
- Returns tuple(cvxopt.spmatrix)
A pair
(A, b)
of CVXOPT sparse matrices representing the matrixand the column vector
. (If
dense_b=True
, thenb
is returned as a dense CVXOPT column vector instead.)
- sparse_rows(varOffsetMap)[source]¶
Yield a sparse list representation of the expression.
This is similar to
sparse_matrix_form
(with default arguments) but instead of returningand
at once, this yields for every row of
, each representing a scalar entry of the expression’s vectorization, a triplet containing a list of column indices and values of that row of
and the entry of
.
- Parameters
varOffsetMap – Maps variables to column offsets.
- Yields tuple(list, list, float)
Triples
(J, V, c)
whereJ
contains column indices (representing scalar variables),V
contains coefficients for each column index, and wherec
is a constant term.
- property imag[source]¶
Override
imag
.The result is returned as an
AffineExpression
.
- property real[source]¶
Override
real
.The result is returned as an
AffineExpression
.
Functions
- picos.expressions.exp_affine.Constant(name_or_value, value=None, shape=None)[source]¶
Create a constant PICOS expression.
Loads the given numeric value as a constant
ComplexAffineExpression
orAffineExpression
, depending on the value. Optionally, the value is broadcasted or reshaped according to the shape argument.- Parameters
See
load_data
for supported data formats and broadcasting and reshaping rules.- Example
>>> from picos import Constant >>> Constant(1) <1×1 Real Constant: 1> >>> Constant(1, shape=(2, 2)) <2×2 Real Constant: [1]> >>> Constant("one", 1) <1×1 Real Constant: one> >>> Constant("J", 1, (2, 2)) <2×2 Real Constant: J>