Tools
Merge two dictionaries
Multiply two dictionaries
- PEPit.tools.dict_operations.multiply_dicts(dict1, dict2)[source]
Multiply 2 dictionaries in the sense of developing a product of 2 sums.
- Parameters:
dict1 (dict) – any dictionary
dict2 (dict) – any dictionary
- Returns:
(dict) – the keys are the couple of keys of dict1 and dict2 and the values the product of values of dict1 and dict2.
Prune a dictionary
Symmetrize a dictionary
- PEPit.tools.dict_operations.symmetrize_dict(my_dict)[source]
Symmetrize the keys of a dictionary. Each entry which key is a tuple is replaced by two entries:
one with the same key and half the original value,
the other one with reversed key and half the original value as well.
- Parameters:
my_dict (dict) – any dictionary
- Returns:
(dict) – the keys are the ones of my_dict and the reversed tuples for the tuple ones. the values are half the original ones for entries with symmetries tuples keys, and the original ones for the others.
Expression to matrices
- PEPit.tools.expressions_to_matrices.expression_to_matrices(expression)[source]
Translate an expression from an
Expression
to a matrix, a vector, and a constant such that..math:: mathrm{Tr}(text{Gweights},G) + text{Fweights}^T F + text{cons}
corresponds to the expression.
- Parameters:
expression (Expression) – any expression.
- Returns:
Gweights (numpy array) – weights of the entries of G in the
Expression
.Fweights (numpy array) – weights of the entries of F in the
Expression
cons (float) – constant term in the
Expression
Expression to sparse matrices
- PEPit.tools.expressions_to_matrices.expression_to_sparse_matrices(expression)[source]
Translate an expression from an
Expression
to a matrix, a vector, and a constant such that..math:: mathrm{Tr}(text{Gweights},G) + text{Fweights}^T F + text{cons}
where \(\text{Gweights}\) and \(\text{Fweights}\) are expressed in sparse formats.
- Parameters:
expression (Expression) – any expression.
- Returns:
Gweights_indi (numpy array) – Set of line indices for the sparse representation of the constraint matrix (multiplying G).
Gweights_indj (numpy array) – Set of column indices for the sparse representation of the constraint matrix (multiplying G).
Gweights_val (numpy array) – Set of values for the sparse representation of the constraint matrix (multiplying G).
Fweights_ind (numpy array) – Set of indices for the sparse representation of the constraint vector (multiplying F).
Fweights_val (numpy array) – Set of values of the sparse representation of the constraint vector (multiplying F).
cons_val (float) – Constant part of the constraint.