diff options
Diffstat (limited to 'polymatrix/expression/init')
45 files changed, 0 insertions, 722 deletions
diff --git a/polymatrix/expression/init/__init__.py b/polymatrix/expression/init/__init__.py deleted file mode 100644 index e69de29..0000000 --- a/polymatrix/expression/init/__init__.py +++ /dev/null diff --git a/polymatrix/expression/init/initadditionexpr.py b/polymatrix/expression/init/initadditionexpr.py deleted file mode 100644 index cdc97b1..0000000 --- a/polymatrix/expression/init/initadditionexpr.py +++ /dev/null @@ -1,12 +0,0 @@ -from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin -import polymatrix.expression.impl.impl - - -def init_addition_expr( - left: ExpressionBaseMixin, - right: ExpressionBaseMixin, -): - return polymatrix.expression.impl.impl.AdditionExprImpl( - left=left, - right=right, -) diff --git a/polymatrix/expression/init/initblockdiagexpr.py b/polymatrix/expression/init/initblockdiagexpr.py deleted file mode 100644 index a9ad8a6..0000000 --- a/polymatrix/expression/init/initblockdiagexpr.py +++ /dev/null @@ -1,7 +0,0 @@ -import polymatrix.expression.impl.impl -def init_block_diag_expr( - underlying: tuple, -): - return polymatrix.expression.impl.impl.BlockDiagExprImpl( - underlying=underlying, -) diff --git a/polymatrix/expression/init/initcacheexpr.py b/polymatrix/expression/init/initcacheexpr.py deleted file mode 100644 index 861ffa1..0000000 --- a/polymatrix/expression/init/initcacheexpr.py +++ /dev/null @@ -1,10 +0,0 @@ -from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin -import polymatrix.expression.impl.impl - - -def init_cache_expr( - underlying: ExpressionBaseMixin, -): - return polymatrix.expression.impl.impl.CacheExprImpl( - underlying=underlying, -) diff --git a/polymatrix/expression/init/initcombinationsexpr.py b/polymatrix/expression/init/initcombinationsexpr.py deleted file mode 100644 index 10931e6..0000000 --- a/polymatrix/expression/init/initcombinationsexpr.py +++ /dev/null @@ -1,12 +0,0 @@ -from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin -import polymatrix.expression.impl.impl - - -def init_combinations_expr( - monomials: ExpressionBaseMixin, - number: int, -): - return polymatrix.expression.impl.impl.CombinationsExprImpl( - monomials=monomials, - number=number, -) diff --git a/polymatrix/expression/init/initderivativeexpr.py b/polymatrix/expression/init/initderivativeexpr.py deleted file mode 100644 index b1c9405..0000000 --- a/polymatrix/expression/init/initderivativeexpr.py +++ /dev/null @@ -1,20 +0,0 @@ -from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin -import polymatrix.expression.impl.impl - - -def init_derivative_expr( - underlying: ExpressionBaseMixin, - variables: ExpressionBaseMixin, - introduce_derivatives: bool = None, -): - - assert isinstance(variables, ExpressionBaseMixin), f'{variables=}' - - if introduce_derivatives is None: - introduce_derivatives = False - - return polymatrix.expression.impl.impl.DerivativeExprImpl( - underlying=underlying, - variables=variables, - introduce_derivatives=introduce_derivatives, -) diff --git a/polymatrix/expression/init/initdeterminantexpr.py b/polymatrix/expression/init/initdeterminantexpr.py deleted file mode 100644 index 660f3ae..0000000 --- a/polymatrix/expression/init/initdeterminantexpr.py +++ /dev/null @@ -1,10 +0,0 @@ -from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin -import polymatrix.expression.impl.impl - - -def init_determinant_expr( - underlying: ExpressionBaseMixin, -): - return polymatrix.expression.impl.impl.DeterminantExprImpl( - underlying=underlying, -) diff --git a/polymatrix/expression/init/initdiagexpr.py b/polymatrix/expression/init/initdiagexpr.py deleted file mode 100644 index 794c5bf..0000000 --- a/polymatrix/expression/init/initdiagexpr.py +++ /dev/null @@ -1,10 +0,0 @@ -from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin -import polymatrix.expression.impl.impl - - -def init_diag_expr( - underlying: ExpressionBaseMixin, -): - return polymatrix.expression.impl.impl.DiagExprImpl( - underlying=underlying, -) diff --git a/polymatrix/expression/init/initdivergenceexpr.py b/polymatrix/expression/init/initdivergenceexpr.py deleted file mode 100644 index 6f5d99d..0000000 --- a/polymatrix/expression/init/initdivergenceexpr.py +++ /dev/null @@ -1,13 +0,0 @@ -from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin -from typing import Union -import polymatrix.expression.impl.impl - - -def init_divergence_expr( - underlying: ExpressionBaseMixin, - variables: tuple, -): - return polymatrix.expression.impl.impl.DivergenceExprImpl( - underlying=underlying, - variables=variables, -) diff --git a/polymatrix/expression/init/initdivisionexpr.py b/polymatrix/expression/init/initdivisionexpr.py deleted file mode 100644 index d7870bc..0000000 --- a/polymatrix/expression/init/initdivisionexpr.py +++ /dev/null @@ -1,12 +0,0 @@ -from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin -import polymatrix.expression.impl.impl - - -def init_division_expr( - left: ExpressionBaseMixin, - right: ExpressionBaseMixin, -): - return polymatrix.expression.impl.impl.DivisionExprImpl( - left=left, - right=right, -) diff --git a/polymatrix/expression/init/initelemmultexpr.py b/polymatrix/expression/init/initelemmultexpr.py deleted file mode 100644 index ef66c68..0000000 --- a/polymatrix/expression/init/initelemmultexpr.py +++ /dev/null @@ -1,12 +0,0 @@ -from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin -import polymatrix.expression.impl.impl - - -def init_elem_mult_expr( - left: ExpressionBaseMixin, - right: ExpressionBaseMixin, -): - return polymatrix.expression.impl.impl.ElemMultExprImpl( - left=left, - right=right, -) diff --git a/polymatrix/expression/init/initevalexpr.py b/polymatrix/expression/init/initevalexpr.py deleted file mode 100644 index 29359d6..0000000 --- a/polymatrix/expression/init/initevalexpr.py +++ /dev/null @@ -1,37 +0,0 @@ -import typing -import numpy as np -from polymatrix.expression.init.initsubstituteexpr import format_substitutions -from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin -import polymatrix.expression.impl.impl - - -def init_eval_expr( - underlying: ExpressionBaseMixin, - variables: typing.Union[typing.Any, tuple, dict], - values: typing.Union[float, tuple] = None, -): - - substitutions = format_substitutions( - variables=variables, - values=values, - ) - - def formatted_values(value): - if isinstance(value, np.ndarray): - return tuple(value.reshape(-1)) - - elif isinstance(value, tuple): - return value - - elif isinstance(value, int) or isinstance(value, float): - return (value,) - - else: - return (float(value),) - - substitutions = tuple((variable, formatted_values(value)) for variable, value in substitutions) - - return polymatrix.expression.impl.impl.EvalExprImpl( - underlying=underlying, - substitutions=substitutions, - ) diff --git a/polymatrix/expression/init/initexpression.py b/polymatrix/expression/init/initexpression.py deleted file mode 100644 index 3c3258c..0000000 --- a/polymatrix/expression/init/initexpression.py +++ /dev/null @@ -1,10 +0,0 @@ -from polymatrix.expression.expression import ExpressionImpl -from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin - - -def init_expression( - underlying: ExpressionBaseMixin, -): - return ExpressionImpl( - underlying=underlying, -) diff --git a/polymatrix/expression/init/initeyeexpr.py b/polymatrix/expression/init/initeyeexpr.py deleted file mode 100644 index 642e4c6..0000000 --- a/polymatrix/expression/init/initeyeexpr.py +++ /dev/null @@ -1,10 +0,0 @@ -from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin -import polymatrix.expression.impl.impl - - -def init_eye_expr( - variable: ExpressionBaseMixin, -): - return polymatrix.expression.impl.impl.EyeExprImpl( - variable=variable, -) diff --git a/polymatrix/expression/init/initfilterexpr.py b/polymatrix/expression/init/initfilterexpr.py deleted file mode 100644 index 7164183..0000000 --- a/polymatrix/expression/init/initfilterexpr.py +++ /dev/null @@ -1,17 +0,0 @@ -from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin -import polymatrix.expression.impl.impl - - -def init_filter_expr( - underlying: ExpressionBaseMixin, - predicator: ExpressionBaseMixin, - inverse: bool == None, -): - if inverse is None: - inverse = False - - return polymatrix.expression.impl.impl.FilterExprImpl( - underlying=underlying, - predicator=predicator, - inverse=inverse, -) diff --git a/polymatrix/expression/init/initfromsymmetricmatrixexpr.py b/polymatrix/expression/init/initfromsymmetricmatrixexpr.py deleted file mode 100644 index b3ef782..0000000 --- a/polymatrix/expression/init/initfromsymmetricmatrixexpr.py +++ /dev/null @@ -1,10 +0,0 @@ -from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin -import polymatrix.expression.impl.impl - - -def init_from_symmetric_matrix_expr( - underlying: ExpressionBaseMixin, -): - return polymatrix.expression.impl.impl.FromSymmetricMatrixExprImpl( - underlying=underlying, -) diff --git a/polymatrix/expression/init/initfromsympyexpr.py b/polymatrix/expression/init/initfromsympyexpr.py deleted file mode 100644 index 4ca6fcf..0000000 --- a/polymatrix/expression/init/initfromsympyexpr.py +++ /dev/null @@ -1,68 +0,0 @@ -import typing -import numpy as np -import sympy - -from polymatrix.expression.impl.impl import FromSympyExprImpl -from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin - - -def init_from_expr_or_none( - data: typing.Union[np.ndarray, tuple[tuple[float]]], -) -> ExpressionBaseMixin | None: - match data: - case np.ndarray(): - assert len(data.shape) <= 2 - - def gen_elements(): - for row in data: - if isinstance(row, np.ndarray): - yield tuple(row) - else: - yield (row,) - - data = tuple(gen_elements()) - - case sympy.Matrix(): - data = tuple(tuple(i for i in data.row(row)) for row in range(data.rows)) - - case tuple(): - - match data[0]: - - case tuple(): - n_col = len(data[0]) - assert all(len(col) == n_col for col in data) - - case _: - data = tuple((e,) for e in data) - - case sympy.Expr(): - data = ((sympy.expand(data),),) - - case ExpressionBaseMixin(): - return data - - case _: - if not isinstance(data, (float, int, np.number)): - # raise Exception(f'{data=}, {type(data)=}') - return None - - data = ((data,),) - - return FromSympyExprImpl( - data=data, - ) - - -def init_from_sympy_expr( - data: typing.Union[np.ndarray, tuple[tuple[float]]], -): - # if isinstance(data, ExpressionBaseMixin): - # return data - - expr = init_from_expr_or_none(data) - - if expr is None: - raise Exception(f'{data=}') - - return expr diff --git a/polymatrix/expression/init/initfromtermsexpr.py b/polymatrix/expression/init/initfromtermsexpr.py deleted file mode 100644 index b2c1dc3..0000000 --- a/polymatrix/expression/init/initfromtermsexpr.py +++ /dev/null @@ -1,33 +0,0 @@ -import typing -from polymatrix.polymatrix.mixins.polymatrixmixin import PolyMatrixMixin -import polymatrix.expression.impl.impl - - -def init_from_terms_expr( - terms: typing.Union[tuple, PolyMatrixMixin], - shape: tuple[int, int] = None, -): - - if isinstance(terms, PolyMatrixMixin): - shape = terms.shape - gen_terms = terms.gen_terms() - - else: - assert shape is not None - - if isinstance(terms, tuple): - gen_terms = terms - - elif isinstance(terms, dict): - gen_terms = terms.items() - - else: - raise Exception(f'{terms=}') - - # Expression needs to be hashable - terms_formatted = tuple((key, tuple(monomials.items())) for key, monomials in gen_terms) - - return polymatrix.expression.impl.impl.FromTermsExprImpl( - terms=terms_formatted, - shape=shape, - ) diff --git a/polymatrix/expression/init/initgetitemexpr.py b/polymatrix/expression/init/initgetitemexpr.py deleted file mode 100644 index f7fc0c9..0000000 --- a/polymatrix/expression/init/initgetitemexpr.py +++ /dev/null @@ -1,22 +0,0 @@ -from numpy import isin -from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin -import polymatrix.expression.impl.impl - - -def init_get_item_expr( - underlying: ExpressionBaseMixin, - index: tuple[tuple[int, ...], tuple[int, ...]], -): - - def get_hashable_slice(index): - if isinstance(index, slice): - return polymatrix.expression.impl.impl.GetItemExprImpl.Slice(start=index.start, stop=index.stop, step=index.step) - else: - return index - - proper_index = (get_hashable_slice(index[0]), get_hashable_slice(index[1])) - - return polymatrix.expression.impl.impl.GetItemExprImpl( - underlying=underlying, - index=proper_index, -) diff --git a/polymatrix/expression/init/inithalfnewtonpolytopeexpr.py b/polymatrix/expression/init/inithalfnewtonpolytopeexpr.py deleted file mode 100644 index 794c938..0000000 --- a/polymatrix/expression/init/inithalfnewtonpolytopeexpr.py +++ /dev/null @@ -1,14 +0,0 @@ -from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin -import polymatrix.expression.impl.impl - - -def init_half_newton_polytope_expr( - monomials: ExpressionBaseMixin, - variables: ExpressionBaseMixin, - filter: ExpressionBaseMixin | None = None, -): - return polymatrix.expression.impl.impl.HalfNewtonPolytopeExprImpl( - monomials=monomials, - variables=variables, - filter=filter -) diff --git a/polymatrix/expression/init/initlinearinexpr.py b/polymatrix/expression/init/initlinearinexpr.py deleted file mode 100644 index 30705e2..0000000 --- a/polymatrix/expression/init/initlinearinexpr.py +++ /dev/null @@ -1,18 +0,0 @@ -from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin -import polymatrix.expression.impl.impl - - -def init_linear_in_expr( - underlying: ExpressionBaseMixin, - monomials: ExpressionBaseMixin, - variables: ExpressionBaseMixin, - ignore_unmatched: bool = None, -): - assert isinstance(variables, ExpressionBaseMixin), f'{variables=}' - - return polymatrix.expression.impl.impl.LinearInExprImpl( - underlying=underlying, - monomials=monomials, - variables=variables, - ignore_unmatched = ignore_unmatched, -) diff --git a/polymatrix/expression/init/initlinearmatrixinexpr.py b/polymatrix/expression/init/initlinearmatrixinexpr.py deleted file mode 100644 index 83e9aea..0000000 --- a/polymatrix/expression/init/initlinearmatrixinexpr.py +++ /dev/null @@ -1,12 +0,0 @@ -from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin -import polymatrix.expression.impl.impl - - -def init_linear_matrix_in_expr( - underlying: ExpressionBaseMixin, - variable: int, -): - return polymatrix.expression.impl.impl.LinearMatrixInExprImpl( - underlying=underlying, - variable=variable, -) diff --git a/polymatrix/expression/init/initlinearmonomialsexpr.py b/polymatrix/expression/init/initlinearmonomialsexpr.py deleted file mode 100644 index f830542..0000000 --- a/polymatrix/expression/init/initlinearmonomialsexpr.py +++ /dev/null @@ -1,15 +0,0 @@ -from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin -import polymatrix.expression.impl.impl - - -def init_linear_monomials_expr( - underlying: ExpressionBaseMixin, - variables: ExpressionBaseMixin, -): - - assert isinstance(variables, ExpressionBaseMixin), f'{variables=}' - - return polymatrix.expression.impl.impl.LinearMonomialsExprImpl( - underlying=underlying, - variables=variables, - ) diff --git a/polymatrix/expression/init/initmatrixmultexpr.py b/polymatrix/expression/init/initmatrixmultexpr.py deleted file mode 100644 index 20bffec..0000000 --- a/polymatrix/expression/init/initmatrixmultexpr.py +++ /dev/null @@ -1,12 +0,0 @@ -from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin -import polymatrix.expression.impl.impl - - -def init_matrix_mult_expr( - left: ExpressionBaseMixin, - right: ExpressionBaseMixin, -): - return polymatrix.expression.impl.impl.MatrixMultExprImpl( - left=left, - right=right, -) diff --git a/polymatrix/expression/init/initmaxdegreeexpr.py b/polymatrix/expression/init/initmaxdegreeexpr.py deleted file mode 100644 index d232163..0000000 --- a/polymatrix/expression/init/initmaxdegreeexpr.py +++ /dev/null @@ -1,10 +0,0 @@ -from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin -import polymatrix.expression.impl.impl - - -def init_max_degree_expr( - underlying: ExpressionBaseMixin, -): - return polymatrix.expression.impl.impl.MaxDegreeExprImpl( - underlying=underlying, -) diff --git a/polymatrix/expression/init/initmaxexpr.py b/polymatrix/expression/init/initmaxexpr.py deleted file mode 100644 index 41dde90..0000000 --- a/polymatrix/expression/init/initmaxexpr.py +++ /dev/null @@ -1,10 +0,0 @@ -from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin -import polymatrix.expression.impl.impl - - -def init_max_expr( - underlying: ExpressionBaseMixin, -): - return polymatrix.expression.impl.impl.MaxExprImpl( - underlying=underlying, -) diff --git a/polymatrix/expression/init/initparametrizeexpr.py b/polymatrix/expression/init/initparametrizeexpr.py deleted file mode 100644 index 178d963..0000000 --- a/polymatrix/expression/init/initparametrizeexpr.py +++ /dev/null @@ -1,15 +0,0 @@ -from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin -import polymatrix.expression.impl.impl - - -def init_parametrize_expr( - underlying: ExpressionBaseMixin, - name: str = None, -): - if name is None: - name = 'undefined' - - return polymatrix.expression.impl.impl.ParametrizeExprImpl( - underlying=underlying, - name=name, -) diff --git a/polymatrix/expression/init/initparametrizematrixexpr.py b/polymatrix/expression/init/initparametrizematrixexpr.py deleted file mode 100644 index bf90510..0000000 --- a/polymatrix/expression/init/initparametrizematrixexpr.py +++ /dev/null @@ -1,12 +0,0 @@ -from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin -import polymatrix.expression.impl.impl - - -def init_parametrize_matrix_expr( - underlying: ExpressionBaseMixin, - name: str, -): - return polymatrix.expression.impl.impl.ParametrizeMatrixExprImpl( - underlying=underlying, - name=name, -) diff --git a/polymatrix/expression/init/initquadraticinexpr.py b/polymatrix/expression/init/initquadraticinexpr.py deleted file mode 100644 index 9569cd3..0000000 --- a/polymatrix/expression/init/initquadraticinexpr.py +++ /dev/null @@ -1,17 +0,0 @@ -from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin -import polymatrix.expression.impl.impl - - -def init_quadratic_in_expr( - underlying: ExpressionBaseMixin, - monomials: ExpressionBaseMixin, - variables: ExpressionBaseMixin, -): - - assert isinstance(variables, ExpressionBaseMixin), f'{variables=}' - - return polymatrix.expression.impl.impl.QuadraticInExprImpl( - underlying=underlying, - monomials=monomials, - variables=variables, - ) diff --git a/polymatrix/expression/init/initquadraticmonomialsexpr.py b/polymatrix/expression/init/initquadraticmonomialsexpr.py deleted file mode 100644 index c965312..0000000 --- a/polymatrix/expression/init/initquadraticmonomialsexpr.py +++ /dev/null @@ -1,15 +0,0 @@ -from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin -import polymatrix.expression.impl.impl - - -def init_quadratic_monomials_expr( - underlying: ExpressionBaseMixin, - variables: ExpressionBaseMixin, -): - - assert isinstance(variables, ExpressionBaseMixin), f'{variables=}' - - return polymatrix.expression.impl.impl.QuadraticMonomialsExprImpl( - underlying=underlying, - variables=variables, - ) diff --git a/polymatrix/expression/init/initrepmatexpr.py b/polymatrix/expression/init/initrepmatexpr.py deleted file mode 100644 index 152fff8..0000000 --- a/polymatrix/expression/init/initrepmatexpr.py +++ /dev/null @@ -1,12 +0,0 @@ -from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin -import polymatrix.expression.impl.impl - - -def init_rep_mat_expr( - underlying: ExpressionBaseMixin, - repetition: tuple, -): - return polymatrix.expression.impl.impl.RepMatExprImpl( - underlying=underlying, - repetition=repetition, -) diff --git a/polymatrix/expression/init/initreshapeexpr.py b/polymatrix/expression/init/initreshapeexpr.py deleted file mode 100644 index 4e6ab57..0000000 --- a/polymatrix/expression/init/initreshapeexpr.py +++ /dev/null @@ -1,12 +0,0 @@ -from polymatrix.expression.impl.reshapeexprmixin import ReshapeExprImpl -from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin - - -def init_reshape_expr( - underlying: ExpressionBaseMixin, - new_shape: tuple, -): - return ReshapeExprImpl( - underlying=underlying, - new_shape=new_shape, -) diff --git a/polymatrix/expression/init/initsetelementatexpr.py b/polymatrix/expression/init/initsetelementatexpr.py deleted file mode 100644 index 250c35b..0000000 --- a/polymatrix/expression/init/initsetelementatexpr.py +++ /dev/null @@ -1,14 +0,0 @@ -from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin -import polymatrix.expression.impl.impl - - -def init_set_element_at_expr( - underlying: ExpressionBaseMixin, - index: tuple, - value: ExpressionBaseMixin, -): - return polymatrix.expression.impl.impl.SetElementAtExprImpl( - underlying=underlying, - index=index, - value=value, -) diff --git a/polymatrix/expression/init/initsqueezeexpr.py b/polymatrix/expression/init/initsqueezeexpr.py deleted file mode 100644 index d539453..0000000 --- a/polymatrix/expression/init/initsqueezeexpr.py +++ /dev/null @@ -1,10 +0,0 @@ -from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin -import polymatrix.expression.impl.impl - - -def init_squeeze_expr( - underlying: ExpressionBaseMixin, -): - return polymatrix.expression.impl.impl.SqueezeExprImpl( - underlying=underlying, -) diff --git a/polymatrix/expression/init/initsubstituteexpr.py b/polymatrix/expression/init/initsubstituteexpr.py deleted file mode 100644 index e141d9e..0000000 --- a/polymatrix/expression/init/initsubstituteexpr.py +++ /dev/null @@ -1,75 +0,0 @@ -import typing -import numpy as np - -from polymatrix.expression.init.initfromsympyexpr import init_from_sympy_expr -from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin -import polymatrix.expression.impl.impl - - -def format_substitutions( - variables: typing.Union[typing.Any, tuple, dict], - values: float | tuple = None, -): - """ - (variables = x, values = 1.0) # ok - (variables = x, values = np.array(1.0)) # ok - (variables = (x, y, z), values = 1.0) # ok - (variables = (x, y, z), values = (1.0, 2.0, 3.0)) # ok - (variables = {x: 1.0, y: 2.0, z: 3.0}) # ok - (variables = ((x, 1.0), (y, 2.0), (z, 3.0))) # ok - - (variables = v, values = (1.0, 2.0)) # ok - (variables = (v1, v2), values = ((1.0, 2.0), (3.0,))) # ok - (variables = (v1, v2), values = (1.0, 2.0, 3.0)) # not ok - """ - - if values is not None: - if isinstance(variables, tuple): - if isinstance(values, tuple): - assert len(variables) == len(values), f'{variables=}, {values=}' - - else: - values = tuple(values for _ in variables) - - else: - variables = (variables,) - values = (values,) - - substitutions = zip(variables, values) - - elif isinstance(variables, dict): - substitutions = variables.items() - - elif isinstance(variables, tuple): - substitutions = variables - - else: - raise Exception(f'{variables=}') - - return substitutions - - -def init_substitute_expr( - underlying: ExpressionBaseMixin, - variables: tuple, - values: tuple = None, -): - - substitutions = format_substitutions( - variables=variables, - values=values, - ) - - def formatted_values(value) -> ExpressionBaseMixin: - if isinstance(value, ExpressionBaseMixin): - return value - - else: - return init_from_sympy_expr(value) - - substitutions = tuple((variable, formatted_values(value)) for variable, value in substitutions) - - return polymatrix.expression.impl.impl.SubstituteExprImpl( - underlying=underlying, - substitutions=substitutions, - ) diff --git a/polymatrix/expression/init/initsubtractmonomialsexpr.py b/polymatrix/expression/init/initsubtractmonomialsexpr.py deleted file mode 100644 index de720bd..0000000 --- a/polymatrix/expression/init/initsubtractmonomialsexpr.py +++ /dev/null @@ -1,12 +0,0 @@ -from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin -import polymatrix.expression.impl.impl - - -def init_subtract_monomials_expr( - underlying: ExpressionBaseMixin, - monomials: ExpressionBaseMixin, -): - return polymatrix.expression.impl.impl.SubtractMonomialsExprImpl( - underlying=underlying, - monomials=monomials, -) diff --git a/polymatrix/expression/init/initsumexpr.py b/polymatrix/expression/init/initsumexpr.py deleted file mode 100644 index 288ae72..0000000 --- a/polymatrix/expression/init/initsumexpr.py +++ /dev/null @@ -1,10 +0,0 @@ -from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin -import polymatrix.expression.impl.impl - - -def init_sum_expr( - underlying: ExpressionBaseMixin, -): - return polymatrix.expression.impl.impl.SumExprImpl( - underlying=underlying, -) diff --git a/polymatrix/expression/init/initsymmetricexpr.py b/polymatrix/expression/init/initsymmetricexpr.py deleted file mode 100644 index dc321e5..0000000 --- a/polymatrix/expression/init/initsymmetricexpr.py +++ /dev/null @@ -1,10 +0,0 @@ -from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin -import polymatrix.expression.impl.impl - - -def init_symmetric_expr( - underlying: ExpressionBaseMixin, -): - return polymatrix.expression.impl.impl.SymmetricExprImpl( - underlying=underlying, -) diff --git a/polymatrix/expression/init/inittoconstantexpr.py b/polymatrix/expression/init/inittoconstantexpr.py deleted file mode 100644 index a0084a1..0000000 --- a/polymatrix/expression/init/inittoconstantexpr.py +++ /dev/null @@ -1,10 +0,0 @@ -from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin -import polymatrix.expression.impl.impl - - -def init_to_constant_expr( - underlying: ExpressionBaseMixin, -): - return polymatrix.expression.impl.impl.ToConstantExprImpl( - underlying=underlying, -) diff --git a/polymatrix/expression/init/inittoquadraticexpr.py b/polymatrix/expression/init/inittoquadraticexpr.py deleted file mode 100644 index 77e6943..0000000 --- a/polymatrix/expression/init/inittoquadraticexpr.py +++ /dev/null @@ -1,10 +0,0 @@ -from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin -import polymatrix.expression.impl.impl - - -def init_to_quadratic_expr( - underlying: ExpressionBaseMixin, -): - return polymatrix.expression.impl.impl.ToQuadraticExprImpl( - underlying=underlying, -) diff --git a/polymatrix/expression/init/inittosortedvariables.py b/polymatrix/expression/init/inittosortedvariables.py deleted file mode 100644 index 3f5222a..0000000 --- a/polymatrix/expression/init/inittosortedvariables.py +++ /dev/null @@ -1,10 +0,0 @@ -from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin -import polymatrix.expression.impl.impl - - -def init_to_sorted_variables( - underlying: ExpressionBaseMixin, -): - return polymatrix.expression.impl.impl.ToSortedVariablesImpl( - underlying=underlying, -) diff --git a/polymatrix/expression/init/inittosymmetricmatrixexpr.py b/polymatrix/expression/init/inittosymmetricmatrixexpr.py deleted file mode 100644 index 68b27fe..0000000 --- a/polymatrix/expression/init/inittosymmetricmatrixexpr.py +++ /dev/null @@ -1,10 +0,0 @@ -from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin -import polymatrix.expression.impl.impl - - -def init_to_symmetric_matrix_expr( - underlying: ExpressionBaseMixin, -): - return polymatrix.expression.impl.impl.ToSymmetricMatrixExprImpl( - underlying=underlying, -) diff --git a/polymatrix/expression/init/inittransposeexpr.py b/polymatrix/expression/init/inittransposeexpr.py deleted file mode 100644 index 7807e4d..0000000 --- a/polymatrix/expression/init/inittransposeexpr.py +++ /dev/null @@ -1,10 +0,0 @@ -from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin -import polymatrix.expression.impl.impl - - -def init_transpose_expr( - underlying: ExpressionBaseMixin, -): - return polymatrix.expression.impl.impl.TransposeExprImpl( - underlying=underlying, -) diff --git a/polymatrix/expression/init/inittruncateexpr.py b/polymatrix/expression/init/inittruncateexpr.py deleted file mode 100644 index d36db03..0000000 --- a/polymatrix/expression/init/inittruncateexpr.py +++ /dev/null @@ -1,22 +0,0 @@ -from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin -import polymatrix.expression.impl.impl - - -def init_truncate_expr( - underlying: ExpressionBaseMixin, - variables: ExpressionBaseMixin, - degrees: tuple[int], - inverse: bool = None, -): - if isinstance(degrees, int): - degrees = (degrees,) - - if inverse is None: - inverse = False - - return polymatrix.expression.impl.impl.TruncateExprImpl( - underlying=underlying, - variables=variables, - degrees=degrees, - inverse=inverse, - ) diff --git a/polymatrix/expression/init/initvstackexpr.py b/polymatrix/expression/init/initvstackexpr.py deleted file mode 100644 index 3d47979..0000000 --- a/polymatrix/expression/init/initvstackexpr.py +++ /dev/null @@ -1,20 +0,0 @@ -from polymatrix.expression.init.initfromsympyexpr import init_from_sympy_expr -from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin -import polymatrix.expression.impl.impl - - -def init_v_stack_expr( - underlying: tuple, -): - - def gen_underlying(): - - for e in underlying: - if isinstance(e, ExpressionBaseMixin): - yield e - else: - yield init_from_sympy_expr(e) - - return polymatrix.expression.impl.impl.VStackExprImpl( - underlying=tuple(gen_underlying()), -) |