yaocptool.util package

Submodules

yaocptool.util.util module

blockdiag(*matrices_list)[source]

Receives a list of matrices and return a block diagonal.

Parameters:matrices_list (DM|MX|SX) – list of matrices
convert_expr_from_tau_to_time(expr, t_sym, tau_sym, t_k, t_kp1)[source]
Parameters:
  • expr
  • t_sym
  • tau_sym
  • t_k
  • t_kp1
Returns:

create_constant_theta(constant, dimension, finite_elements)[source]
Create constant theta

The created theta will be a dictionary with keys = range(finite_element) and each value will be a vector with value ‘constant’ and number of rows ‘dimension’

Parameters:
  • constant (float|int|DM) – value of each theta entry .
  • dimension (int) – number of rows of the vector of each theta entry.
  • finite_elements (int) – number of theta entries.
Returns:

constant theta

Return type:

dict

create_polynomial_approximation(tau, size, degree, name='var_appr', point_at_zero=False)[source]
Create a polynomial function.
Parameters:
  • tau (casadi.SX) –
  • size (int) – size of the approximated variable (number of rows)
  • degree (int) – approximation degree
  • name (list|str) – name for created parameters
  • point_at_zero (bool) – if the polynomial has an collocation point at tau=0
Returns:

(pol, par), returns the polynomial and a vector of parameters

Return type:

tuple

expm(a_matrix)[source]

Since casadi does not have native support for matrix exponential, this is a trick to computing it. It can be quite expensive, specially for large matrices. THIS ONLY SUPPORT NUMERIC MATRICES AND MX VARIABLES, DOES NOT SUPPORT SX SYMBOLIC VARIABLES.

Parameters:a_matrix (DM) – matrix
Returns:
find_variables_in_vector_by_name(names, vector, exact=False)[source]
Parameters:
  • of str names (str|list) – variable names
  • vector (casadi.SX|casadi.MX) –
  • exact (bool) – default: False. If true it will use an exact match otherwise it will use an regex match
Returns:

list of variables found.

Return type:

list

find_variables_indices_in_vector(var, vector, depth=0)[source]
Given symbolic variables return the indices of the variables in a vector
Parameters:
  • var (casadi.SX|casadi.MX) –
  • vector (casadi.SX|casadi.MX) –
  • depth (int) – depth for which is_equal will check for equality
Returns:

list of indices

Return type:

list

is_equality(expr)[source]

Return true if an expression is an equality (e.g.: x == 2)

Only supports MX expr.

Parameters:expr (MX) – symbolic expression
Returns:True if ‘expr’ is an inequality, False otherwise
Return type:bool
is_inequality(expr)[source]
Return true if an expression is an inequality (e.g.: x < 1, x <= 2)

Only supports MX expr.

Parameters:expr (MX) – symbolic expression
Returns:True if ‘expr’ is an inequality, False otherwise
Return type:bool
join_thetas(*args)[source]
Join the passed ‘thetas’

Receives a list of dicts. The dicts are required to have the same keys, with the exception of empty dicts or None, those will be skipped. For each key, the values will be concatenated and put in the return dictionary.

Parameters:args (dict|None) – thetas to be joined
Returns:return a single dictionary containing the information of the input dict
Return type:dict
remove_variables_from_vector(var, vector)[source]
Returns a vector with items removed
Parameters:
  • var – items to be removed
  • vector – vector which will have items removed
Returns:

remove_variables_from_vector_by_indices(indices, vector)[source]
Returns a vector with items removed
Parameters:
  • indices (list) – list of indices for which the variables need to be removed.
  • vector (SX|MX|DM) – vector which will have items removed
Returns:

the vector with the variables removed

Return type:

SX|MX|DM

Module contents