diff options
Diffstat (limited to 'sumofsquares/sosexprbase/init/initsosexprbase.py')
-rw-r--r-- | sumofsquares/sosexprbase/init/initsosexprbase.py | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/sumofsquares/sosexprbase/init/initsosexprbase.py b/sumofsquares/sosexprbase/init/initsosexprbase.py new file mode 100644 index 0000000..6b7f299 --- /dev/null +++ b/sumofsquares/sosexprbase/init/initsosexprbase.py @@ -0,0 +1,56 @@ +import polymatrix + +from sumofsquares.sosexprbase.impl import ParamSOSExprBaseImpl, SOSExprBaseImpl +from sumofsquares.sosexprbase.mixins.parametermixin import ParameterMixin + + +def init_sos_expr_base( + expr: polymatrix.Expression, + variables: polymatrix.Expression, + dependence: tuple[ParameterMixin] | None = None, +): + + if not isinstance(expr, polymatrix.Expression): + expr = polymatrix.from_(expr) + + # if variables is None: + # variables = polymatrix.from_(1) + + if dependence is None: + dependence = tuple() + + return SOSExprBaseImpl( + expr=expr, + variables=variables, + dependence=dependence, + ) + + +def init_param_sos_expr_base( + name: str, + variables: polymatrix.Expression, + monom: polymatrix.Expression | None = None, + n_rows: int | None = None, +): + if monom is None: + monom = polymatrix.from_(1) + + if n_rows is None: + n_rows = 1 + + if n_rows is 1: + param = monom.parametrize(f'{name}') + param_matrix = param.T + + else: + params = tuple(monom.parametrize(f'{name}_{row+1}') for row in range(n_rows)) + param = polymatrix.v_stack(params) + param_matrix = polymatrix.v_stack(tuple(param.T for param in params)) + + return ParamSOSExprBaseImpl( + name=name, + param=param, + monom=monom, + variables=variables, + param_matrix=param_matrix, + ) |