summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Schneeberger <michael.schneeberger@fhnw.ch>2023-04-21 09:09:13 +0200
committerMichael Schneeberger <michael.schneeberger@fhnw.ch>2023-04-21 09:09:13 +0200
commit55ac3a7bd2a0e294de6d11709c805bedc4f6d849 (patch)
tree821ba96bc3687f2f1b4c89e06197c8773e2b8ca4
parentparametrize operator acts only on column vector (diff)
downloadpolymatrix-55ac3a7bd2a0e294de6d11709c805bedc4f6d849.tar.gz
polymatrix-55ac3a7bd2a0e294de6d11709c805bedc4f6d849.zip
rename dataclass_abc to dataclassabc
-rw-r--r--polymatrix/__init__.py9
-rw-r--r--polymatrix/expression/additionexpr.py4
-rw-r--r--polymatrix/expression/blockdiagexpr.py4
-rw-r--r--polymatrix/expression/cacheexpr.py4
-rw-r--r--polymatrix/expression/combinationsexpr.py4
-rw-r--r--polymatrix/expression/derivativeexpr.py4
-rw-r--r--polymatrix/expression/determinantexpr.py4
-rw-r--r--polymatrix/expression/diagexpr.py4
-rw-r--r--polymatrix/expression/divergenceexpr.py4
-rw-r--r--polymatrix/expression/divisionexpr.py4
-rw-r--r--polymatrix/expression/elemmultexpr.py4
-rw-r--r--polymatrix/expression/evalexpr.py4
-rw-r--r--polymatrix/expression/expression.py539
-rw-r--r--polymatrix/expression/eyeexpr.py4
-rw-r--r--polymatrix/expression/filterexpr.py4
-rw-r--r--polymatrix/expression/fromsymmetricmatrixexpr.py4
-rw-r--r--polymatrix/expression/fromsympyexpr.py4
-rw-r--r--polymatrix/expression/fromtermsexpr.py4
-rw-r--r--polymatrix/expression/getitemexpr.py4
-rw-r--r--polymatrix/expression/halfnewtonpolytopeexpr.py4
-rw-r--r--polymatrix/expression/impl/__init__.py0
-rw-r--r--polymatrix/expression/impl/additionexprimpl.py9
-rw-r--r--polymatrix/expression/impl/blockdiagexprimpl.py7
-rw-r--r--polymatrix/expression/impl/cacheexprimpl.py9
-rw-r--r--polymatrix/expression/impl/combinationsexprimpl.py9
-rw-r--r--polymatrix/expression/impl/derivativeexprimpl.py10
-rw-r--r--polymatrix/expression/impl/determinantexprimpl.py8
-rw-r--r--polymatrix/expression/impl/diagexprimpl.py8
-rw-r--r--polymatrix/expression/impl/divergenceexprimpl.py10
-rw-r--r--polymatrix/expression/impl/divisionexprimpl.py9
-rw-r--r--polymatrix/expression/impl/elemmultexprimpl.py9
-rw-r--r--polymatrix/expression/impl/evalexprimpl.py10
-rw-r--r--polymatrix/expression/impl/expressionimpl.py11
-rw-r--r--polymatrix/expression/impl/eyeexprimpl.py8
-rw-r--r--polymatrix/expression/impl/filterexprimpl.py10
-rw-r--r--polymatrix/expression/impl/fromsymmetricmatrixexprimpl.py8
-rw-r--r--polymatrix/expression/impl/fromsympyexprimpl.py7
-rw-r--r--polymatrix/expression/impl/fromtermsexprimpl.py8
-rw-r--r--polymatrix/expression/impl/getitemexprimpl.py9
-rw-r--r--polymatrix/expression/impl/halfnewtonpolytopeexprimpl.py10
-rw-r--r--polymatrix/expression/impl/impl.py320
-rw-r--r--polymatrix/expression/impl/linearinexprimpl.py11
-rw-r--r--polymatrix/expression/impl/linearmatrixinexprimpl.py9
-rw-r--r--polymatrix/expression/impl/linearmonomialsexprimpl.py9
-rw-r--r--polymatrix/expression/impl/matrixmultexprimpl.py9
-rw-r--r--polymatrix/expression/impl/maxdegreeexprimpl.py8
-rw-r--r--polymatrix/expression/impl/maxexprimpl.py8
-rw-r--r--polymatrix/expression/impl/parametrizeexprimpl.py19
-rw-r--r--polymatrix/expression/impl/quadraticinexprimpl.py10
-rw-r--r--polymatrix/expression/impl/quadraticmonomialsexprimpl.py9
-rw-r--r--polymatrix/expression/impl/repmatexprimpl.py9
-rw-r--r--polymatrix/expression/impl/reshapeexprimpl.py9
-rw-r--r--polymatrix/expression/impl/reshapeexprmixin.py10
-rw-r--r--polymatrix/expression/impl/setelementatexprimpl.py10
-rw-r--r--polymatrix/expression/impl/squeezeexprimpl.py8
-rw-r--r--polymatrix/expression/impl/substituteexprimpl.py10
-rw-r--r--polymatrix/expression/impl/subtractmonomialsexprimpl.py9
-rw-r--r--polymatrix/expression/impl/sumexprimpl.py8
-rw-r--r--polymatrix/expression/impl/symmetricexprimpl.py8
-rw-r--r--polymatrix/expression/impl/toconstantexprimpl.py8
-rw-r--r--polymatrix/expression/impl/toquadraticexprimpl.py8
-rw-r--r--polymatrix/expression/impl/tosortedvariablesimpl.py8
-rw-r--r--polymatrix/expression/impl/tosymmetricmatrixexprimpl.py8
-rw-r--r--polymatrix/expression/impl/transposeexprimpl.py8
-rw-r--r--polymatrix/expression/impl/truncateexprimpl.py11
-rw-r--r--polymatrix/expression/impl/vstackexprimpl.py7
-rw-r--r--polymatrix/expression/init/initadditionexpr.py4
-rw-r--r--polymatrix/expression/init/initblockdiagexpr.py6
-rw-r--r--polymatrix/expression/init/initcacheexpr.py4
-rw-r--r--polymatrix/expression/init/initcombinationsexpr.py4
-rw-r--r--polymatrix/expression/init/initderivativeexpr.py4
-rw-r--r--polymatrix/expression/init/initdeterminantexpr.py4
-rw-r--r--polymatrix/expression/init/initdiagexpr.py4
-rw-r--r--polymatrix/expression/init/initdivergenceexpr.py4
-rw-r--r--polymatrix/expression/init/initdivisionexpr.py4
-rw-r--r--polymatrix/expression/init/initelemmultexpr.py4
-rw-r--r--polymatrix/expression/init/initevalexpr.py4
-rw-r--r--polymatrix/expression/init/initexpression.py2
-rw-r--r--polymatrix/expression/init/initeyeexpr.py4
-rw-r--r--polymatrix/expression/init/initfilterexpr.py4
-rw-r--r--polymatrix/expression/init/initfromsymmetricmatrixexpr.py4
-rw-r--r--polymatrix/expression/init/initfromsympyexpr.py37
-rw-r--r--polymatrix/expression/init/initfromtermsexpr.py4
-rw-r--r--polymatrix/expression/init/initgetitemexpr.py6
-rw-r--r--polymatrix/expression/init/inithalfnewtonpolytopeexpr.py4
-rw-r--r--polymatrix/expression/init/initlinearinexpr.py4
-rw-r--r--polymatrix/expression/init/initlinearmatrixinexpr.py4
-rw-r--r--polymatrix/expression/init/initlinearmonomialsexpr.py4
-rw-r--r--polymatrix/expression/init/initmatrixmultexpr.py4
-rw-r--r--polymatrix/expression/init/initmaxdegreeexpr.py4
-rw-r--r--polymatrix/expression/init/initmaxexpr.py4
-rw-r--r--polymatrix/expression/init/initparametrizeexpr.py4
-rw-r--r--polymatrix/expression/init/initparametrizematrixexpr.py12
-rw-r--r--polymatrix/expression/init/initquadraticinexpr.py4
-rw-r--r--polymatrix/expression/init/initquadraticmonomialsexpr.py4
-rw-r--r--polymatrix/expression/init/initrepmatexpr.py4
-rw-r--r--polymatrix/expression/init/initreshapeexpr.py2
-rw-r--r--polymatrix/expression/init/initsetelementatexpr.py4
-rw-r--r--polymatrix/expression/init/initsqueezeexpr.py4
-rw-r--r--polymatrix/expression/init/initsubstituteexpr.py7
-rw-r--r--polymatrix/expression/init/initsubtractmonomialsexpr.py4
-rw-r--r--polymatrix/expression/init/initsumexpr.py4
-rw-r--r--polymatrix/expression/init/initsymmetricexpr.py4
-rw-r--r--polymatrix/expression/init/inittoconstantexpr.py4
-rw-r--r--polymatrix/expression/init/inittoquadraticexpr.py4
-rw-r--r--polymatrix/expression/init/inittosortedvariables.py4
-rw-r--r--polymatrix/expression/init/inittosymmetricmatrixexpr.py4
-rw-r--r--polymatrix/expression/init/inittransposeexpr.py4
-rw-r--r--polymatrix/expression/init/inittruncateexpr.py4
-rw-r--r--polymatrix/expression/init/initvstackexpr.py4
-rw-r--r--polymatrix/expression/linearinexpr.py4
-rw-r--r--polymatrix/expression/linearmatrixinexpr.py4
-rw-r--r--polymatrix/expression/linearmonomialsexpr.py4
-rw-r--r--polymatrix/expression/matrixmultexpr.py4
-rw-r--r--polymatrix/expression/maxdegreeexpr.py4
-rw-r--r--polymatrix/expression/maxexpr.py4
-rw-r--r--polymatrix/expression/mixins/additionexprmixin.py6
-rw-r--r--polymatrix/expression/mixins/assertdegreeexprmixin.py4
-rw-r--r--polymatrix/expression/mixins/blockdiagexprmixin.py4
-rw-r--r--polymatrix/expression/mixins/diagexprmixin.py6
-rw-r--r--polymatrix/expression/mixins/elemmultexprmixin.py4
-rw-r--r--polymatrix/expression/mixins/evalexprmixin.py1
-rw-r--r--polymatrix/expression/mixins/expressionmixin.py534
-rw-r--r--polymatrix/expression/mixins/eyeexprmixin.py4
-rw-r--r--polymatrix/expression/mixins/fromsympyexprmixin.py2
-rw-r--r--polymatrix/expression/mixins/getitemexprmixin.py4
-rw-r--r--polymatrix/expression/mixins/quadraticinexprmixin.py7
-rw-r--r--polymatrix/expression/mixins/repmatexprmixin.py4
-rw-r--r--polymatrix/expression/mixins/reshapeexprmixin.py4
-rw-r--r--polymatrix/expression/mixins/setelementatexprmixin.py4
-rw-r--r--polymatrix/expression/mixins/squeezeexprmixin.py3
-rw-r--r--polymatrix/expression/mixins/substituteexprmixin.py11
-rw-r--r--polymatrix/expression/mixins/symmetricexprmixin.py4
-rw-r--r--polymatrix/expression/mixins/tosortedvariablesmixin.py2
-rw-r--r--polymatrix/expression/mixins/transposeexprmixin.py4
-rw-r--r--polymatrix/expression/mixins/vstackexprmixin.py4
-rw-r--r--polymatrix/expression/parametrizeexpr.py4
-rw-r--r--polymatrix/expression/quadraticinexpr.py4
-rw-r--r--polymatrix/expression/quadraticmonomialsexpr.py4
-rw-r--r--polymatrix/expression/repmatexpr.py4
-rw-r--r--polymatrix/expression/reshapeexpr.py4
-rw-r--r--polymatrix/expression/setelementatexpr.py4
-rw-r--r--polymatrix/expression/squeezeexpr.py4
-rw-r--r--polymatrix/expression/substituteexpr.py4
-rw-r--r--polymatrix/expression/subtractmonomialsexpr.py4
-rw-r--r--polymatrix/expression/sumexpr.py4
-rw-r--r--polymatrix/expression/symmetricexpr.py4
-rw-r--r--polymatrix/expression/toconstantexpr.py4
-rw-r--r--polymatrix/expression/toquadraticexpr.py4
-rw-r--r--polymatrix/expression/tosortedvariables.py4
-rw-r--r--polymatrix/expression/tosymmetricmatrixexpr.py4
-rw-r--r--polymatrix/expression/transposeexpr.py4
-rw-r--r--polymatrix/expression/truncateexpr.py4
-rw-r--r--polymatrix/expression/vstackexpr.py4
-rw-r--r--polymatrix/expressionstate/impl/expressionstateimpl.py4
-rw-r--r--polymatrix/polymatrix/impl/polymatriximpl.py4
-rw-r--r--polymatrix/statemonad/impl/statemonadimpl.py4
157 files changed, 1038 insertions, 1246 deletions
diff --git a/polymatrix/__init__.py b/polymatrix/__init__.py
index 64f3d63..8cffe4b 100644
--- a/polymatrix/__init__.py
+++ b/polymatrix/__init__.py
@@ -7,9 +7,8 @@ import numpy as np
import scipy.sparse
import sympy
-from polymatrix.expression.mixins.expressionmixin import ExpressionMixin as Expression
+from polymatrix.expression.expression import Expression
from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
-# from polymatrix.expression.mixins.expressionmixin import ExpressionMixin
from polymatrix.expression.mixins.parametrizeexprmixin import ParametrizeExprMixin
from polymatrix.expression.mixins.parametrizematrixexprmixin import ParametrizeMatrixExprMixin
from polymatrix.expressionstate.expressionstate import ExpressionState
@@ -480,7 +479,10 @@ def to_matrix_repr(
else:
sorted_variable_index = variable_index
- assert len(sorted_variable_index) == len(set(sorted_variable_index)), f'{sorted_variable_index=} contains repeated variables. Make sure you give a unique name for each variables.'
+ sorted_variable_index_set = set(sorted_variable_index)
+ if len(sorted_variable_index) != len(sorted_variable_index_set):
+ duplicates = tuple(state.get_name_from_offset(var) for var in sorted_variable_index_set if 1 < sorted_variable_index.count(var))
+ raise Exception(f'{duplicates=}. Make sure you give a unique name for each variables.')
variable_index_map = {old: new for new, old in enumerate(sorted_variable_index)}
@@ -575,6 +577,7 @@ def to_matrix_repr(
return init_state_monad(func)
+
def to_constant_repr(
expr: Expression,
assert_constant: bool = True,
diff --git a/polymatrix/expression/additionexpr.py b/polymatrix/expression/additionexpr.py
deleted file mode 100644
index 6a43ba3..0000000
--- a/polymatrix/expression/additionexpr.py
+++ /dev/null
@@ -1,4 +0,0 @@
-from polymatrix.expression.mixins.additionexprmixin import AdditionExprMixin
-
-class AdditionExpr(AdditionExprMixin):
- pass
diff --git a/polymatrix/expression/blockdiagexpr.py b/polymatrix/expression/blockdiagexpr.py
deleted file mode 100644
index e3acee5..0000000
--- a/polymatrix/expression/blockdiagexpr.py
+++ /dev/null
@@ -1,4 +0,0 @@
-from polymatrix.expression.mixins.blockdiagexprmixin import BlockDiagExprMixin
-
-class BlockDiagExpr(BlockDiagExprMixin):
- pass
diff --git a/polymatrix/expression/cacheexpr.py b/polymatrix/expression/cacheexpr.py
deleted file mode 100644
index 5ae4052..0000000
--- a/polymatrix/expression/cacheexpr.py
+++ /dev/null
@@ -1,4 +0,0 @@
-from polymatrix.expression.mixins.cacheexprmixin import CacheExprMixin
-
-class CacheExpr(CacheExprMixin):
- pass
diff --git a/polymatrix/expression/combinationsexpr.py b/polymatrix/expression/combinationsexpr.py
deleted file mode 100644
index 3373365..0000000
--- a/polymatrix/expression/combinationsexpr.py
+++ /dev/null
@@ -1,4 +0,0 @@
-from polymatrix.expression.mixins.combinationsexprmixin import CombinationsExprMixin
-
-class CombinationsExpr(CombinationsExprMixin):
- pass
diff --git a/polymatrix/expression/derivativeexpr.py b/polymatrix/expression/derivativeexpr.py
deleted file mode 100644
index 6805e4b..0000000
--- a/polymatrix/expression/derivativeexpr.py
+++ /dev/null
@@ -1,4 +0,0 @@
-from polymatrix.expression.mixins.derivativeexprmixin import DerivativeExprMixin
-
-class DerivativeExpr(DerivativeExprMixin):
- pass
diff --git a/polymatrix/expression/determinantexpr.py b/polymatrix/expression/determinantexpr.py
deleted file mode 100644
index 6e584f9..0000000
--- a/polymatrix/expression/determinantexpr.py
+++ /dev/null
@@ -1,4 +0,0 @@
-from polymatrix.expression.mixins.determinantexprmixin import DeterminantExprMixin
-
-class DeterminantExpr(DeterminantExprMixin):
- pass
diff --git a/polymatrix/expression/diagexpr.py b/polymatrix/expression/diagexpr.py
deleted file mode 100644
index 1fcf14e..0000000
--- a/polymatrix/expression/diagexpr.py
+++ /dev/null
@@ -1,4 +0,0 @@
-from polymatrix.expression.mixins.diagexprmixin import DiagExprMixin
-
-class DiagExpr(DiagExprMixin):
- pass
diff --git a/polymatrix/expression/divergenceexpr.py b/polymatrix/expression/divergenceexpr.py
deleted file mode 100644
index 9207bd2..0000000
--- a/polymatrix/expression/divergenceexpr.py
+++ /dev/null
@@ -1,4 +0,0 @@
-from polymatrix.expression.mixins.divergenceexprmixin import DivergenceExprMixin
-
-class DivergenceExpr(DivergenceExprMixin):
- pass
diff --git a/polymatrix/expression/divisionexpr.py b/polymatrix/expression/divisionexpr.py
deleted file mode 100644
index 63c95d9..0000000
--- a/polymatrix/expression/divisionexpr.py
+++ /dev/null
@@ -1,4 +0,0 @@
-from polymatrix.expression.mixins.divisionexprmixin import DivisionExprMixin
-
-class DivisionExpr(DivisionExprMixin):
- pass
diff --git a/polymatrix/expression/elemmultexpr.py b/polymatrix/expression/elemmultexpr.py
deleted file mode 100644
index 1c8ef58..0000000
--- a/polymatrix/expression/elemmultexpr.py
+++ /dev/null
@@ -1,4 +0,0 @@
-from polymatrix.expression.mixins.elemmultexprmixin import ElemMultExprMixin
-
-class ElemMultExpr(ElemMultExprMixin):
- pass
diff --git a/polymatrix/expression/evalexpr.py b/polymatrix/expression/evalexpr.py
deleted file mode 100644
index 0af72d1..0000000
--- a/polymatrix/expression/evalexpr.py
+++ /dev/null
@@ -1,4 +0,0 @@
-from polymatrix.expression.mixins.evalexprmixin import EvalExprMixin
-
-class EvalExpr(EvalExprMixin):
- pass
diff --git a/polymatrix/expression/expression.py b/polymatrix/expression/expression.py
index 7f34637..25a8c9b 100644
--- a/polymatrix/expression/expression.py
+++ b/polymatrix/expression/expression.py
@@ -1,4 +1,537 @@
-from polymatrix.expression.mixins.expressionmixin import ExpressionMixin
+import abc
+import dataclasses
+import dataclassabc
+import typing
+import numpy as np
-class Expression(ExpressionMixin):
- pass
+from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
+from polymatrix.expression.init.initadditionexpr import init_addition_expr
+from polymatrix.expression.init.initcacheexpr import init_cache_expr
+from polymatrix.expression.init.initcombinationsexpr import init_combinations_expr
+from polymatrix.expression.init.initderivativeexpr import init_derivative_expr
+from polymatrix.expression.init.initdeterminantexpr import init_determinant_expr
+from polymatrix.expression.init.initdivergenceexpr import init_divergence_expr
+from polymatrix.expression.init.initdivisionexpr import init_division_expr
+from polymatrix.expression.init.initelemmultexpr import init_elem_mult_expr
+from polymatrix.expression.init.initevalexpr import init_eval_expr
+from polymatrix.expression.init.initfilterexpr import init_filter_expr
+from polymatrix.expression.init.initfromsymmetricmatrixexpr import init_from_symmetric_matrix_expr
+from polymatrix.expression.init.inithalfnewtonpolytopeexpr import init_half_newton_polytope_expr
+from polymatrix.expression.init.initlinearinexpr import init_linear_in_expr
+from polymatrix.expression.init.initfromsympyexpr import init_from_expr_or_none, init_from_sympy_expr
+from polymatrix.expression.init.initgetitemexpr import init_get_item_expr
+from polymatrix.expression.init.initlinearmatrixinexpr import init_linear_matrix_in_expr
+from polymatrix.expression.init.initlinearmonomialsexpr import init_linear_monomials_expr
+from polymatrix.expression.init.initmatrixmultexpr import init_matrix_mult_expr
+from polymatrix.expression.init.initmaxdegreeexpr import init_max_degree_expr
+from polymatrix.expression.init.initmaxexpr import init_max_expr
+from polymatrix.expression.init.initparametrizeexpr import init_parametrize_expr
+from polymatrix.expression.init.initparametrizematrixexpr import init_parametrize_matrix_expr
+from polymatrix.expression.init.initquadraticinexpr import init_quadratic_in_expr
+from polymatrix.expression.init.initrepmatexpr import init_rep_mat_expr
+from polymatrix.expression.init.initreshapeexpr import init_reshape_expr
+from polymatrix.expression.init.initsetelementatexpr import init_set_element_at_expr
+from polymatrix.expression.init.initquadraticmonomialsexpr import init_quadratic_monomials_expr
+from polymatrix.expression.init.initsqueezeexpr import init_squeeze_expr
+from polymatrix.expression.init.initsubstituteexpr import init_substitute_expr
+from polymatrix.expression.init.initsubtractmonomialsexpr import init_subtract_monomials_expr
+from polymatrix.expression.init.initsumexpr import init_sum_expr
+from polymatrix.expression.init.initsymmetricexpr import init_symmetric_expr
+from polymatrix.expression.init.inittoconstantexpr import init_to_constant_expr
+from polymatrix.expression.init.inittoquadraticexpr import init_to_quadratic_expr
+from polymatrix.expression.init.initdiagexpr import init_diag_expr
+from polymatrix.expression.init.inittosortedvariables import init_to_sorted_variables
+from polymatrix.expression.init.inittosymmetricmatrixexpr import init_to_symmetric_matrix_expr
+from polymatrix.expression.init.inittransposeexpr import init_transpose_expr
+from polymatrix.expression.init.inittruncateexpr import init_truncate_expr
+
+from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
+from polymatrix.polymatrix.polymatrix import PolyMatrix
+from polymatrix.expressionstate.expressionstate import ExpressionState
+
+
+class Expression(
+ ExpressionBaseMixin,
+ abc.ABC,
+):
+
+ @property
+ @abc.abstractmethod
+ def underlying(self) -> ExpressionBaseMixin:
+ ...
+
+ # overwrites abstract method of `PolyMatrixExprBaseMixin`
+ def apply(self, state: ExpressionState) -> tuple[ExpressionState, PolyMatrix]:
+ return self.underlying.apply(state)
+
+ def __add__(self, other: ExpressionBaseMixin) -> 'Expression':
+ return self._binary(init_addition_expr, self, other)
+
+ def __getattr__(self, name):
+ attr = getattr(self.underlying, name)
+
+ if isinstance(attr, ExpressionBaseMixin):
+ return dataclasses.replace(
+ self,
+ underlying=attr,
+ )
+
+ else:
+ return attr
+
+ def __getitem__(self, key: tuple[int, int]):
+ return dataclasses.replace(
+ self,
+ underlying=init_get_item_expr(
+ underlying=self.underlying,
+ index=key,
+ ),
+ )
+
+ def __matmul__(self, other: typing.Union[ExpressionBaseMixin, np.ndarray]) -> 'Expression':
+ return self._binary(init_matrix_mult_expr, self, other)
+
+ def __mul__(self, other) -> 'Expression':
+ return self._binary(init_elem_mult_expr, self, other)
+
+ def __pow__(self, num):
+ curr = 1
+
+ for _ in range(num):
+ curr = curr * self
+
+ return curr
+
+ def __neg__(self):
+ return self * (-1)
+
+ def __radd__(self, other):
+ return self._binary(init_addition_expr, other, self)
+
+ def __rmatmul__(self, other):
+ return self._binary(init_matrix_mult_expr, other, self)
+
+ def __rmul__(self, other):
+ return self * other
+
+ def __rsub__(self, other):
+ return other + (-self)
+
+ def __sub__(self, other):
+ return self + (-other)
+
+ def __truediv__(self, other: ExpressionBaseMixin):
+ return self._binary(init_division_expr, self, other)
+
+ @staticmethod
+ def _binary(op, left, right):
+ if not isinstance(left, Expression):
+ left = init_from_expr_or_none(left)
+
+ if left is None:
+ return NotImplemented
+
+ return dataclasses.replace(
+ right,
+ underlying=op(left, right),
+ )
+
+ else:
+ right = init_from_expr_or_none(right)
+
+ if right is None:
+ return NotImplemented
+
+ return dataclasses.replace(
+ left,
+ underlying=op(left, right),
+ )
+
+ # def _convert_to_expression(self, other):
+ # result = init_from_expr_or_none(other)
+
+ # if result is None:
+ # return NotImplemented
+
+ # return result
+
+ def cache(self) -> 'Expression':
+ return dataclasses.replace(
+ self,
+ underlying=init_cache_expr(
+ underlying=self.underlying,
+ ),
+ )
+
+ # only applies to monomials and variables
+ def combinations(self, number: int):
+ return dataclasses.replace(
+ self,
+ underlying=init_combinations_expr(
+ monomials=self.underlying,
+ number=number,
+ ),
+ )
+
+ def determinant(self) -> 'Expression':
+ return dataclasses.replace(
+ self,
+ underlying=init_determinant_expr(
+ underlying=self.underlying,
+ ),
+ )
+
+ def diag(self):
+ return dataclasses.replace(
+ self,
+ underlying=init_diag_expr(
+ underlying=self.underlying,
+ ),
+ )
+
+ def diff(
+ self,
+ variables: 'Expression',
+ introduce_derivatives: bool = None,
+ ) -> 'Expression':
+ return dataclasses.replace(
+ self,
+ underlying=init_derivative_expr(
+ underlying=self.underlying,
+ variables=variables,
+ introduce_derivatives=introduce_derivatives,
+ ),
+ )
+
+ def divergence(
+ self,
+ variables: tuple,
+ ) -> 'Expression':
+ return dataclasses.replace(
+ self,
+ underlying=init_divergence_expr(
+ underlying=self.underlying,
+ variables=variables,
+ ),
+ )
+
+ def eval(
+ self,
+ variable: tuple,
+ value: tuple[float, ...] = None,
+ ) -> 'Expression':
+ return dataclasses.replace(
+ self,
+ underlying=init_eval_expr(
+ underlying=self.underlying,
+ variables=variable,
+ values=value,
+ ),
+ )
+
+ # also applies to monomials (and variables?)
+ def filter(
+ self,
+ predicator: 'Expression',
+ inverse: bool = None,
+ ) -> 'Expression':
+ return dataclasses.replace(
+ self,
+ underlying=init_filter_expr(
+ underlying=self.underlying,
+ predicator=predicator,
+ inverse=inverse,
+ ),
+ )
+
+ # only applies to symmetric matrix
+ def from_symmetric_matrix(self) -> 'Expression':
+ return dataclasses.replace(
+ self,
+ underlying=init_from_symmetric_matrix_expr(
+ underlying=self.underlying,
+ ),
+ )
+
+ # only applies to monomials
+ def half_newton_polytope(
+ self,
+ variables: 'Expression',
+ filter: 'Expression | None' = None,
+ ) -> 'Expression':
+ return dataclasses.replace(
+ self,
+ underlying=init_half_newton_polytope_expr(
+ monomials=self.underlying,
+ variables=variables,
+ filter=filter,
+ ),
+ )
+
+ def linear_matrix_in(self, variable: 'Expression') -> 'Expression':
+ return dataclasses.replace(
+ self,
+ underlying=init_linear_matrix_in_expr(
+ underlying=self.underlying,
+ variable=variable,
+ ),
+ )
+
+ def linear_monomials(self, variables: 'Expression') -> 'Expression':
+ return dataclasses.replace(
+ self,
+ underlying=init_linear_monomials_expr(
+ underlying=self.underlying,
+ variables=variables,
+ ),
+ )
+
+ def linear_in(
+ self,
+ variables: 'Expression',
+ monomials: 'Expression' = None,
+ ignore_unmatched: bool = None,
+ ) -> 'Expression':
+ if monomials is None:
+ monomials = self.linear_monomials(variables)
+
+ return dataclasses.replace(
+ self,
+ underlying=init_linear_in_expr(
+ underlying=self.underlying,
+ monomials=monomials,
+ variables=variables,
+ ignore_unmatched=ignore_unmatched,
+ ),
+ )
+
+ def max(self) -> 'Expression':
+ return dataclasses.replace(
+ self,
+ underlying=init_max_expr(
+ underlying=self.underlying,
+ ),
+ )
+
+ def max_degree(self) -> 'Expression':
+ return dataclasses.replace(
+ self,
+ underlying=init_max_degree_expr(
+ underlying=self.underlying,
+ ),
+ )
+
+ def parametrize(self, name: str = None) -> 'Expression':
+ return dataclasses.replace(
+ self,
+ underlying=init_parametrize_expr(
+ underlying=self.underlying,
+ name=name,
+ ),
+ )
+
+ # def parametrize_matrix(self, name: str = None) -> 'ExpressionMixin':
+ # return dataclasses.replace(
+ # self,
+ # underlying=init_parametrize_matrix_expr(
+ # underlying=self.underlying,
+ # name=name,
+ # ),
+ # )
+
+ def quadratic_in(self, variables: 'Expression', monomials: 'Expression' = None) -> 'Expression':
+ if monomials is None:
+ monomials = self.quadratic_monomials(variables)
+
+ return dataclasses.replace(
+ self,
+ underlying=init_quadratic_in_expr(
+ underlying=self.underlying,
+ monomials=monomials,
+ variables=variables,
+ ),
+ )
+
+ def quadratic_monomials(
+ self,
+ variables: 'Expression',
+ ) -> 'Expression':
+ return dataclasses.replace(
+ self,
+ underlying=init_quadratic_monomials_expr(
+ underlying=self.underlying,
+ variables=variables,
+ ),
+ )
+
+ def reshape(self, n: int, m: int) -> 'Expression':
+ return dataclasses.replace(
+ self,
+ underlying=init_reshape_expr(
+ underlying=self.underlying,
+ new_shape=(n, m),
+ ),
+ )
+
+ def rep_mat(self, n: int, m: int) -> 'Expression':
+ return dataclasses.replace(
+ self,
+ underlying=init_rep_mat_expr(
+ underlying=self.underlying,
+ repetition=(n, m),
+ ),
+ )
+
+ def set_element_at(
+ self,
+ row: int,
+ col: int,
+ value: 'Expression',
+ ) -> 'Expression':
+ if isinstance(value, Expression):
+ value = value.underlying
+ else:
+ value = init_from_sympy_expr(value)
+
+ return dataclasses.replace(
+ self,
+ underlying=init_set_element_at_expr(
+ underlying=self.underlying,
+ index=(row, col),
+ value=value,
+ ),
+ )
+
+ #todo: remove?
+ def squeeze(
+ self,
+ ) -> 'Expression':
+ return dataclasses.replace(
+ self,
+ underlying=init_squeeze_expr(
+ underlying=self.underlying,
+ ),
+ )
+
+ # only applies to monomials
+ def subtract_monomials(
+ self,
+ monomials: 'Expression',
+ ) -> 'Expression':
+ return dataclasses.replace(
+ self,
+ underlying=init_subtract_monomials_expr(
+ underlying=self.underlying,
+ monomials=monomials,
+ ),
+ )
+
+ def substitute(
+ self,
+ variable: tuple,
+ values: tuple['Expression', ...] = None,
+ ) -> 'Expression':
+ return dataclasses.replace(
+ self,
+ underlying=init_substitute_expr(
+ underlying=self.underlying,
+ variables=variable,
+ values=values,
+ ),
+ )
+
+ def subs(
+ self,
+ variable: tuple,
+ values: tuple['Expression', ...] = None,
+ ) -> 'Expression':
+ return self.substitute(
+ variable=variable,
+ values=values,
+ )
+
+ def sum(self):
+ return dataclasses.replace(
+ self,
+ underlying=init_sum_expr(
+ underlying=self.underlying,
+ ),
+ )
+
+ def symmetric(self):
+ return dataclasses.replace(
+ self,
+ underlying=init_symmetric_expr(
+ underlying=self.underlying,
+ ),
+ )
+
+ def transpose(self) -> 'Expression':
+ return dataclasses.replace(
+ self,
+ underlying=init_transpose_expr(
+ underlying=self.underlying,
+ ),
+ )
+
+ @property
+ def T(self) -> 'Expression':
+ return self.transpose()
+
+ def to_constant(self) -> 'Expression':
+ return dataclasses.replace(
+ self,
+ underlying=init_to_constant_expr(
+ underlying=self.underlying,
+ ),
+ )
+
+ # def to_quadratic(self) -> 'ExpressionMixin':
+ # return dataclasses.replace(
+ # self,
+ # underlying=init_to_quadratic_expr(
+ # underlying=self.underlying,
+ # ),
+ # )
+
+ def to_symmetric_matrix(self) -> 'Expression':
+ return dataclasses.replace(
+ self,
+ underlying=init_to_symmetric_matrix_expr(
+ underlying=self.underlying,
+ ),
+ )
+
+ # only applies to variables
+ def to_sorted_variables(self) -> 'Expression':
+ return dataclasses.replace(
+ self,
+ underlying=init_to_sorted_variables(
+ underlying=self.underlying,
+ ),
+ )
+
+ # also applies to monomials?
+ def truncate(
+ self,
+ variables: tuple,
+ degrees: tuple[int],
+ inverse: bool = None,
+ ):
+ return dataclasses.replace(
+ self,
+ underlying=init_truncate_expr(
+ underlying=self.underlying,
+ variables=variables,
+ degrees=degrees,
+ inverse=inverse,
+ ),
+ )
+
+
+@dataclassabc.dataclassabc(frozen=True, repr=False)
+class ExpressionImpl(Expression):
+ underlying: ExpressionBaseMixin
+
+ def __repr__(self) -> str:
+ return self.underlying.__repr__()
diff --git a/polymatrix/expression/eyeexpr.py b/polymatrix/expression/eyeexpr.py
deleted file mode 100644
index 4e64569..0000000
--- a/polymatrix/expression/eyeexpr.py
+++ /dev/null
@@ -1,4 +0,0 @@
-from polymatrix.expression.mixins.eyeexprmixin import EyeExprMixin
-
-class EyeExpr(EyeExprMixin):
- pass
diff --git a/polymatrix/expression/filterexpr.py b/polymatrix/expression/filterexpr.py
deleted file mode 100644
index e7ca235..0000000
--- a/polymatrix/expression/filterexpr.py
+++ /dev/null
@@ -1,4 +0,0 @@
-from polymatrix.expression.mixins.filterexprmixin import FilterExprMixin
-
-class FilterExpr(FilterExprMixin):
- pass
diff --git a/polymatrix/expression/fromsymmetricmatrixexpr.py b/polymatrix/expression/fromsymmetricmatrixexpr.py
deleted file mode 100644
index 8ddf2ef..0000000
--- a/polymatrix/expression/fromsymmetricmatrixexpr.py
+++ /dev/null
@@ -1,4 +0,0 @@
-from polymatrix.expression.mixins.fromsymmetricmatrixexprmixin import FromSymmetricMatrixExprMixin
-
-class FromSymmetricMatrixExpr(FromSymmetricMatrixExprMixin):
- pass
diff --git a/polymatrix/expression/fromsympyexpr.py b/polymatrix/expression/fromsympyexpr.py
deleted file mode 100644
index b1e723a..0000000
--- a/polymatrix/expression/fromsympyexpr.py
+++ /dev/null
@@ -1,4 +0,0 @@
-from polymatrix.expression.mixins.fromsympyexprmixin import FromSympyExprMixin
-
-class FromSympyExpr(FromSympyExprMixin):
- pass
diff --git a/polymatrix/expression/fromtermsexpr.py b/polymatrix/expression/fromtermsexpr.py
deleted file mode 100644
index 2dbb5aa..0000000
--- a/polymatrix/expression/fromtermsexpr.py
+++ /dev/null
@@ -1,4 +0,0 @@
-from polymatrix.expression.mixins.fromtermsexprmixin import FromTermsExprMixin
-
-class FromTermsExpr(FromTermsExprMixin):
- pass
diff --git a/polymatrix/expression/getitemexpr.py b/polymatrix/expression/getitemexpr.py
deleted file mode 100644
index e7d32c2..0000000
--- a/polymatrix/expression/getitemexpr.py
+++ /dev/null
@@ -1,4 +0,0 @@
-from polymatrix.expression.mixins.getitemexprmixin import GetItemExprMixin
-
-class GetItemExpr(GetItemExprMixin):
- pass
diff --git a/polymatrix/expression/halfnewtonpolytopeexpr.py b/polymatrix/expression/halfnewtonpolytopeexpr.py
deleted file mode 100644
index 8240d45..0000000
--- a/polymatrix/expression/halfnewtonpolytopeexpr.py
+++ /dev/null
@@ -1,4 +0,0 @@
-from polymatrix.expression.mixins.halfnewtonpolytopeexprmixin import HalfNewtonPolytopeExprMixin
-
-class HalfNewtonPolytopeExpr(HalfNewtonPolytopeExprMixin):
- pass
diff --git a/polymatrix/expression/impl/__init__.py b/polymatrix/expression/impl/__init__.py
deleted file mode 100644
index e69de29..0000000
--- a/polymatrix/expression/impl/__init__.py
+++ /dev/null
diff --git a/polymatrix/expression/impl/additionexprimpl.py b/polymatrix/expression/impl/additionexprimpl.py
deleted file mode 100644
index 2fd7220..0000000
--- a/polymatrix/expression/impl/additionexprimpl.py
+++ /dev/null
@@ -1,9 +0,0 @@
-import dataclass_abc
-from polymatrix.expression.additionexpr import AdditionExpr
-
-from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
-
-@dataclass_abc.dataclass_abc(frozen=True)
-class AdditionExprImpl(AdditionExpr):
- left: ExpressionBaseMixin
- right: ExpressionBaseMixin
diff --git a/polymatrix/expression/impl/blockdiagexprimpl.py b/polymatrix/expression/impl/blockdiagexprimpl.py
deleted file mode 100644
index a2707d8..0000000
--- a/polymatrix/expression/impl/blockdiagexprimpl.py
+++ /dev/null
@@ -1,7 +0,0 @@
-import dataclass_abc
-from polymatrix.expression.blockdiagexpr import BlockDiagExpr
-
-
-@dataclass_abc.dataclass_abc(frozen=True)
-class BlockDiagExprImpl(BlockDiagExpr):
- underlying: tuple
diff --git a/polymatrix/expression/impl/cacheexprimpl.py b/polymatrix/expression/impl/cacheexprimpl.py
deleted file mode 100644
index 4ca4bf2..0000000
--- a/polymatrix/expression/impl/cacheexprimpl.py
+++ /dev/null
@@ -1,9 +0,0 @@
-import dataclass_abc
-from polymatrix.expression.cacheexpr import CacheExpr
-
-from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
-
-# @dataclass_abc.dataclass_abc(frozen=True, eq=False)
-@dataclass_abc.dataclass_abc(frozen=True)
-class CacheExprImpl(CacheExpr):
- underlying: ExpressionBaseMixin
diff --git a/polymatrix/expression/impl/combinationsexprimpl.py b/polymatrix/expression/impl/combinationsexprimpl.py
deleted file mode 100644
index 2438e01..0000000
--- a/polymatrix/expression/impl/combinationsexprimpl.py
+++ /dev/null
@@ -1,9 +0,0 @@
-import dataclass_abc
-from polymatrix.expression.combinationsexpr import CombinationsExpr
-
-from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
-
-@dataclass_abc.dataclass_abc(frozen=True)
-class CombinationsExprImpl(CombinationsExpr):
- monomials: ExpressionBaseMixin
- number: int
diff --git a/polymatrix/expression/impl/derivativeexprimpl.py b/polymatrix/expression/impl/derivativeexprimpl.py
deleted file mode 100644
index 87884ab..0000000
--- a/polymatrix/expression/impl/derivativeexprimpl.py
+++ /dev/null
@@ -1,10 +0,0 @@
-import dataclass_abc
-from polymatrix.expression.derivativeexpr import DerivativeExpr
-
-from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
-
-@dataclass_abc.dataclass_abc(frozen=True)
-class DerivativeExprImpl(DerivativeExpr):
- underlying: ExpressionBaseMixin
- variables: tuple
- introduce_derivatives: bool
diff --git a/polymatrix/expression/impl/determinantexprimpl.py b/polymatrix/expression/impl/determinantexprimpl.py
deleted file mode 100644
index 3dc4ace..0000000
--- a/polymatrix/expression/impl/determinantexprimpl.py
+++ /dev/null
@@ -1,8 +0,0 @@
-import dataclass_abc
-from polymatrix.expression.determinantexpr import DeterminantExpr
-
-from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
-
-@dataclass_abc.dataclass_abc(frozen=True)
-class DeterminantExprImpl(DeterminantExpr):
- underlying: ExpressionBaseMixin
diff --git a/polymatrix/expression/impl/diagexprimpl.py b/polymatrix/expression/impl/diagexprimpl.py
deleted file mode 100644
index 950f2b8..0000000
--- a/polymatrix/expression/impl/diagexprimpl.py
+++ /dev/null
@@ -1,8 +0,0 @@
-import dataclass_abc
-from polymatrix.expression.diagexpr import DiagExpr
-
-from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
-
-@dataclass_abc.dataclass_abc(frozen=True)
-class DiagExprImpl(DiagExpr):
- underlying: ExpressionBaseMixin
diff --git a/polymatrix/expression/impl/divergenceexprimpl.py b/polymatrix/expression/impl/divergenceexprimpl.py
deleted file mode 100644
index 0ea9cdb..0000000
--- a/polymatrix/expression/impl/divergenceexprimpl.py
+++ /dev/null
@@ -1,10 +0,0 @@
-import dataclass_abc
-from polymatrix.expression.divergenceexpr import DivergenceExpr
-
-from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
-from typing import Union
-
-@dataclass_abc.dataclass_abc(frozen=True)
-class DivergenceExprImpl(DivergenceExpr):
- underlying: ExpressionBaseMixin
- variables: tuple
diff --git a/polymatrix/expression/impl/divisionexprimpl.py b/polymatrix/expression/impl/divisionexprimpl.py
deleted file mode 100644
index 639210e..0000000
--- a/polymatrix/expression/impl/divisionexprimpl.py
+++ /dev/null
@@ -1,9 +0,0 @@
-import dataclass_abc
-from polymatrix.expression.divisionexpr import DivisionExpr
-
-from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
-
-@dataclass_abc.dataclass_abc(frozen=True, eq=False)
-class DivisionExprImpl(DivisionExpr):
- left: ExpressionBaseMixin
- right: ExpressionBaseMixin
diff --git a/polymatrix/expression/impl/elemmultexprimpl.py b/polymatrix/expression/impl/elemmultexprimpl.py
deleted file mode 100644
index a9990e4..0000000
--- a/polymatrix/expression/impl/elemmultexprimpl.py
+++ /dev/null
@@ -1,9 +0,0 @@
-import dataclass_abc
-from polymatrix.expression.elemmultexpr import ElemMultExpr
-
-from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
-
-@dataclass_abc.dataclass_abc(frozen=True)
-class ElemMultExprImpl(ElemMultExpr):
- left: ExpressionBaseMixin
- right: ExpressionBaseMixin
diff --git a/polymatrix/expression/impl/evalexprimpl.py b/polymatrix/expression/impl/evalexprimpl.py
deleted file mode 100644
index 7f13a78..0000000
--- a/polymatrix/expression/impl/evalexprimpl.py
+++ /dev/null
@@ -1,10 +0,0 @@
-import dataclass_abc
-from polymatrix.expression.evalexpr import EvalExpr
-
-from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
-
-@dataclass_abc.dataclass_abc(frozen=True)
-class EvalExprImpl(EvalExpr):
- underlying: ExpressionBaseMixin
- substitutions: tuple
- # values: tuple
diff --git a/polymatrix/expression/impl/expressionimpl.py b/polymatrix/expression/impl/expressionimpl.py
deleted file mode 100644
index 6f140b5..0000000
--- a/polymatrix/expression/impl/expressionimpl.py
+++ /dev/null
@@ -1,11 +0,0 @@
-import dataclass_abc
-from polymatrix.expression.expression import Expression
-
-from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
-
-@dataclass_abc.dataclass_abc(frozen=True, repr=False)
-class ExpressionImpl(Expression):
- underlying: ExpressionBaseMixin
-
- def __repr__(self) -> str:
- return self.underlying.__repr__()
diff --git a/polymatrix/expression/impl/eyeexprimpl.py b/polymatrix/expression/impl/eyeexprimpl.py
deleted file mode 100644
index 9c50f8a..0000000
--- a/polymatrix/expression/impl/eyeexprimpl.py
+++ /dev/null
@@ -1,8 +0,0 @@
-import dataclass_abc
-from polymatrix.expression.eyeexpr import EyeExpr
-
-from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
-
-@dataclass_abc.dataclass_abc(frozen=True)
-class EyeExprImpl(EyeExpr):
- variable: ExpressionBaseMixin
diff --git a/polymatrix/expression/impl/filterexprimpl.py b/polymatrix/expression/impl/filterexprimpl.py
deleted file mode 100644
index 547ad9e..0000000
--- a/polymatrix/expression/impl/filterexprimpl.py
+++ /dev/null
@@ -1,10 +0,0 @@
-import dataclass_abc
-from polymatrix.expression.filterexpr import FilterExpr
-
-from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
-
-@dataclass_abc.dataclass_abc(frozen=True)
-class FilterExprImpl(FilterExpr):
- underlying: ExpressionBaseMixin
- predicator: ExpressionBaseMixin
- inverse: bool == None
diff --git a/polymatrix/expression/impl/fromsymmetricmatrixexprimpl.py b/polymatrix/expression/impl/fromsymmetricmatrixexprimpl.py
deleted file mode 100644
index 1c54162..0000000
--- a/polymatrix/expression/impl/fromsymmetricmatrixexprimpl.py
+++ /dev/null
@@ -1,8 +0,0 @@
-import dataclass_abc
-from polymatrix.expression.fromsymmetricmatrixexpr import FromSymmetricMatrixExpr
-
-from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
-
-@dataclass_abc.dataclass_abc(frozen=True)
-class FromSymmetricMatrixExprImpl(FromSymmetricMatrixExpr):
- underlying: ExpressionBaseMixin
diff --git a/polymatrix/expression/impl/fromsympyexprimpl.py b/polymatrix/expression/impl/fromsympyexprimpl.py
deleted file mode 100644
index 986612b..0000000
--- a/polymatrix/expression/impl/fromsympyexprimpl.py
+++ /dev/null
@@ -1,7 +0,0 @@
-import dataclass_abc
-from polymatrix.expression.fromsympyexpr import FromSympyExpr
-
-
-@dataclass_abc.dataclass_abc(frozen=True)
-class FromSympyExprImpl(FromSympyExpr):
- data: tuple[tuple[float]]
diff --git a/polymatrix/expression/impl/fromtermsexprimpl.py b/polymatrix/expression/impl/fromtermsexprimpl.py
deleted file mode 100644
index 92bb6a7..0000000
--- a/polymatrix/expression/impl/fromtermsexprimpl.py
+++ /dev/null
@@ -1,8 +0,0 @@
-import dataclass_abc
-from polymatrix.expression.fromtermsexpr import FromTermsExpr
-
-
-@dataclass_abc.dataclass_abc(frozen=True)
-class FromTermsExprImpl(FromTermsExpr):
- terms: tuple
- shape: tuple[int, int]
diff --git a/polymatrix/expression/impl/getitemexprimpl.py b/polymatrix/expression/impl/getitemexprimpl.py
deleted file mode 100644
index 578d4c7..0000000
--- a/polymatrix/expression/impl/getitemexprimpl.py
+++ /dev/null
@@ -1,9 +0,0 @@
-import dataclass_abc
-from polymatrix.expression.getitemexpr import GetItemExpr
-
-from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
-
-@dataclass_abc.dataclass_abc(frozen=True)
-class GetItemExprImpl(GetItemExpr):
- underlying: ExpressionBaseMixin
- index: tuple[tuple[int, ...], tuple[int, ...]]
diff --git a/polymatrix/expression/impl/halfnewtonpolytopeexprimpl.py b/polymatrix/expression/impl/halfnewtonpolytopeexprimpl.py
deleted file mode 100644
index 6fef1da..0000000
--- a/polymatrix/expression/impl/halfnewtonpolytopeexprimpl.py
+++ /dev/null
@@ -1,10 +0,0 @@
-import dataclass_abc
-from polymatrix.expression.halfnewtonpolytopeexpr import HalfNewtonPolytopeExpr
-
-from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
-
-@dataclass_abc.dataclass_abc(frozen=True)
-class HalfNewtonPolytopeExprImpl(HalfNewtonPolytopeExpr):
- monomials: ExpressionBaseMixin
- variables: ExpressionBaseMixin
- filter: ExpressionBaseMixin | None
diff --git a/polymatrix/expression/impl/impl.py b/polymatrix/expression/impl/impl.py
new file mode 100644
index 0000000..7a919e5
--- /dev/null
+++ b/polymatrix/expression/impl/impl.py
@@ -0,0 +1,320 @@
+import dataclassabc
+
+from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
+from polymatrix.expression.mixins.additionexprmixin import AdditionExprMixin
+from polymatrix.expression.mixins.blockdiagexprmixin import BlockDiagExprMixin
+from polymatrix.expression.mixins.cacheexprmixin import CacheExprMixin
+from polymatrix.expression.mixins.combinationsexprmixin import \
+ CombinationsExprMixin
+from polymatrix.expression.mixins.derivativeexprmixin import \
+ DerivativeExprMixin
+from polymatrix.expression.mixins.determinantexprmixin import \
+ DeterminantExprMixin
+from polymatrix.expression.mixins.diagexprmixin import DiagExprMixin
+from polymatrix.expression.mixins.divergenceexprmixin import \
+ DivergenceExprMixin
+from polymatrix.expression.mixins.divisionexprmixin import DivisionExprMixin
+from polymatrix.expression.mixins.elemmultexprmixin import ElemMultExprMixin
+from polymatrix.expression.mixins.evalexprmixin import EvalExprMixin
+from polymatrix.expression.mixins.eyeexprmixin import EyeExprMixin
+from polymatrix.expression.mixins.filterexprmixin import FilterExprMixin
+from polymatrix.expression.mixins.fromsymmetricmatrixexprmixin import \
+ FromSymmetricMatrixExprMixin
+from polymatrix.expression.mixins.fromsympyexprmixin import FromSympyExprMixin
+from polymatrix.expression.mixins.fromtermsexprmixin import FromTermsExprMixin
+from polymatrix.expression.mixins.getitemexprmixin import GetItemExprMixin
+from polymatrix.expression.mixins.halfnewtonpolytopeexprmixin import \
+ HalfNewtonPolytopeExprMixin
+from polymatrix.expression.mixins.linearinexprmixin import LinearInExprMixin
+from polymatrix.expression.mixins.linearmatrixinexprmixin import \
+ LinearMatrixInExprMixin
+from polymatrix.expression.mixins.linearmonomialsexprmixin import \
+ LinearMonomialsExprMixin
+from polymatrix.expression.mixins.matrixmultexprmixin import \
+ MatrixMultExprMixin
+from polymatrix.expression.mixins.maxdegreeexprmixin import MaxDegreeExprMixin
+from polymatrix.expression.mixins.maxexprmixin import MaxExprMixin
+from polymatrix.expression.mixins.parametrizeexprmixin import \
+ ParametrizeExprMixin
+from polymatrix.expression.mixins.parametrizematrixexprmixin import \
+ ParametrizeMatrixExprMixin
+from polymatrix.expression.mixins.quadraticinexprmixin import \
+ QuadraticInExprMixin
+from polymatrix.expression.mixins.quadraticmonomialsexprmixin import \
+ QuadraticMonomialsExprMixin
+from polymatrix.expression.mixins.repmatexprmixin import RepMatExprMixin
+from polymatrix.expression.mixins.reshapeexprmixin import ReshapeExprMixin
+from polymatrix.expression.mixins.setelementatexprmixin import \
+ SetElementAtExprMixin
+from polymatrix.expression.mixins.squeezeexprmixin import SqueezeExprMixin
+from polymatrix.expression.mixins.substituteexprmixin import \
+ SubstituteExprMixin
+from polymatrix.expression.mixins.subtractmonomialsexprmixin import \
+ SubtractMonomialsExprMixin
+from polymatrix.expression.mixins.sumexprmixin import SumExprMixin
+from polymatrix.expression.mixins.symmetricexprmixin import SymmetricExprMixin
+from polymatrix.expression.mixins.toconstantexprmixin import \
+ ToConstantExprMixin
+from polymatrix.expression.mixins.toquadraticexprmixin import \
+ ToQuadraticExprMixin
+from polymatrix.expression.mixins.tosymmetricmatrixexprmixin import \
+ ToSymmetricMatrixExprMixin
+from polymatrix.expression.mixins.transposeexprmixin import TransposeExprMixin
+from polymatrix.expression.mixins.truncateexprmixin import TruncateExprMixin
+from polymatrix.expression.mixins.vstackexprmixin import VStackExprMixin
+from polymatrix.expression.mixins.tosortedvariablesmixin import ToSortedVariablesExprMixin
+
+
+@dataclassabc.dataclassabc(frozen=True)
+class AdditionExprImpl(AdditionExprMixin):
+ left: ExpressionBaseMixin
+ right: ExpressionBaseMixin
+
+
+@dataclassabc.dataclassabc(frozen=True)
+class BlockDiagExprImpl(BlockDiagExprMixin):
+ underlying: tuple
+
+
+# @dataclassabc.dataclassabc(frozen=True, eq=False)
+@dataclassabc.dataclassabc(frozen=True)
+class CacheExprImpl(CacheExprMixin):
+ underlying: ExpressionBaseMixin
+
+
+@dataclassabc.dataclassabc(frozen=True)
+class CombinationsExprImpl(CombinationsExprMixin):
+ monomials: ExpressionBaseMixin
+ number: int
+
+
+@dataclassabc.dataclassabc(frozen=True)
+class DerivativeExprImpl(DerivativeExprMixin):
+ underlying: ExpressionBaseMixin
+ variables: tuple
+ introduce_derivatives: bool
+
+
+@dataclassabc.dataclassabc(frozen=True)
+class DeterminantExprImpl(DeterminantExprMixin):
+ underlying: ExpressionBaseMixin
+
+
+@dataclassabc.dataclassabc(frozen=True)
+class DiagExprImpl(DiagExprMixin):
+ underlying: ExpressionBaseMixin
+
+
+@dataclassabc.dataclassabc(frozen=True)
+class DivergenceExprImpl(DivergenceExprMixin):
+ underlying: ExpressionBaseMixin
+ variables: tuple
+
+
+@dataclassabc.dataclassabc(frozen=True, eq=False)
+class DivisionExprImpl(DivisionExprMixin):
+ left: ExpressionBaseMixin
+ right: ExpressionBaseMixin
+
+
+@dataclassabc.dataclassabc(frozen=True)
+class ElemMultExprImpl(ElemMultExprMixin):
+ left: ExpressionBaseMixin
+ right: ExpressionBaseMixin
+
+
+@dataclassabc.dataclassabc(frozen=True)
+class EvalExprImpl(EvalExprMixin):
+ underlying: ExpressionBaseMixin
+ substitutions: tuple
+
+
+@dataclassabc.dataclassabc(frozen=True)
+class EyeExprImpl(EyeExprMixin):
+ variable: ExpressionBaseMixin
+
+
+@dataclassabc.dataclassabc(frozen=True)
+class FilterExprImpl(FilterExprMixin):
+ underlying: ExpressionBaseMixin
+ predicator: ExpressionBaseMixin
+ inverse: bool == None
+
+
+@dataclassabc.dataclassabc(frozen=True)
+class FromSymmetricMatrixExprImpl(FromSymmetricMatrixExprMixin):
+ underlying: ExpressionBaseMixin
+
+
+@dataclassabc.dataclassabc(frozen=True)
+class FromSympyExprImpl(FromSympyExprMixin):
+ data: tuple[tuple[float]]
+
+
+@dataclassabc.dataclassabc(frozen=True)
+class FromTermsExprImpl(FromTermsExprMixin):
+ terms: tuple
+ shape: tuple[int, int]
+
+
+@dataclassabc.dataclassabc(frozen=True)
+class GetItemExprImpl(GetItemExprMixin):
+ underlying: ExpressionBaseMixin
+ index: tuple[tuple[int, ...], tuple[int, ...]]
+
+
+@dataclassabc.dataclassabc(frozen=True)
+class HalfNewtonPolytopeExprImpl(HalfNewtonPolytopeExprMixin):
+ monomials: ExpressionBaseMixin
+ variables: ExpressionBaseMixin
+ filter: ExpressionBaseMixin | None
+
+
+@dataclassabc.dataclassabc(frozen=True)
+class LinearInExprImpl(LinearInExprMixin):
+ underlying: ExpressionBaseMixin
+ monomials: ExpressionBaseMixin
+ variables: ExpressionBaseMixin
+ ignore_unmatched: bool
+
+
+@dataclassabc.dataclassabc(frozen=True)
+class LinearMatrixInExprImpl(LinearMatrixInExprMixin):
+ underlying: ExpressionBaseMixin
+ variable: int
+
+
+@dataclassabc.dataclassabc(frozen=True)
+class LinearMonomialsExprImpl(LinearMonomialsExprMixin):
+ underlying: ExpressionBaseMixin
+ variables: tuple
+
+
+@dataclassabc.dataclassabc(frozen=True)
+class MatrixMultExprImpl(MatrixMultExprMixin):
+ left: ExpressionBaseMixin
+ right: ExpressionBaseMixin
+
+
+@dataclassabc.dataclassabc(frozen=True)
+class MaxDegreeExprImpl(MaxDegreeExprMixin):
+ underlying: ExpressionBaseMixin
+
+
+@dataclassabc.dataclassabc(frozen=True)
+class MaxExprImpl(MaxExprMixin):
+ underlying: ExpressionBaseMixin
+
+
+# @dataclassabc.dataclassabc(frozen=True, eq=False, repr=False)
+@dataclassabc.dataclassabc(frozen=True, repr=False)
+class ParametrizeExprImpl(ParametrizeExprMixin):
+ underlying: ExpressionBaseMixin
+ name: str
+
+ def __repr__(self) -> str:
+ return f'{self.__class__.__name__}(name={repr(self.name)})'
+
+
+@dataclassabc.dataclassabc(frozen=True)
+class ParametrizeMatrixExprImpl(ParametrizeMatrixExprMixin):
+ underlying: ExpressionBaseMixin
+ name: str
+
+
+@dataclassabc.dataclassabc(frozen=True)
+class QuadraticInExprImpl(QuadraticInExprMixin):
+ underlying: ExpressionBaseMixin
+ monomials: ExpressionBaseMixin
+ variables: tuple
+
+
+@dataclassabc.dataclassabc(frozen=True)
+class QuadraticMonomialsExprImpl(QuadraticMonomialsExprMixin):
+ underlying: ExpressionBaseMixin
+ variables: tuple
+
+
+@dataclassabc.dataclassabc(frozen=True)
+class RepMatExprImpl(RepMatExprMixin):
+ underlying: ExpressionBaseMixin
+ repetition: tuple
+
+
+# @dataclassabc.dataclassabc(frozen=True)
+# class ReshapeExprImpl(ReshapeExprMixin):
+# underlying: ExpressionBaseMixin
+# new_shape: tuple
+
+
+@dataclassabc.dataclassabc(frozen=True)
+class SetElementAtExprImpl(SetElementAtExprMixin):
+ underlying: ExpressionBaseMixin
+ index: tuple
+ value: ExpressionBaseMixin
+
+
+@dataclassabc.dataclassabc(frozen=True)
+class SqueezeExprImpl(SqueezeExprMixin):
+ underlying: ExpressionBaseMixin
+
+
+@dataclassabc.dataclassabc(frozen=True)
+class SubstituteExprImpl(SubstituteExprMixin):
+ underlying: ExpressionBaseMixin
+ # variables: tuple
+ substitutions: tuple
+
+
+@dataclassabc.dataclassabc(frozen=True)
+class SubtractMonomialsExprImpl(SubtractMonomialsExprMixin):
+ underlying: ExpressionBaseMixin
+ monomials: ExpressionBaseMixin
+
+
+@dataclassabc.dataclassabc(frozen=True)
+class SumExprImpl(SumExprMixin):
+ underlying: ExpressionBaseMixin
+
+
+@dataclassabc.dataclassabc(frozen=True)
+class SymmetricExprImpl(SymmetricExprMixin):
+ underlying: ExpressionBaseMixin
+
+
+@dataclassabc.dataclassabc(frozen=True)
+class ToConstantExprImpl(ToConstantExprMixin):
+ underlying: ExpressionBaseMixin
+
+
+@dataclassabc.dataclassabc(frozen=True)
+class ToQuadraticExprImpl(ToQuadraticExprMixin):
+ underlying: ExpressionBaseMixin
+
+
+@dataclassabc.dataclassabc(frozen=True)
+class ToSortedVariablesImpl(ToSortedVariablesExprMixin):
+ underlying: ExpressionBaseMixin
+
+
+@dataclassabc.dataclassabc(frozen=True)
+class ToSymmetricMatrixExprImpl(ToSymmetricMatrixExprMixin):
+ underlying: ExpressionBaseMixin
+
+
+@dataclassabc.dataclassabc(frozen=True)
+class TransposeExprImpl(TransposeExprMixin):
+ underlying: ExpressionBaseMixin
+
+
+@dataclassabc.dataclassabc(frozen=True)
+class TruncateExprImpl(TruncateExprMixin):
+ underlying: ExpressionBaseMixin
+ variables: ExpressionBaseMixin
+ degrees: tuple[int]
+ inverse: bool
+
+
+@dataclassabc.dataclassabc(frozen=True)
+class VStackExprImpl(VStackExprMixin):
+ underlying: tuple
diff --git a/polymatrix/expression/impl/linearinexprimpl.py b/polymatrix/expression/impl/linearinexprimpl.py
deleted file mode 100644
index 346b19b..0000000
--- a/polymatrix/expression/impl/linearinexprimpl.py
+++ /dev/null
@@ -1,11 +0,0 @@
-import dataclass_abc
-from polymatrix.expression.linearinexpr import LinearInExpr
-
-from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
-
-@dataclass_abc.dataclass_abc(frozen=True)
-class LinearInExprImpl(LinearInExpr):
- underlying: ExpressionBaseMixin
- monomials: ExpressionBaseMixin
- variables: ExpressionBaseMixin
- ignore_unmatched: bool
diff --git a/polymatrix/expression/impl/linearmatrixinexprimpl.py b/polymatrix/expression/impl/linearmatrixinexprimpl.py
deleted file mode 100644
index b40e6a6..0000000
--- a/polymatrix/expression/impl/linearmatrixinexprimpl.py
+++ /dev/null
@@ -1,9 +0,0 @@
-import dataclass_abc
-from polymatrix.expression.linearmatrixinexpr import LinearMatrixInExpr
-
-from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
-
-@dataclass_abc.dataclass_abc(frozen=True)
-class LinearMatrixInExprImpl(LinearMatrixInExpr):
- underlying: ExpressionBaseMixin
- variable: int
diff --git a/polymatrix/expression/impl/linearmonomialsexprimpl.py b/polymatrix/expression/impl/linearmonomialsexprimpl.py
deleted file mode 100644
index 905ec77..0000000
--- a/polymatrix/expression/impl/linearmonomialsexprimpl.py
+++ /dev/null
@@ -1,9 +0,0 @@
-import dataclass_abc
-from polymatrix.expression.linearmonomialsexpr import LinearMonomialsExpr
-
-from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
-
-@dataclass_abc.dataclass_abc(frozen=True)
-class LinearMonomialsExprImpl(LinearMonomialsExpr):
- underlying: ExpressionBaseMixin
- variables: tuple
diff --git a/polymatrix/expression/impl/matrixmultexprimpl.py b/polymatrix/expression/impl/matrixmultexprimpl.py
deleted file mode 100644
index 0b093ab..0000000
--- a/polymatrix/expression/impl/matrixmultexprimpl.py
+++ /dev/null
@@ -1,9 +0,0 @@
-import dataclass_abc
-from polymatrix.expression.matrixmultexpr import MatrixMultExpr
-
-from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
-
-@dataclass_abc.dataclass_abc(frozen=True)
-class MatrixMultExprImpl(MatrixMultExpr):
- left: ExpressionBaseMixin
- right: ExpressionBaseMixin
diff --git a/polymatrix/expression/impl/maxdegreeexprimpl.py b/polymatrix/expression/impl/maxdegreeexprimpl.py
deleted file mode 100644
index 5327659..0000000
--- a/polymatrix/expression/impl/maxdegreeexprimpl.py
+++ /dev/null
@@ -1,8 +0,0 @@
-import dataclass_abc
-from polymatrix.expression.maxdegreeexpr import MaxDegreeExpr
-
-from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
-
-@dataclass_abc.dataclass_abc(frozen=True)
-class MaxDegreeExprImpl(MaxDegreeExpr):
- underlying: ExpressionBaseMixin
diff --git a/polymatrix/expression/impl/maxexprimpl.py b/polymatrix/expression/impl/maxexprimpl.py
deleted file mode 100644
index ae2fe90..0000000
--- a/polymatrix/expression/impl/maxexprimpl.py
+++ /dev/null
@@ -1,8 +0,0 @@
-import dataclass_abc
-from polymatrix.expression.maxexpr import MaxExpr
-
-from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
-
-@dataclass_abc.dataclass_abc(frozen=True)
-class MaxExprImpl(MaxExpr):
- underlying: ExpressionBaseMixin
diff --git a/polymatrix/expression/impl/parametrizeexprimpl.py b/polymatrix/expression/impl/parametrizeexprimpl.py
deleted file mode 100644
index 4278a68..0000000
--- a/polymatrix/expression/impl/parametrizeexprimpl.py
+++ /dev/null
@@ -1,19 +0,0 @@
-import dataclass_abc
-from polymatrix.expression.parametrizeexpr import ParametrizeExpr
-
-from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
-
-# @dataclass_abc.dataclass_abc(frozen=True, eq=False, repr=False)
-@dataclass_abc.dataclass_abc(frozen=True, repr=False)
-class ParametrizeExprImpl(ParametrizeExpr):
- underlying: ExpressionBaseMixin
- name: str
-
- def __repr__(self) -> str:
- return f'{self.__class__.__name__}(name={repr(self.name)})'
-
- # def __eq__(self, other: object) -> bool:
- # return self.name == other.name
-
- # def __hash__(self) -> bool:
- # return hash(self.name)
diff --git a/polymatrix/expression/impl/quadraticinexprimpl.py b/polymatrix/expression/impl/quadraticinexprimpl.py
deleted file mode 100644
index da8fa21..0000000
--- a/polymatrix/expression/impl/quadraticinexprimpl.py
+++ /dev/null
@@ -1,10 +0,0 @@
-import dataclass_abc
-from polymatrix.expression.quadraticinexpr import QuadraticInExpr
-
-from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
-
-@dataclass_abc.dataclass_abc(frozen=True)
-class QuadraticInExprImpl(QuadraticInExpr):
- underlying: ExpressionBaseMixin
- monomials: ExpressionBaseMixin
- variables: tuple
diff --git a/polymatrix/expression/impl/quadraticmonomialsexprimpl.py b/polymatrix/expression/impl/quadraticmonomialsexprimpl.py
deleted file mode 100644
index 5930764..0000000
--- a/polymatrix/expression/impl/quadraticmonomialsexprimpl.py
+++ /dev/null
@@ -1,9 +0,0 @@
-import dataclass_abc
-from polymatrix.expression.quadraticmonomialsexpr import QuadraticMonomialsExpr
-
-from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
-
-@dataclass_abc.dataclass_abc(frozen=True)
-class QuadraticMonomialsExprImpl(QuadraticMonomialsExpr):
- underlying: ExpressionBaseMixin
- variables: tuple
diff --git a/polymatrix/expression/impl/repmatexprimpl.py b/polymatrix/expression/impl/repmatexprimpl.py
deleted file mode 100644
index f8cee79..0000000
--- a/polymatrix/expression/impl/repmatexprimpl.py
+++ /dev/null
@@ -1,9 +0,0 @@
-import dataclass_abc
-from polymatrix.expression.repmatexpr import RepMatExpr
-
-from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
-
-@dataclass_abc.dataclass_abc(frozen=True)
-class RepMatExprImpl(RepMatExpr):
- underlying: ExpressionBaseMixin
- repetition: tuple
diff --git a/polymatrix/expression/impl/reshapeexprimpl.py b/polymatrix/expression/impl/reshapeexprimpl.py
deleted file mode 100644
index 7c16f16..0000000
--- a/polymatrix/expression/impl/reshapeexprimpl.py
+++ /dev/null
@@ -1,9 +0,0 @@
-import dataclass_abc
-from polymatrix.expression.reshapeexpr import ReshapeExpr
-
-from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
-
-@dataclass_abc.dataclass_abc(frozen=True)
-class ReshapeExprImpl(ReshapeExpr):
- underlying: ExpressionBaseMixin
- new_shape: tuple
diff --git a/polymatrix/expression/impl/reshapeexprmixin.py b/polymatrix/expression/impl/reshapeexprmixin.py
new file mode 100644
index 0000000..00a93b8
--- /dev/null
+++ b/polymatrix/expression/impl/reshapeexprmixin.py
@@ -0,0 +1,10 @@
+import dataclassabc
+
+from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
+from polymatrix.expression.mixins.reshapeexprmixin import ReshapeExprMixin
+
+
+@dataclassabc.dataclassabc(frozen=True)
+class ReshapeExprImpl(ReshapeExprMixin):
+ underlying: ExpressionBaseMixin
+ new_shape: tuple
diff --git a/polymatrix/expression/impl/setelementatexprimpl.py b/polymatrix/expression/impl/setelementatexprimpl.py
deleted file mode 100644
index 6d070ac..0000000
--- a/polymatrix/expression/impl/setelementatexprimpl.py
+++ /dev/null
@@ -1,10 +0,0 @@
-import dataclass_abc
-from polymatrix.expression.setelementatexpr import SetElementAtExpr
-
-from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
-
-@dataclass_abc.dataclass_abc(frozen=True)
-class SetElementAtExprImpl(SetElementAtExpr):
- underlying: ExpressionBaseMixin
- index: tuple
- value: ExpressionBaseMixin
diff --git a/polymatrix/expression/impl/squeezeexprimpl.py b/polymatrix/expression/impl/squeezeexprimpl.py
deleted file mode 100644
index b60af68..0000000
--- a/polymatrix/expression/impl/squeezeexprimpl.py
+++ /dev/null
@@ -1,8 +0,0 @@
-import dataclass_abc
-from polymatrix.expression.squeezeexpr import SqueezeExpr
-
-from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
-
-@dataclass_abc.dataclass_abc(frozen=True)
-class SqueezeExprImpl(SqueezeExpr):
- underlying: ExpressionBaseMixin
diff --git a/polymatrix/expression/impl/substituteexprimpl.py b/polymatrix/expression/impl/substituteexprimpl.py
deleted file mode 100644
index 086f17e..0000000
--- a/polymatrix/expression/impl/substituteexprimpl.py
+++ /dev/null
@@ -1,10 +0,0 @@
-import dataclass_abc
-from polymatrix.expression.substituteexpr import SubstituteExpr
-
-from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
-
-@dataclass_abc.dataclass_abc(frozen=True)
-class SubstituteExprImpl(SubstituteExpr):
- underlying: ExpressionBaseMixin
- # variables: tuple
- substitutions: tuple
diff --git a/polymatrix/expression/impl/subtractmonomialsexprimpl.py b/polymatrix/expression/impl/subtractmonomialsexprimpl.py
deleted file mode 100644
index 211f7b1..0000000
--- a/polymatrix/expression/impl/subtractmonomialsexprimpl.py
+++ /dev/null
@@ -1,9 +0,0 @@
-import dataclass_abc
-from polymatrix.expression.subtractmonomialsexpr import SubtractMonomialsExpr
-
-from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
-
-@dataclass_abc.dataclass_abc(frozen=True)
-class SubtractMonomialsExprImpl(SubtractMonomialsExpr):
- underlying: ExpressionBaseMixin
- monomials: ExpressionBaseMixin
diff --git a/polymatrix/expression/impl/sumexprimpl.py b/polymatrix/expression/impl/sumexprimpl.py
deleted file mode 100644
index b148b43..0000000
--- a/polymatrix/expression/impl/sumexprimpl.py
+++ /dev/null
@@ -1,8 +0,0 @@
-import dataclass_abc
-from polymatrix.expression.sumexpr import SumExpr
-
-from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
-
-@dataclass_abc.dataclass_abc(frozen=True)
-class SumExprImpl(SumExpr):
- underlying: ExpressionBaseMixin
diff --git a/polymatrix/expression/impl/symmetricexprimpl.py b/polymatrix/expression/impl/symmetricexprimpl.py
deleted file mode 100644
index b15b8a0..0000000
--- a/polymatrix/expression/impl/symmetricexprimpl.py
+++ /dev/null
@@ -1,8 +0,0 @@
-import dataclass_abc
-from polymatrix.expression.symmetricexpr import SymmetricExpr
-
-from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
-
-@dataclass_abc.dataclass_abc(frozen=True)
-class SymmetricExprImpl(SymmetricExpr):
- underlying: ExpressionBaseMixin
diff --git a/polymatrix/expression/impl/toconstantexprimpl.py b/polymatrix/expression/impl/toconstantexprimpl.py
deleted file mode 100644
index 9e3d13d..0000000
--- a/polymatrix/expression/impl/toconstantexprimpl.py
+++ /dev/null
@@ -1,8 +0,0 @@
-import dataclass_abc
-from polymatrix.expression.toconstantexpr import ToConstantExpr
-
-from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
-
-@dataclass_abc.dataclass_abc(frozen=True)
-class ToConstantExprImpl(ToConstantExpr):
- underlying: ExpressionBaseMixin
diff --git a/polymatrix/expression/impl/toquadraticexprimpl.py b/polymatrix/expression/impl/toquadraticexprimpl.py
deleted file mode 100644
index 63a2cdb..0000000
--- a/polymatrix/expression/impl/toquadraticexprimpl.py
+++ /dev/null
@@ -1,8 +0,0 @@
-import dataclass_abc
-from polymatrix.expression.toquadraticexpr import ToQuadraticExpr
-
-from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
-
-@dataclass_abc.dataclass_abc(frozen=True)
-class ToQuadraticExprImpl(ToQuadraticExpr):
- underlying: ExpressionBaseMixin
diff --git a/polymatrix/expression/impl/tosortedvariablesimpl.py b/polymatrix/expression/impl/tosortedvariablesimpl.py
deleted file mode 100644
index 249e55e..0000000
--- a/polymatrix/expression/impl/tosortedvariablesimpl.py
+++ /dev/null
@@ -1,8 +0,0 @@
-import dataclass_abc
-from polymatrix.expression.tosortedvariables import ToSortedVariables
-
-from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
-
-@dataclass_abc.dataclass_abc(frozen=True)
-class ToSortedVariablesImpl(ToSortedVariables):
- underlying: ExpressionBaseMixin
diff --git a/polymatrix/expression/impl/tosymmetricmatrixexprimpl.py b/polymatrix/expression/impl/tosymmetricmatrixexprimpl.py
deleted file mode 100644
index da43157..0000000
--- a/polymatrix/expression/impl/tosymmetricmatrixexprimpl.py
+++ /dev/null
@@ -1,8 +0,0 @@
-import dataclass_abc
-from polymatrix.expression.tosymmetricmatrixexpr import ToSymmetricMatrixExpr
-
-from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
-
-@dataclass_abc.dataclass_abc(frozen=True)
-class ToSymmetricMatrixExprImpl(ToSymmetricMatrixExpr):
- underlying: ExpressionBaseMixin
diff --git a/polymatrix/expression/impl/transposeexprimpl.py b/polymatrix/expression/impl/transposeexprimpl.py
deleted file mode 100644
index 59b1a53..0000000
--- a/polymatrix/expression/impl/transposeexprimpl.py
+++ /dev/null
@@ -1,8 +0,0 @@
-import dataclass_abc
-from polymatrix.expression.transposeexpr import TransposeExpr
-
-from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
-
-@dataclass_abc.dataclass_abc(frozen=True)
-class TransposeExprImpl(TransposeExpr):
- underlying: ExpressionBaseMixin
diff --git a/polymatrix/expression/impl/truncateexprimpl.py b/polymatrix/expression/impl/truncateexprimpl.py
deleted file mode 100644
index 5bd45f3..0000000
--- a/polymatrix/expression/impl/truncateexprimpl.py
+++ /dev/null
@@ -1,11 +0,0 @@
-import dataclass_abc
-from polymatrix.expression.truncateexpr import TruncateExpr
-
-from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
-
-@dataclass_abc.dataclass_abc(frozen=True)
-class TruncateExprImpl(TruncateExpr):
- underlying: ExpressionBaseMixin
- variables: ExpressionBaseMixin
- degrees: tuple[int]
- inverse: bool
diff --git a/polymatrix/expression/impl/vstackexprimpl.py b/polymatrix/expression/impl/vstackexprimpl.py
deleted file mode 100644
index 9ee582d..0000000
--- a/polymatrix/expression/impl/vstackexprimpl.py
+++ /dev/null
@@ -1,7 +0,0 @@
-import dataclass_abc
-from polymatrix.expression.vstackexpr import VStackExpr
-
-
-@dataclass_abc.dataclass_abc(frozen=True)
-class VStackExprImpl(VStackExpr):
- underlying: tuple
diff --git a/polymatrix/expression/init/initadditionexpr.py b/polymatrix/expression/init/initadditionexpr.py
index e5b31c8..cdc97b1 100644
--- a/polymatrix/expression/init/initadditionexpr.py
+++ b/polymatrix/expression/init/initadditionexpr.py
@@ -1,12 +1,12 @@
from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
-from polymatrix.expression.impl.additionexprimpl import AdditionExprImpl
+import polymatrix.expression.impl.impl
def init_addition_expr(
left: ExpressionBaseMixin,
right: ExpressionBaseMixin,
):
- return AdditionExprImpl(
+ return polymatrix.expression.impl.impl.AdditionExprImpl(
left=left,
right=right,
)
diff --git a/polymatrix/expression/init/initblockdiagexpr.py b/polymatrix/expression/init/initblockdiagexpr.py
index 930385f..a9ad8a6 100644
--- a/polymatrix/expression/init/initblockdiagexpr.py
+++ b/polymatrix/expression/init/initblockdiagexpr.py
@@ -1,9 +1,7 @@
-from polymatrix.expression.impl.blockdiagexprimpl import BlockDiagExprImpl
-
-
+import polymatrix.expression.impl.impl
def init_block_diag_expr(
underlying: tuple,
):
- return BlockDiagExprImpl(
+ return polymatrix.expression.impl.impl.BlockDiagExprImpl(
underlying=underlying,
)
diff --git a/polymatrix/expression/init/initcacheexpr.py b/polymatrix/expression/init/initcacheexpr.py
index 977e033..861ffa1 100644
--- a/polymatrix/expression/init/initcacheexpr.py
+++ b/polymatrix/expression/init/initcacheexpr.py
@@ -1,10 +1,10 @@
from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
-from polymatrix.expression.impl.cacheexprimpl import CacheExprImpl
+import polymatrix.expression.impl.impl
def init_cache_expr(
underlying: ExpressionBaseMixin,
):
- return CacheExprImpl(
+ return polymatrix.expression.impl.impl.CacheExprImpl(
underlying=underlying,
)
diff --git a/polymatrix/expression/init/initcombinationsexpr.py b/polymatrix/expression/init/initcombinationsexpr.py
index 80bf4d0..10931e6 100644
--- a/polymatrix/expression/init/initcombinationsexpr.py
+++ b/polymatrix/expression/init/initcombinationsexpr.py
@@ -1,12 +1,12 @@
from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
-from polymatrix.expression.impl.combinationsexprimpl import CombinationsExprImpl
+import polymatrix.expression.impl.impl
def init_combinations_expr(
monomials: ExpressionBaseMixin,
number: int,
):
- return CombinationsExprImpl(
+ return polymatrix.expression.impl.impl.CombinationsExprImpl(
monomials=monomials,
number=number,
)
diff --git a/polymatrix/expression/init/initderivativeexpr.py b/polymatrix/expression/init/initderivativeexpr.py
index a6ca06c..b1c9405 100644
--- a/polymatrix/expression/init/initderivativeexpr.py
+++ b/polymatrix/expression/init/initderivativeexpr.py
@@ -1,5 +1,5 @@
from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
-from polymatrix.expression.impl.derivativeexprimpl import DerivativeExprImpl
+import polymatrix.expression.impl.impl
def init_derivative_expr(
@@ -13,7 +13,7 @@ def init_derivative_expr(
if introduce_derivatives is None:
introduce_derivatives = False
- return DerivativeExprImpl(
+ 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
index f0d1bb5..660f3ae 100644
--- a/polymatrix/expression/init/initdeterminantexpr.py
+++ b/polymatrix/expression/init/initdeterminantexpr.py
@@ -1,10 +1,10 @@
from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
-from polymatrix.expression.impl.determinantexprimpl import DeterminantExprImpl
+import polymatrix.expression.impl.impl
def init_determinant_expr(
underlying: ExpressionBaseMixin,
):
- return DeterminantExprImpl(
+ return polymatrix.expression.impl.impl.DeterminantExprImpl(
underlying=underlying,
)
diff --git a/polymatrix/expression/init/initdiagexpr.py b/polymatrix/expression/init/initdiagexpr.py
index db9b6d4..794c5bf 100644
--- a/polymatrix/expression/init/initdiagexpr.py
+++ b/polymatrix/expression/init/initdiagexpr.py
@@ -1,10 +1,10 @@
from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
-from polymatrix.expression.impl.diagexprimpl import DiagExprImpl
+import polymatrix.expression.impl.impl
def init_diag_expr(
underlying: ExpressionBaseMixin,
):
- return DiagExprImpl(
+ return polymatrix.expression.impl.impl.DiagExprImpl(
underlying=underlying,
)
diff --git a/polymatrix/expression/init/initdivergenceexpr.py b/polymatrix/expression/init/initdivergenceexpr.py
index d1aa02c..6f5d99d 100644
--- a/polymatrix/expression/init/initdivergenceexpr.py
+++ b/polymatrix/expression/init/initdivergenceexpr.py
@@ -1,13 +1,13 @@
from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
from typing import Union
-from polymatrix.expression.impl.divergenceexprimpl import DivergenceExprImpl
+import polymatrix.expression.impl.impl
def init_divergence_expr(
underlying: ExpressionBaseMixin,
variables: tuple,
):
- return DivergenceExprImpl(
+ return polymatrix.expression.impl.impl.DivergenceExprImpl(
underlying=underlying,
variables=variables,
)
diff --git a/polymatrix/expression/init/initdivisionexpr.py b/polymatrix/expression/init/initdivisionexpr.py
index 2a701a9..d7870bc 100644
--- a/polymatrix/expression/init/initdivisionexpr.py
+++ b/polymatrix/expression/init/initdivisionexpr.py
@@ -1,12 +1,12 @@
from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
-from polymatrix.expression.impl.divisionexprimpl import DivisionExprImpl
+import polymatrix.expression.impl.impl
def init_division_expr(
left: ExpressionBaseMixin,
right: ExpressionBaseMixin,
):
- return DivisionExprImpl(
+ return polymatrix.expression.impl.impl.DivisionExprImpl(
left=left,
right=right,
)
diff --git a/polymatrix/expression/init/initelemmultexpr.py b/polymatrix/expression/init/initelemmultexpr.py
index ae0e85f..ef66c68 100644
--- a/polymatrix/expression/init/initelemmultexpr.py
+++ b/polymatrix/expression/init/initelemmultexpr.py
@@ -1,12 +1,12 @@
from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
-from polymatrix.expression.impl.elemmultexprimpl import ElemMultExprImpl
+import polymatrix.expression.impl.impl
def init_elem_mult_expr(
left: ExpressionBaseMixin,
right: ExpressionBaseMixin,
):
- return ElemMultExprImpl(
+ return polymatrix.expression.impl.impl.ElemMultExprImpl(
left=left,
right=right,
)
diff --git a/polymatrix/expression/init/initevalexpr.py b/polymatrix/expression/init/initevalexpr.py
index 0fad8e5..c59a8d5 100644
--- a/polymatrix/expression/init/initevalexpr.py
+++ b/polymatrix/expression/init/initevalexpr.py
@@ -2,7 +2,7 @@ import typing
import numpy as np
from polymatrix.expression.init.initsubstituteexpr import format_substitutions
from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
-from polymatrix.expression.impl.evalexprimpl import EvalExprImpl
+import polymatrix.expression.impl.impl
def init_eval_expr(
@@ -31,7 +31,7 @@ def init_eval_expr(
substitutions = tuple((variable, formatted_values(value)) for variable, value in substitutions)
- return EvalExprImpl(
+ return polymatrix.expression.impl.impl.EvalExprImpl(
underlying=underlying,
substitutions=substitutions,
)
diff --git a/polymatrix/expression/init/initexpression.py b/polymatrix/expression/init/initexpression.py
index 7262e47..3c3258c 100644
--- a/polymatrix/expression/init/initexpression.py
+++ b/polymatrix/expression/init/initexpression.py
@@ -1,5 +1,5 @@
+from polymatrix.expression.expression import ExpressionImpl
from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
-from polymatrix.expression.impl.expressionimpl import ExpressionImpl
def init_expression(
diff --git a/polymatrix/expression/init/initeyeexpr.py b/polymatrix/expression/init/initeyeexpr.py
index e691b03..642e4c6 100644
--- a/polymatrix/expression/init/initeyeexpr.py
+++ b/polymatrix/expression/init/initeyeexpr.py
@@ -1,10 +1,10 @@
from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
-from polymatrix.expression.impl.eyeexprimpl import EyeExprImpl
+import polymatrix.expression.impl.impl
def init_eye_expr(
variable: ExpressionBaseMixin,
):
- return EyeExprImpl(
+ return polymatrix.expression.impl.impl.EyeExprImpl(
variable=variable,
)
diff --git a/polymatrix/expression/init/initfilterexpr.py b/polymatrix/expression/init/initfilterexpr.py
index c47036f..7164183 100644
--- a/polymatrix/expression/init/initfilterexpr.py
+++ b/polymatrix/expression/init/initfilterexpr.py
@@ -1,5 +1,5 @@
from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
-from polymatrix.expression.impl.filterexprimpl import FilterExprImpl
+import polymatrix.expression.impl.impl
def init_filter_expr(
@@ -10,7 +10,7 @@ def init_filter_expr(
if inverse is None:
inverse = False
- return FilterExprImpl(
+ 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
index 3af7dc3..b3ef782 100644
--- a/polymatrix/expression/init/initfromsymmetricmatrixexpr.py
+++ b/polymatrix/expression/init/initfromsymmetricmatrixexpr.py
@@ -1,10 +1,10 @@
from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
-from polymatrix.expression.impl.fromsymmetricmatrixexprimpl import FromSymmetricMatrixExprImpl
+import polymatrix.expression.impl.impl
def init_from_symmetric_matrix_expr(
underlying: ExpressionBaseMixin,
):
- return FromSymmetricMatrixExprImpl(
+ return polymatrix.expression.impl.impl.FromSymmetricMatrixExprImpl(
underlying=underlying,
)
diff --git a/polymatrix/expression/init/initfromsympyexpr.py b/polymatrix/expression/init/initfromsympyexpr.py
index 2ab6ded..4ca6fcf 100644
--- a/polymatrix/expression/init/initfromsympyexpr.py
+++ b/polymatrix/expression/init/initfromsympyexpr.py
@@ -2,14 +2,13 @@ import typing
import numpy as np
import sympy
-from polymatrix.expression.impl.fromsympyexprimpl import FromSympyExprImpl
+from polymatrix.expression.impl.impl import FromSympyExprImpl
from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
-def init_from_sympy_expr(
- data: typing.Union[np.ndarray, tuple[tuple[float]]],
-):
-
+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
@@ -37,21 +36,33 @@ def init_from_sympy_expr(
case _:
data = tuple((e,) for e in data)
- case np.number:
- data = ((float(data),),)
+ case sympy.Expr():
+ data = ((sympy.expand(data),),)
case ExpressionBaseMixin():
return data
- case sympy.Expr():
- data = ((sympy.expand(data),),)
-
case _:
- if not isinstance(data, (float, int)):
- raise Exception(f'{data=}, {type(data)=}')
+ if not isinstance(data, (float, int, np.number)):
+ # raise Exception(f'{data=}, {type(data)=}')
+ return None
data = ((data,),)
return FromSympyExprImpl(
- data=data,
+ 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
index c2080c6..b2c1dc3 100644
--- a/polymatrix/expression/init/initfromtermsexpr.py
+++ b/polymatrix/expression/init/initfromtermsexpr.py
@@ -1,6 +1,6 @@
import typing
-from polymatrix.expression.impl.fromtermsexprimpl import FromTermsExprImpl
from polymatrix.polymatrix.mixins.polymatrixmixin import PolyMatrixMixin
+import polymatrix.expression.impl.impl
def init_from_terms_expr(
@@ -27,7 +27,7 @@ def init_from_terms_expr(
# Expression needs to be hashable
terms_formatted = tuple((key, tuple(monomials.items())) for key, monomials in gen_terms)
- return FromTermsExprImpl(
+ 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
index 5fea7a5..f7fc0c9 100644
--- a/polymatrix/expression/init/initgetitemexpr.py
+++ b/polymatrix/expression/init/initgetitemexpr.py
@@ -1,6 +1,6 @@
from numpy import isin
from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
-from polymatrix.expression.impl.getitemexprimpl import GetItemExprImpl
+import polymatrix.expression.impl.impl
def init_get_item_expr(
@@ -10,13 +10,13 @@ def init_get_item_expr(
def get_hashable_slice(index):
if isinstance(index, slice):
- return GetItemExprImpl.Slice(start=index.start, stop=index.stop, step=index.step)
+ 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 GetItemExprImpl(
+ 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
index e4ab6a2..794c938 100644
--- a/polymatrix/expression/init/inithalfnewtonpolytopeexpr.py
+++ b/polymatrix/expression/init/inithalfnewtonpolytopeexpr.py
@@ -1,5 +1,5 @@
from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
-from polymatrix.expression.impl.halfnewtonpolytopeexprimpl import HalfNewtonPolytopeExprImpl
+import polymatrix.expression.impl.impl
def init_half_newton_polytope_expr(
@@ -7,7 +7,7 @@ def init_half_newton_polytope_expr(
variables: ExpressionBaseMixin,
filter: ExpressionBaseMixin | None = None,
):
- return HalfNewtonPolytopeExprImpl(
+ 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
index b869aee..30705e2 100644
--- a/polymatrix/expression/init/initlinearinexpr.py
+++ b/polymatrix/expression/init/initlinearinexpr.py
@@ -1,5 +1,5 @@
from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
-from polymatrix.expression.impl.linearinexprimpl import LinearInExprImpl
+import polymatrix.expression.impl.impl
def init_linear_in_expr(
@@ -10,7 +10,7 @@ def init_linear_in_expr(
):
assert isinstance(variables, ExpressionBaseMixin), f'{variables=}'
- return LinearInExprImpl(
+ return polymatrix.expression.impl.impl.LinearInExprImpl(
underlying=underlying,
monomials=monomials,
variables=variables,
diff --git a/polymatrix/expression/init/initlinearmatrixinexpr.py b/polymatrix/expression/init/initlinearmatrixinexpr.py
index cd4ce97..83e9aea 100644
--- a/polymatrix/expression/init/initlinearmatrixinexpr.py
+++ b/polymatrix/expression/init/initlinearmatrixinexpr.py
@@ -1,12 +1,12 @@
from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
-from polymatrix.expression.impl.linearmatrixinexprimpl import LinearMatrixInExprImpl
+import polymatrix.expression.impl.impl
def init_linear_matrix_in_expr(
underlying: ExpressionBaseMixin,
variable: int,
):
- return LinearMatrixInExprImpl(
+ return polymatrix.expression.impl.impl.LinearMatrixInExprImpl(
underlying=underlying,
variable=variable,
)
diff --git a/polymatrix/expression/init/initlinearmonomialsexpr.py b/polymatrix/expression/init/initlinearmonomialsexpr.py
index 8083715..f830542 100644
--- a/polymatrix/expression/init/initlinearmonomialsexpr.py
+++ b/polymatrix/expression/init/initlinearmonomialsexpr.py
@@ -1,5 +1,5 @@
from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
-from polymatrix.expression.impl.linearmonomialsexprimpl import LinearMonomialsExprImpl
+import polymatrix.expression.impl.impl
def init_linear_monomials_expr(
@@ -9,7 +9,7 @@ def init_linear_monomials_expr(
assert isinstance(variables, ExpressionBaseMixin), f'{variables=}'
- return LinearMonomialsExprImpl(
+ return polymatrix.expression.impl.impl.LinearMonomialsExprImpl(
underlying=underlying,
variables=variables,
)
diff --git a/polymatrix/expression/init/initmatrixmultexpr.py b/polymatrix/expression/init/initmatrixmultexpr.py
index 9081368..20bffec 100644
--- a/polymatrix/expression/init/initmatrixmultexpr.py
+++ b/polymatrix/expression/init/initmatrixmultexpr.py
@@ -1,12 +1,12 @@
from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
-from polymatrix.expression.impl.matrixmultexprimpl import MatrixMultExprImpl
+import polymatrix.expression.impl.impl
def init_matrix_mult_expr(
left: ExpressionBaseMixin,
right: ExpressionBaseMixin,
):
- return MatrixMultExprImpl(
+ return polymatrix.expression.impl.impl.MatrixMultExprImpl(
left=left,
right=right,
)
diff --git a/polymatrix/expression/init/initmaxdegreeexpr.py b/polymatrix/expression/init/initmaxdegreeexpr.py
index 60fc40a..d232163 100644
--- a/polymatrix/expression/init/initmaxdegreeexpr.py
+++ b/polymatrix/expression/init/initmaxdegreeexpr.py
@@ -1,10 +1,10 @@
from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
-from polymatrix.expression.impl.maxdegreeexprimpl import MaxDegreeExprImpl
+import polymatrix.expression.impl.impl
def init_max_degree_expr(
underlying: ExpressionBaseMixin,
):
- return MaxDegreeExprImpl(
+ return polymatrix.expression.impl.impl.MaxDegreeExprImpl(
underlying=underlying,
)
diff --git a/polymatrix/expression/init/initmaxexpr.py b/polymatrix/expression/init/initmaxexpr.py
index b0b1e4d..41dde90 100644
--- a/polymatrix/expression/init/initmaxexpr.py
+++ b/polymatrix/expression/init/initmaxexpr.py
@@ -1,10 +1,10 @@
from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
-from polymatrix.expression.impl.maxexprimpl import MaxExprImpl
+import polymatrix.expression.impl.impl
def init_max_expr(
underlying: ExpressionBaseMixin,
):
- return MaxExprImpl(
+ return polymatrix.expression.impl.impl.MaxExprImpl(
underlying=underlying,
)
diff --git a/polymatrix/expression/init/initparametrizeexpr.py b/polymatrix/expression/init/initparametrizeexpr.py
index c5b77a3..178d963 100644
--- a/polymatrix/expression/init/initparametrizeexpr.py
+++ b/polymatrix/expression/init/initparametrizeexpr.py
@@ -1,5 +1,5 @@
from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
-from polymatrix.expression.impl.parametrizeexprimpl import ParametrizeExprImpl
+import polymatrix.expression.impl.impl
def init_parametrize_expr(
@@ -9,7 +9,7 @@ def init_parametrize_expr(
if name is None:
name = 'undefined'
- return ParametrizeExprImpl(
+ return polymatrix.expression.impl.impl.ParametrizeExprImpl(
underlying=underlying,
name=name,
)
diff --git a/polymatrix/expression/init/initparametrizematrixexpr.py b/polymatrix/expression/init/initparametrizematrixexpr.py
new file mode 100644
index 0000000..bf90510
--- /dev/null
+++ b/polymatrix/expression/init/initparametrizematrixexpr.py
@@ -0,0 +1,12 @@
+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
index 6555b4b..9569cd3 100644
--- a/polymatrix/expression/init/initquadraticinexpr.py
+++ b/polymatrix/expression/init/initquadraticinexpr.py
@@ -1,5 +1,5 @@
from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
-from polymatrix.expression.impl.quadraticinexprimpl import QuadraticInExprImpl
+import polymatrix.expression.impl.impl
def init_quadratic_in_expr(
@@ -10,7 +10,7 @@ def init_quadratic_in_expr(
assert isinstance(variables, ExpressionBaseMixin), f'{variables=}'
- return QuadraticInExprImpl(
+ 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
index 190f7df..c965312 100644
--- a/polymatrix/expression/init/initquadraticmonomialsexpr.py
+++ b/polymatrix/expression/init/initquadraticmonomialsexpr.py
@@ -1,5 +1,5 @@
from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
-from polymatrix.expression.impl.quadraticmonomialsexprimpl import QuadraticMonomialsExprImpl
+import polymatrix.expression.impl.impl
def init_quadratic_monomials_expr(
@@ -9,7 +9,7 @@ def init_quadratic_monomials_expr(
assert isinstance(variables, ExpressionBaseMixin), f'{variables=}'
- return QuadraticMonomialsExprImpl(
+ return polymatrix.expression.impl.impl.QuadraticMonomialsExprImpl(
underlying=underlying,
variables=variables,
)
diff --git a/polymatrix/expression/init/initrepmatexpr.py b/polymatrix/expression/init/initrepmatexpr.py
index 2f7fb7c..152fff8 100644
--- a/polymatrix/expression/init/initrepmatexpr.py
+++ b/polymatrix/expression/init/initrepmatexpr.py
@@ -1,12 +1,12 @@
from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
-from polymatrix.expression.impl.repmatexprimpl import RepMatExprImpl
+import polymatrix.expression.impl.impl
def init_rep_mat_expr(
underlying: ExpressionBaseMixin,
repetition: tuple,
):
- return RepMatExprImpl(
+ return polymatrix.expression.impl.impl.RepMatExprImpl(
underlying=underlying,
repetition=repetition,
)
diff --git a/polymatrix/expression/init/initreshapeexpr.py b/polymatrix/expression/init/initreshapeexpr.py
index f95fb00..4e6ab57 100644
--- a/polymatrix/expression/init/initreshapeexpr.py
+++ b/polymatrix/expression/init/initreshapeexpr.py
@@ -1,5 +1,5 @@
+from polymatrix.expression.impl.reshapeexprmixin import ReshapeExprImpl
from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
-from polymatrix.expression.impl.reshapeexprimpl import ReshapeExprImpl
def init_reshape_expr(
diff --git a/polymatrix/expression/init/initsetelementatexpr.py b/polymatrix/expression/init/initsetelementatexpr.py
index 86df5aa..250c35b 100644
--- a/polymatrix/expression/init/initsetelementatexpr.py
+++ b/polymatrix/expression/init/initsetelementatexpr.py
@@ -1,5 +1,5 @@
from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
-from polymatrix.expression.impl.setelementatexprimpl import SetElementAtExprImpl
+import polymatrix.expression.impl.impl
def init_set_element_at_expr(
@@ -7,7 +7,7 @@ def init_set_element_at_expr(
index: tuple,
value: ExpressionBaseMixin,
):
- return SetElementAtExprImpl(
+ 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
index d71a9b5..d539453 100644
--- a/polymatrix/expression/init/initsqueezeexpr.py
+++ b/polymatrix/expression/init/initsqueezeexpr.py
@@ -1,10 +1,10 @@
from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
-from polymatrix.expression.impl.squeezeexprimpl import SqueezeExprImpl
+import polymatrix.expression.impl.impl
def init_squeeze_expr(
underlying: ExpressionBaseMixin,
):
- return SqueezeExprImpl(
+ return polymatrix.expression.impl.impl.SqueezeExprImpl(
underlying=underlying,
)
diff --git a/polymatrix/expression/init/initsubstituteexpr.py b/polymatrix/expression/init/initsubstituteexpr.py
index 50cbee0..15a6566 100644
--- a/polymatrix/expression/init/initsubstituteexpr.py
+++ b/polymatrix/expression/init/initsubstituteexpr.py
@@ -3,12 +3,12 @@ import numpy as np
from polymatrix.expression.init.initfromsympyexpr import init_from_sympy_expr
from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
-from polymatrix.expression.impl.substituteexprimpl import SubstituteExprImpl
+import polymatrix.expression.impl.impl
def format_substitutions(
variables: typing.Union[typing.Any, tuple, dict],
- values: typing.Union[float, tuple] = None,
+ values: float | tuple = None,
):
"""
(variables = x, values = 1.0) # ok
@@ -63,12 +63,13 @@ def init_substitute_expr(
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 SubstituteExprImpl(
+ return polymatrix.expression.impl.impl.SubstituteExprImpl(
underlying=underlying,
substitutions=substitutions,
)
diff --git a/polymatrix/expression/init/initsubtractmonomialsexpr.py b/polymatrix/expression/init/initsubtractmonomialsexpr.py
index 131401b..de720bd 100644
--- a/polymatrix/expression/init/initsubtractmonomialsexpr.py
+++ b/polymatrix/expression/init/initsubtractmonomialsexpr.py
@@ -1,12 +1,12 @@
from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
-from polymatrix.expression.impl.subtractmonomialsexprimpl import SubtractMonomialsExprImpl
+import polymatrix.expression.impl.impl
def init_subtract_monomials_expr(
underlying: ExpressionBaseMixin,
monomials: ExpressionBaseMixin,
):
- return SubtractMonomialsExprImpl(
+ return polymatrix.expression.impl.impl.SubtractMonomialsExprImpl(
underlying=underlying,
monomials=monomials,
)
diff --git a/polymatrix/expression/init/initsumexpr.py b/polymatrix/expression/init/initsumexpr.py
index 606d86b..288ae72 100644
--- a/polymatrix/expression/init/initsumexpr.py
+++ b/polymatrix/expression/init/initsumexpr.py
@@ -1,10 +1,10 @@
from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
-from polymatrix.expression.impl.sumexprimpl import SumExprImpl
+import polymatrix.expression.impl.impl
def init_sum_expr(
underlying: ExpressionBaseMixin,
):
- return SumExprImpl(
+ return polymatrix.expression.impl.impl.SumExprImpl(
underlying=underlying,
)
diff --git a/polymatrix/expression/init/initsymmetricexpr.py b/polymatrix/expression/init/initsymmetricexpr.py
index 87be3ed..dc321e5 100644
--- a/polymatrix/expression/init/initsymmetricexpr.py
+++ b/polymatrix/expression/init/initsymmetricexpr.py
@@ -1,10 +1,10 @@
from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
-from polymatrix.expression.impl.symmetricexprimpl import SymmetricExprImpl
+import polymatrix.expression.impl.impl
def init_symmetric_expr(
underlying: ExpressionBaseMixin,
):
- return SymmetricExprImpl(
+ return polymatrix.expression.impl.impl.SymmetricExprImpl(
underlying=underlying,
)
diff --git a/polymatrix/expression/init/inittoconstantexpr.py b/polymatrix/expression/init/inittoconstantexpr.py
index ead35f8..a0084a1 100644
--- a/polymatrix/expression/init/inittoconstantexpr.py
+++ b/polymatrix/expression/init/inittoconstantexpr.py
@@ -1,10 +1,10 @@
from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
-from polymatrix.expression.impl.toconstantexprimpl import ToConstantExprImpl
+import polymatrix.expression.impl.impl
def init_to_constant_expr(
underlying: ExpressionBaseMixin,
):
- return ToConstantExprImpl(
+ return polymatrix.expression.impl.impl.ToConstantExprImpl(
underlying=underlying,
)
diff --git a/polymatrix/expression/init/inittoquadraticexpr.py b/polymatrix/expression/init/inittoquadraticexpr.py
index dfc0567..77e6943 100644
--- a/polymatrix/expression/init/inittoquadraticexpr.py
+++ b/polymatrix/expression/init/inittoquadraticexpr.py
@@ -1,10 +1,10 @@
from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
-from polymatrix.expression.impl.toquadraticexprimpl import ToQuadraticExprImpl
+import polymatrix.expression.impl.impl
def init_to_quadratic_expr(
underlying: ExpressionBaseMixin,
):
- return ToQuadraticExprImpl(
+ return polymatrix.expression.impl.impl.ToQuadraticExprImpl(
underlying=underlying,
)
diff --git a/polymatrix/expression/init/inittosortedvariables.py b/polymatrix/expression/init/inittosortedvariables.py
index 5d669c9..3f5222a 100644
--- a/polymatrix/expression/init/inittosortedvariables.py
+++ b/polymatrix/expression/init/inittosortedvariables.py
@@ -1,10 +1,10 @@
from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
-from polymatrix.expression.impl.tosortedvariablesimpl import ToSortedVariablesImpl
+import polymatrix.expression.impl.impl
def init_to_sorted_variables(
underlying: ExpressionBaseMixin,
):
- return ToSortedVariablesImpl(
+ return polymatrix.expression.impl.impl.ToSortedVariablesImpl(
underlying=underlying,
)
diff --git a/polymatrix/expression/init/inittosymmetricmatrixexpr.py b/polymatrix/expression/init/inittosymmetricmatrixexpr.py
index 89fc46c..68b27fe 100644
--- a/polymatrix/expression/init/inittosymmetricmatrixexpr.py
+++ b/polymatrix/expression/init/inittosymmetricmatrixexpr.py
@@ -1,10 +1,10 @@
from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
-from polymatrix.expression.impl.tosymmetricmatrixexprimpl import ToSymmetricMatrixExprImpl
+import polymatrix.expression.impl.impl
def init_to_symmetric_matrix_expr(
underlying: ExpressionBaseMixin,
):
- return ToSymmetricMatrixExprImpl(
+ return polymatrix.expression.impl.impl.ToSymmetricMatrixExprImpl(
underlying=underlying,
)
diff --git a/polymatrix/expression/init/inittransposeexpr.py b/polymatrix/expression/init/inittransposeexpr.py
index 9ca9d91..7807e4d 100644
--- a/polymatrix/expression/init/inittransposeexpr.py
+++ b/polymatrix/expression/init/inittransposeexpr.py
@@ -1,10 +1,10 @@
from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
-from polymatrix.expression.impl.transposeexprimpl import TransposeExprImpl
+import polymatrix.expression.impl.impl
def init_transpose_expr(
underlying: ExpressionBaseMixin,
):
- return TransposeExprImpl(
+ return polymatrix.expression.impl.impl.TransposeExprImpl(
underlying=underlying,
)
diff --git a/polymatrix/expression/init/inittruncateexpr.py b/polymatrix/expression/init/inittruncateexpr.py
index 4582bcb..d36db03 100644
--- a/polymatrix/expression/init/inittruncateexpr.py
+++ b/polymatrix/expression/init/inittruncateexpr.py
@@ -1,5 +1,5 @@
from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
-from polymatrix.expression.impl.truncateexprimpl import TruncateExprImpl
+import polymatrix.expression.impl.impl
def init_truncate_expr(
@@ -14,7 +14,7 @@ def init_truncate_expr(
if inverse is None:
inverse = False
- return TruncateExprImpl(
+ return polymatrix.expression.impl.impl.TruncateExprImpl(
underlying=underlying,
variables=variables,
degrees=degrees,
diff --git a/polymatrix/expression/init/initvstackexpr.py b/polymatrix/expression/init/initvstackexpr.py
index 1edc716..3d47979 100644
--- a/polymatrix/expression/init/initvstackexpr.py
+++ b/polymatrix/expression/init/initvstackexpr.py
@@ -1,6 +1,6 @@
-from polymatrix.expression.impl.vstackexprimpl import VStackExprImpl
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(
@@ -15,6 +15,6 @@ def init_v_stack_expr(
else:
yield init_from_sympy_expr(e)
- return VStackExprImpl(
+ return polymatrix.expression.impl.impl.VStackExprImpl(
underlying=tuple(gen_underlying()),
)
diff --git a/polymatrix/expression/linearinexpr.py b/polymatrix/expression/linearinexpr.py
deleted file mode 100644
index 4edf8b3..0000000
--- a/polymatrix/expression/linearinexpr.py
+++ /dev/null
@@ -1,4 +0,0 @@
-from polymatrix.expression.mixins.linearinexprmixin import LinearInExprMixin
-
-class LinearInExpr(LinearInExprMixin):
- pass
diff --git a/polymatrix/expression/linearmatrixinexpr.py b/polymatrix/expression/linearmatrixinexpr.py
deleted file mode 100644
index 2bce2e7..0000000
--- a/polymatrix/expression/linearmatrixinexpr.py
+++ /dev/null
@@ -1,4 +0,0 @@
-from polymatrix.expression.mixins.linearmatrixinexprmixin import LinearMatrixInExprMixin
-
-class LinearMatrixInExpr(LinearMatrixInExprMixin):
- pass
diff --git a/polymatrix/expression/linearmonomialsexpr.py b/polymatrix/expression/linearmonomialsexpr.py
deleted file mode 100644
index 9ff6337..0000000
--- a/polymatrix/expression/linearmonomialsexpr.py
+++ /dev/null
@@ -1,4 +0,0 @@
-from polymatrix.expression.mixins.linearmonomialsexprmixin import LinearMonomialsExprMixin
-
-class LinearMonomialsExpr(LinearMonomialsExprMixin):
- pass
diff --git a/polymatrix/expression/matrixmultexpr.py b/polymatrix/expression/matrixmultexpr.py
deleted file mode 100644
index 62f0cf3..0000000
--- a/polymatrix/expression/matrixmultexpr.py
+++ /dev/null
@@ -1,4 +0,0 @@
-from polymatrix.expression.mixins.matrixmultexprmixin import MatrixMultExprMixin
-
-class MatrixMultExpr(MatrixMultExprMixin):
- pass
diff --git a/polymatrix/expression/maxdegreeexpr.py b/polymatrix/expression/maxdegreeexpr.py
deleted file mode 100644
index ec8ad47..0000000
--- a/polymatrix/expression/maxdegreeexpr.py
+++ /dev/null
@@ -1,4 +0,0 @@
-from polymatrix.expression.mixins.maxdegreeexprmixin import MaxDegreeExprMixin
-
-class MaxDegreeExpr(MaxDegreeExprMixin):
- pass
diff --git a/polymatrix/expression/maxexpr.py b/polymatrix/expression/maxexpr.py
deleted file mode 100644
index dc0996c..0000000
--- a/polymatrix/expression/maxexpr.py
+++ /dev/null
@@ -1,4 +0,0 @@
-from polymatrix.expression.mixins.maxexprmixin import MaxExprMixin
-
-class MaxExpr(MaxExprMixin):
- pass
diff --git a/polymatrix/expression/mixins/additionexprmixin.py b/polymatrix/expression/mixins/additionexprmixin.py
index 20ff5d0..e247ebd 100644
--- a/polymatrix/expression/mixins/additionexprmixin.py
+++ b/polymatrix/expression/mixins/additionexprmixin.py
@@ -1,9 +1,7 @@
-
import abc
-import collections
import math
import typing
-import dataclass_abc
+import dataclassabc
from polymatrix.polymatrix.init.initpolymatrix import init_poly_matrix
from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
@@ -36,7 +34,7 @@ class AdditionExprMixin(ExpressionBaseMixin):
if left.shape != (1, 1) and right.shape == (1, 1):
- @dataclass_abc.dataclass_abc(frozen=True)
+ @dataclassabc.dataclassabc(frozen=True)
class BroadCastedPolyMatrix(PolyMatrixMixin):
underlying_monomials: tuple[tuple[int], float]
shape: tuple[int, int]
diff --git a/polymatrix/expression/mixins/assertdegreeexprmixin.py b/polymatrix/expression/mixins/assertdegreeexprmixin.py
index a41e6ba..e57de1c 100644
--- a/polymatrix/expression/mixins/assertdegreeexprmixin.py
+++ b/polymatrix/expression/mixins/assertdegreeexprmixin.py
@@ -1,7 +1,7 @@
import abc
import itertools
-import dataclass_abc
+import dataclassabc
from polymatrix.polymatrix.mixins.polymatrixmixin import PolyMatrixMixin
from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
@@ -28,7 +28,7 @@ class AssertDegreeExprMixin(ExpressionBaseMixin):
state, underlying = self.underlying.apply(state)
- @dataclass_abc.dataclass_abc(frozen=True)
+ @dataclassabc.dataclassabc(frozen=True)
class AssertDegreePolyMatrix(PolyMatrixMixin):
underlying: PolyMatrixMixin
degrees: tuple[int, ...]
diff --git a/polymatrix/expression/mixins/blockdiagexprmixin.py b/polymatrix/expression/mixins/blockdiagexprmixin.py
index eff8de8..b210d27 100644
--- a/polymatrix/expression/mixins/blockdiagexprmixin.py
+++ b/polymatrix/expression/mixins/blockdiagexprmixin.py
@@ -1,7 +1,7 @@
import abc
import itertools
-import dataclass_abc
+import dataclassabc
from polymatrix.polymatrix.mixins.polymatrixmixin import PolyMatrixMixin
from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
@@ -28,7 +28,7 @@ class BlockDiagExprMixin(ExpressionBaseMixin):
# assert all(underlying.shape[0] == underlying.shape[1] for underlying in all_underlying)
- @dataclass_abc.dataclass_abc(frozen=True)
+ @dataclassabc.dataclassabc(frozen=True)
class BlockDiagPolyMatrix(PolyMatrixMixin):
all_underlying: tuple[PolyMatrixMixin]
underlying_row_col_range: tuple[tuple[int, int], ...]
diff --git a/polymatrix/expression/mixins/diagexprmixin.py b/polymatrix/expression/mixins/diagexprmixin.py
index 7eded9e..26c75d0 100644
--- a/polymatrix/expression/mixins/diagexprmixin.py
+++ b/polymatrix/expression/mixins/diagexprmixin.py
@@ -1,5 +1,5 @@
import abc
-import dataclass_abc
+import dataclassabc
from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
from polymatrix.expressionstate.mixins.expressionstatemixin import ExpressionStateMixin
@@ -20,7 +20,7 @@ class DiagExprMixin(ExpressionBaseMixin):
state, underlying = self.underlying.apply(state)
if underlying.shape[1] == 1:
- @dataclass_abc.dataclass_abc(frozen=True)
+ @dataclassabc.dataclassabc(frozen=True)
class DiagPolyMatrix(PolyMatrixMixin):
underlying: PolyMatrixMixin
shape: tuple[int, int]
@@ -39,7 +39,7 @@ class DiagExprMixin(ExpressionBaseMixin):
else:
assert underlying.shape[0] == underlying.shape[1], f'{underlying.shape=}'
- @dataclass_abc.dataclass_abc(frozen=True)
+ @dataclassabc.dataclassabc(frozen=True)
class TracePolyMatrix(PolyMatrixMixin):
underlying: PolyMatrixMixin
shape: tuple[int, int]
diff --git a/polymatrix/expression/mixins/elemmultexprmixin.py b/polymatrix/expression/mixins/elemmultexprmixin.py
index ab1f265..2edf9e6 100644
--- a/polymatrix/expression/mixins/elemmultexprmixin.py
+++ b/polymatrix/expression/mixins/elemmultexprmixin.py
@@ -2,7 +2,7 @@
import abc
import itertools
import typing
-import dataclass_abc
+import dataclassabc
from polymatrix.polymatrix.init.initpolymatrix import init_poly_matrix
from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
@@ -42,7 +42,7 @@ class ElemMultExprMixin(ExpressionBaseMixin):
if right.shape == (1, 1):
right_poly = right.get_poly(0, 0)
- @dataclass_abc.dataclass_abc(frozen=True)
+ @dataclassabc.dataclassabc(frozen=True)
class BroadCastedPolyMatrix(PolyMatrixMixin):
underlying: tuple[tuple[int], float]
shape: tuple[int, int]
diff --git a/polymatrix/expression/mixins/evalexprmixin.py b/polymatrix/expression/mixins/evalexprmixin.py
index cbf4ce8..e769d8b 100644
--- a/polymatrix/expression/mixins/evalexprmixin.py
+++ b/polymatrix/expression/mixins/evalexprmixin.py
@@ -102,7 +102,6 @@ class EvalExprMixin(ExpressionBaseMixin):
return state, poly_matrix
-
# if len(self.values) == 1:
# values = tuple(self.values[0] for _ in self.variables)
diff --git a/polymatrix/expression/mixins/expressionmixin.py b/polymatrix/expression/mixins/expressionmixin.py
deleted file mode 100644
index 22702ca..0000000
--- a/polymatrix/expression/mixins/expressionmixin.py
+++ /dev/null
@@ -1,534 +0,0 @@
-import abc
-import dataclasses
-import typing
-import numpy as np
-import sympy
-
-from polymatrix.expression.init.initadditionexpr import init_addition_expr
-from polymatrix.expression.init.initcacheexpr import init_cache_expr
-from polymatrix.expression.init.initcombinationsexpr import init_combinations_expr
-from polymatrix.expression.init.initderivativeexpr import init_derivative_expr
-from polymatrix.expression.init.initdeterminantexpr import init_determinant_expr
-from polymatrix.expression.init.initdivergenceexpr import init_divergence_expr
-from polymatrix.expression.init.initdivisionexpr import init_division_expr
-from polymatrix.expression.init.initelemmultexpr import init_elem_mult_expr
-from polymatrix.expression.init.initevalexpr import init_eval_expr
-from polymatrix.expression.init.initfilterexpr import init_filter_expr
-from polymatrix.expression.init.initfromsymmetricmatrixexpr import init_from_symmetric_matrix_expr
-from polymatrix.expression.init.inithalfnewtonpolytopeexpr import init_half_newton_polytope_expr
-from polymatrix.expression.init.initlinearinexpr import init_linear_in_expr
-from polymatrix.expression.init.initfromsympyexpr import init_from_sympy_expr
-from polymatrix.expression.init.initgetitemexpr import init_get_item_expr
-from polymatrix.expression.init.initlinearmatrixinexpr import init_linear_matrix_in_expr
-from polymatrix.expression.init.initlinearmonomialsexpr import init_linear_monomials_expr
-from polymatrix.expression.init.initmatrixmultexpr import init_matrix_mult_expr
-from polymatrix.expression.init.initmaxdegreeexpr import init_max_degree_expr
-from polymatrix.expression.init.initmaxexpr import init_max_expr
-from polymatrix.expression.init.initparametrizeexpr import init_parametrize_expr
-from polymatrix.expression.init.initparametrizematrixexpr import init_parametrize_matrix_expr
-from polymatrix.expression.init.initquadraticinexpr import init_quadratic_in_expr
-from polymatrix.expression.init.initrepmatexpr import init_rep_mat_expr
-from polymatrix.expression.init.initreshapeexpr import init_reshape_expr
-from polymatrix.expression.init.initsetelementatexpr import init_set_element_at_expr
-from polymatrix.expression.init.initquadraticmonomialsexpr import init_quadratic_monomials_expr
-from polymatrix.expression.init.initsqueezeexpr import init_squeeze_expr
-from polymatrix.expression.init.initsubstituteexpr import init_substitute_expr
-from polymatrix.expression.init.initsubtractmonomialsexpr import init_subtract_monomials_expr
-from polymatrix.expression.init.initsumexpr import init_sum_expr
-from polymatrix.expression.init.initsymmetricexpr import init_symmetric_expr
-from polymatrix.expression.init.inittoconstantexpr import init_to_constant_expr
-from polymatrix.expression.init.inittoquadraticexpr import init_to_quadratic_expr
-from polymatrix.expression.init.initdiagexpr import init_diag_expr
-from polymatrix.expression.init.inittosortedvariables import init_to_sorted_variables
-from polymatrix.expression.init.inittosymmetricmatrixexpr import init_to_symmetric_matrix_expr
-from polymatrix.expression.init.inittransposeexpr import init_transpose_expr
-from polymatrix.expression.init.inittruncateexpr import init_truncate_expr
-
-from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
-from polymatrix.polymatrix.polymatrix import PolyMatrix
-from polymatrix.expressionstate.expressionstate import ExpressionState
-
-
-class ExpressionMixin(
- ExpressionBaseMixin,
- abc.ABC,
-):
-
- @property
- @abc.abstractmethod
- def underlying(self) -> ExpressionBaseMixin:
- ...
-
- # overwrites abstract method of `PolyMatrixExprBaseMixin`
- def apply(self, state: ExpressionState) -> tuple[ExpressionState, PolyMatrix]:
- return self.underlying.apply(state)
-
- def __add__(self, other: ExpressionBaseMixin) -> 'ExpressionMixin':
- if other is None:
- return self
-
- right = self._convert_to_expression(other)
-
- return dataclasses.replace(
- self,
- underlying=init_addition_expr(
- left=self.underlying,
- right=right,
- ),
- )
-
- def __getattr__(self, name):
- attr = getattr(self.underlying, name)
-
- if isinstance(attr, ExpressionBaseMixin):
- return dataclasses.replace(
- self,
- underlying=attr,
- )
-
- else:
- return attr
-
- def __getitem__(self, key: tuple[int, int]):
- return dataclasses.replace(
- self,
- underlying=init_get_item_expr(
- underlying=self.underlying,
- index=key,
- ),
- )
-
- def __matmul__(self, other: typing.Union[ExpressionBaseMixin, np.ndarray]) -> 'ExpressionMixin':
- right = self._convert_to_expression(other)
-
- return dataclasses.replace(
- self,
- underlying=init_matrix_mult_expr(
- left=self.underlying,
- right=right,
- ),
- )
-
- def __mul__(self, other) -> 'ExpressionMixin':
- right = self._convert_to_expression(other)
-
- return dataclasses.replace(
- self,
- underlying=init_elem_mult_expr(
- left=self.underlying,
- right=right,
- ),
- )
-
- def __pow__(self, num):
- curr = 1
-
- for _ in range(num):
- curr = curr * self
-
- return curr
-
- def __neg__(self):
- return self * (-1)
-
- def __radd__(self, other):
- return self + other
-
- def __rmatmul__(self, other):
- left = self._convert_to_expression(other)
-
- return left @ self
-
- def __rmul__(self, other):
- return self * other
-
- def __sub__(self, other):
- return self + other * (-1)
-
- def __truediv__(self, other: ExpressionBaseMixin):
- if isinstance(other, (int, float)):
- return self * (1/other)
-
- right = self._convert_to_expression(other)
-
- return dataclasses.replace(
- self,
- underlying=init_division_expr(
- left=self.underlying,
- right=right,
- ),
- )
-
- def _convert_to_expression(self, other):
- if isinstance(other, ExpressionBaseMixin):
- return other
-
- # can_convert = isinstance(other, (float, int, sympy.Expr, np.ndarray))
-
- # if not can_convert:
- # raise Exception(f'{other} cannot be converted to an Expression')
- # else:
-
- return init_from_sympy_expr(other)
-
- def cache(self) -> 'ExpressionMixin':
- return dataclasses.replace(
- self,
- underlying=init_cache_expr(
- underlying=self.underlying,
- ),
- )
-
- def combinations(self, number: int):
- return dataclasses.replace(
- self,
- underlying=init_combinations_expr(
- monomials=self.underlying,
- number=number,
- ),
- )
-
- def determinant(self) -> 'ExpressionMixin':
- return dataclasses.replace(
- self,
- underlying=init_determinant_expr(
- underlying=self.underlying,
- ),
- )
-
- def diag(self):
- return dataclasses.replace(
- self,
- underlying=init_diag_expr(
- underlying=self.underlying,
- ),
- )
-
- def diff(
- self,
- variables: 'ExpressionMixin',
- introduce_derivatives: bool = None,
- ) -> 'ExpressionMixin':
- return dataclasses.replace(
- self,
- underlying=init_derivative_expr(
- underlying=self.underlying,
- variables=variables,
- introduce_derivatives=introduce_derivatives,
- ),
- )
-
- def divergence(
- self,
- variables: tuple,
- ) -> 'ExpressionMixin':
- return dataclasses.replace(
- self,
- underlying=init_divergence_expr(
- underlying=self.underlying,
- variables=variables,
- ),
- )
-
- def eval(
- self,
- variable: tuple,
- value: tuple[float, ...] = None,
- ) -> 'ExpressionMixin':
- return dataclasses.replace(
- self,
- underlying=init_eval_expr(
- underlying=self.underlying,
- variables=variable,
- values=value,
- ),
- )
-
- def filter(
- self,
- predicator: 'ExpressionMixin',
- inverse: bool = None,
- ) -> 'ExpressionMixin':
- return dataclasses.replace(
- self,
- underlying=init_filter_expr(
- underlying=self.underlying,
- predicator=predicator,
- inverse=inverse,
- ),
- )
-
- def from_symmetric_matrix(self) -> 'ExpressionMixin':
- return dataclasses.replace(
- self,
- underlying=init_from_symmetric_matrix_expr(
- underlying=self.underlying,
- ),
- )
-
- def half_newton_polytope(
- self,
- variables: 'ExpressionMixin',
- filter: 'ExpressionMixin | None' = None,
- ) -> 'ExpressionMixin':
- return dataclasses.replace(
- self,
- underlying=init_half_newton_polytope_expr(
- monomials=self.underlying,
- variables=variables,
- filter=filter,
- ),
- )
-
- def linear_matrix_in(self, variable: 'ExpressionMixin') -> 'ExpressionMixin':
- return dataclasses.replace(
- self,
- underlying=init_linear_matrix_in_expr(
- underlying=self.underlying,
- variable=variable,
- ),
- )
-
- def linear_monomials(self, variables: 'ExpressionMixin') -> 'ExpressionMixin':
- return dataclasses.replace(
- self,
- underlying=init_linear_monomials_expr(
- underlying=self.underlying,
- variables=variables,
- ),
- )
-
- def linear_in(
- self,
- variables: 'ExpressionMixin',
- monomials: 'ExpressionMixin' = None,
- ignore_unmatched: bool = None,
- ) -> 'ExpressionMixin':
- if monomials is None:
- monomials = self.linear_monomials(variables)
-
- return dataclasses.replace(
- self,
- underlying=init_linear_in_expr(
- underlying=self.underlying,
- monomials=monomials,
- variables=variables,
- ignore_unmatched=ignore_unmatched,
- ),
- )
-
- def max(self) -> 'ExpressionMixin':
- return dataclasses.replace(
- self,
- underlying=init_max_expr(
- underlying=self.underlying,
- ),
- )
-
- def max_degree(self) -> 'ExpressionMixin':
- return dataclasses.replace(
- self,
- underlying=init_max_degree_expr(
- underlying=self.underlying,
- ),
- )
-
- def parametrize(self, name: str = None) -> 'ExpressionMixin':
- return dataclasses.replace(
- self,
- underlying=init_parametrize_expr(
- underlying=self.underlying,
- name=name,
- ),
- )
-
- # def parametrize_matrix(self, name: str = None) -> 'ExpressionMixin':
- # return dataclasses.replace(
- # self,
- # underlying=init_parametrize_matrix_expr(
- # underlying=self.underlying,
- # name=name,
- # ),
- # )
-
- def quadratic_in(self, variables: 'ExpressionMixin', monomials: 'ExpressionMixin' = None) -> 'ExpressionMixin':
- if monomials is None:
- monomials = self.quadratic_monomials(variables)
-
- return dataclasses.replace(
- self,
- underlying=init_quadratic_in_expr(
- underlying=self.underlying,
- monomials=monomials,
- variables=variables,
- ),
- )
-
- def quadratic_monomials(
- self,
- variables: 'ExpressionMixin',
- ) -> 'ExpressionMixin':
- return dataclasses.replace(
- self,
- underlying=init_quadratic_monomials_expr(
- underlying=self.underlying,
- variables=variables,
- ),
- )
-
- def reshape(self, n: int, m: int) -> 'ExpressionMixin':
- return dataclasses.replace(
- self,
- underlying=init_reshape_expr(
- underlying=self.underlying,
- new_shape=(n, m),
- ),
- )
-
- def rep_mat(self, n: int, m: int) -> 'ExpressionMixin':
- return dataclasses.replace(
- self,
- underlying=init_rep_mat_expr(
- underlying=self.underlying,
- repetition=(n, m),
- ),
- )
-
- def set_element_at(
- self,
- row: int,
- col: int,
- value: 'ExpressionMixin',
- ) -> 'ExpressionMixin':
- if isinstance(value, ExpressionMixin):
- value = value.underlying
- else:
- value = init_from_sympy_expr(value)
-
- return dataclasses.replace(
- self,
- underlying=init_set_element_at_expr(
- underlying=self.underlying,
- index=(row, col),
- value=value,
- ),
- )
-
- def squeeze(
- self,
- ) -> 'ExpressionMixin':
- return dataclasses.replace(
- self,
- underlying=init_squeeze_expr(
- underlying=self.underlying,
- ),
- )
-
- def subtract_monomials(
- self,
- monomials: 'ExpressionMixin',
- ) -> 'ExpressionMixin':
- return dataclasses.replace(
- self,
- underlying=init_subtract_monomials_expr(
- underlying=self.underlying,
- monomials=monomials,
- ),
- )
-
- def substitute(
- self,
- variable: tuple,
- values: tuple['ExpressionMixin', ...] = None,
- ) -> 'ExpressionMixin':
- return dataclasses.replace(
- self,
- underlying=init_substitute_expr(
- underlying=self.underlying,
- variables=variable,
- values=values,
- ),
- )
-
- def subs(
- self,
- variable: tuple,
- values: tuple['ExpressionMixin', ...] = None,
- ) -> 'ExpressionMixin':
- return self.substitute(
- variable=variable,
- values=values,
- )
-
- def sum(self):
- return dataclasses.replace(
- self,
- underlying=init_sum_expr(
- underlying=self.underlying,
- ),
- )
-
- def symmetric(self):
- return dataclasses.replace(
- self,
- underlying=init_symmetric_expr(
- underlying=self.underlying,
- ),
- )
-
- @property
- def T(self) -> 'ExpressionMixin':
- return dataclasses.replace(
- self,
- underlying=init_transpose_expr(
- underlying=self.underlying,
- ),
- )
-
- def to_constant(self) -> 'ExpressionMixin':
- return dataclasses.replace(
- self,
- underlying=init_to_constant_expr(
- underlying=self.underlying,
- ),
- )
-
- # def to_quadratic(self) -> 'ExpressionMixin':
- # return dataclasses.replace(
- # self,
- # underlying=init_to_quadratic_expr(
- # underlying=self.underlying,
- # ),
- # )
-
- def to_symmetric_matrix(self) -> 'ExpressionMixin':
- return dataclasses.replace(
- self,
- underlying=init_to_symmetric_matrix_expr(
- underlying=self.underlying,
- ),
- )
-
- def to_sorted_variables(self) -> 'ExpressionMixin':
- return dataclasses.replace(
- self,
- underlying=init_to_sorted_variables(
- underlying=self.underlying,
- ),
- )
-
- def truncate(
- self,
- variables: tuple,
- degrees: tuple[int],
- inverse: bool = None,
- ):
- return dataclasses.replace(
- self,
- underlying=init_truncate_expr(
- underlying=self.underlying,
- variables=variables,
- degrees=degrees,
- inverse=inverse,
- ),
- )
diff --git a/polymatrix/expression/mixins/eyeexprmixin.py b/polymatrix/expression/mixins/eyeexprmixin.py
index 47e83f9..7d844ce 100644
--- a/polymatrix/expression/mixins/eyeexprmixin.py
+++ b/polymatrix/expression/mixins/eyeexprmixin.py
@@ -1,7 +1,7 @@
import abc
import itertools
-import dataclass_abc
+import dataclassabc
from polymatrix.polymatrix.mixins.polymatrixmixin import PolyMatrixMixin
from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
@@ -23,7 +23,7 @@ class EyeExprMixin(ExpressionBaseMixin):
state, variable = self.variable.apply(state)
- @dataclass_abc.dataclass_abc(frozen=True)
+ @dataclassabc.dataclassabc(frozen=True)
class EyePolyMatrix(PolyMatrixMixin):
shape: tuple[int, int]
diff --git a/polymatrix/expression/mixins/fromsympyexprmixin.py b/polymatrix/expression/mixins/fromsympyexprmixin.py
index 4728bbb..25edde0 100644
--- a/polymatrix/expression/mixins/fromsympyexprmixin.py
+++ b/polymatrix/expression/mixins/fromsympyexprmixin.py
@@ -27,7 +27,7 @@ class FromSympyExprMixin(ExpressionBaseMixin):
for poly_row, col_data in enumerate(self.data):
for poly_col, poly_data in enumerate(col_data):
- if isinstance(poly_data, (int, float)):
+ if isinstance(poly_data, (int, float, np.number)):
if math.isclose(poly_data, 0):
polynomial = {}
else:
diff --git a/polymatrix/expression/mixins/getitemexprmixin.py b/polymatrix/expression/mixins/getitemexprmixin.py
index 1d0586f..60adac1 100644
--- a/polymatrix/expression/mixins/getitemexprmixin.py
+++ b/polymatrix/expression/mixins/getitemexprmixin.py
@@ -2,7 +2,7 @@
import abc
import dataclasses
import typing
-import dataclass_abc
+import dataclassabc
from polymatrix.polymatrix.mixins.polymatrixmixin import PolyMatrixMixin
from polymatrix.polymatrix.init.initpolymatrix import init_poly_matrix
@@ -65,7 +65,7 @@ class GetItemExprMixin(ExpressionBaseMixin):
get_proper_index(self.index[1], underlying.shape[1]),
)
- @dataclass_abc.dataclass_abc(frozen=True)
+ @dataclassabc.dataclassabc(frozen=True)
class GetItemPolyMatrix(PolyMatrixMixin):
underlying: PolyMatrixMixin
index: tuple[int, int]
diff --git a/polymatrix/expression/mixins/quadraticinexprmixin.py b/polymatrix/expression/mixins/quadraticinexprmixin.py
index 5c32f45..4568286 100644
--- a/polymatrix/expression/mixins/quadraticinexprmixin.py
+++ b/polymatrix/expression/mixins/quadraticinexprmixin.py
@@ -39,7 +39,6 @@ class QuadraticInExprMixin(ExpressionBaseMixin):
assert underlying.shape == (1, 1), f'underlying shape is {underlying.shape}'
- terms = collections.defaultdict(dict)
terms = collections.defaultdict(lambda: collections.defaultdict(float))
for monomial, value in underlying.get_poly(0, 0).items():
@@ -59,14 +58,10 @@ class QuadraticInExprMixin(ExpressionBaseMixin):
except ValueError:
raise ValueError(f'{right=} not in {sos_monomials=}')
- # monomial_terms = terms[row, col]
- # if p_monomial not in monomial_terms:
- # monomial_terms[p_monomial] = 0
-
terms[row, col][p_monomial] += value
poly_matrix = init_poly_matrix(
- terms=dict(terms),
+ terms=dict((k, dict(v)) for k, v in terms.items()),
shape=2*(len(sos_monomials),),
)
diff --git a/polymatrix/expression/mixins/repmatexprmixin.py b/polymatrix/expression/mixins/repmatexprmixin.py
index d45cca2..8ed4811 100644
--- a/polymatrix/expression/mixins/repmatexprmixin.py
+++ b/polymatrix/expression/mixins/repmatexprmixin.py
@@ -1,5 +1,5 @@
import abc
-import dataclass_abc
+import dataclassabc
from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
from polymatrix.expressionstate.mixins.expressionstatemixin import ExpressionStateMixin
@@ -24,7 +24,7 @@ class RepMatExprMixin(ExpressionBaseMixin):
state, underlying = self.underlying.apply(state)
- @dataclass_abc.dataclass_abc(frozen=True)
+ @dataclassabc.dataclassabc(frozen=True)
class RepMatPolyMatrix(PolyMatrixMixin):
underlying: PolyMatrixMixin
shape: tuple[int, int]
diff --git a/polymatrix/expression/mixins/reshapeexprmixin.py b/polymatrix/expression/mixins/reshapeexprmixin.py
index a73c00e..683d2fa 100644
--- a/polymatrix/expression/mixins/reshapeexprmixin.py
+++ b/polymatrix/expression/mixins/reshapeexprmixin.py
@@ -1,7 +1,7 @@
import abc
import functools
import operator
-import dataclass_abc
+import dataclassabc
import numpy as np
from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
@@ -27,7 +27,7 @@ class ReshapeExprMixin(ExpressionBaseMixin):
state, underlying = self.underlying.apply(state)
- @dataclass_abc.dataclass_abc(frozen=True)
+ @dataclassabc.dataclassabc(frozen=True)
class ReshapePolyMatrix(PolyMatrixMixin):
underlying: PolyMatrixMixin
shape: tuple[int, int]
diff --git a/polymatrix/expression/mixins/setelementatexprmixin.py b/polymatrix/expression/mixins/setelementatexprmixin.py
index a111d20..8af695c 100644
--- a/polymatrix/expression/mixins/setelementatexprmixin.py
+++ b/polymatrix/expression/mixins/setelementatexprmixin.py
@@ -2,7 +2,7 @@
import abc
import dataclasses
import typing
-import dataclass_abc
+import dataclassabc
from polymatrix.polymatrix.mixins.polymatrixmixin import PolyMatrixMixin
from polymatrix.polymatrix.init.initpolymatrix import init_poly_matrix
@@ -47,7 +47,7 @@ class SetElementAtExprMixin(ExpressionBaseMixin):
if polynomial is None:
polynomial = 0
- @dataclass_abc.dataclass_abc(frozen=True)
+ @dataclassabc.dataclassabc(frozen=True)
class SetElementAtPolyMatrix(PolyMatrixMixin):
underlying: PolyMatrixMixin
shape: tuple[int, int]
diff --git a/polymatrix/expression/mixins/squeezeexprmixin.py b/polymatrix/expression/mixins/squeezeexprmixin.py
index 14cf1f3..6800890 100644
--- a/polymatrix/expression/mixins/squeezeexprmixin.py
+++ b/polymatrix/expression/mixins/squeezeexprmixin.py
@@ -1,8 +1,5 @@
import abc
-import collections
-import typing
-import dataclass_abc
from polymatrix.polymatrix.init.initpolymatrix import init_poly_matrix
from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
diff --git a/polymatrix/expression/mixins/substituteexprmixin.py b/polymatrix/expression/mixins/substituteexprmixin.py
index f69c870..e693de1 100644
--- a/polymatrix/expression/mixins/substituteexprmixin.py
+++ b/polymatrix/expression/mixins/substituteexprmixin.py
@@ -4,6 +4,7 @@ import collections
import itertools
import math
import typing
+from polymatrix.expression.impl.reshapeexprmixin import ReshapeExprImpl
from polymatrix.polymatrix.init.initpolymatrix import init_poly_matrix
from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
@@ -29,6 +30,7 @@ class SubstituteExprMixin(ExpressionBaseMixin):
self,
state: ExpressionState,
) -> tuple[ExpressionState, PolyMatrix]:
+
state, underlying = self.underlying.apply(state=state)
def acc_substitutions(acc, next):
@@ -40,9 +42,14 @@ class SubstituteExprMixin(ExpressionBaseMixin):
if indices is None:
return acc
- state, substitution = expr.apply(state)
+ state, substitution = ReshapeExprImpl(
+ underlying=expr,
+ new_shape=(-1, 1),
+ ).apply(state)
- assert substitution.shape[1] == 1, f'The following expression has to be a vector {expr=}'
+ # # todo: improve this?
+ # substitution = substitution.reshape(-1, 1)
+ # assert substitution.shape[1] == 1, f'The substitutions have to be a vector {substitution=}'
def gen_polynomials():
for row in range(substitution.shape[0]):
diff --git a/polymatrix/expression/mixins/symmetricexprmixin.py b/polymatrix/expression/mixins/symmetricexprmixin.py
index e41e889..2677501 100644
--- a/polymatrix/expression/mixins/symmetricexprmixin.py
+++ b/polymatrix/expression/mixins/symmetricexprmixin.py
@@ -2,7 +2,7 @@
import abc
import collections
import itertools
-import dataclass_abc
+import dataclassabc
from polymatrix.polymatrix.mixins.polymatrixmixin import PolyMatrixMixin
from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
@@ -26,7 +26,7 @@ class SymmetricExprMixin(ExpressionBaseMixin):
assert underlying.shape[0] == underlying.shape[1]
- @dataclass_abc.dataclass_abc(frozen=True)
+ @dataclassabc.dataclassabc(frozen=True)
class SymmetricPolyMatrix(PolyMatrixMixin):
underlying: PolyMatrixMixin
diff --git a/polymatrix/expression/mixins/tosortedvariablesmixin.py b/polymatrix/expression/mixins/tosortedvariablesmixin.py
index b4c8d19..eb80597 100644
--- a/polymatrix/expression/mixins/tosortedvariablesmixin.py
+++ b/polymatrix/expression/mixins/tosortedvariablesmixin.py
@@ -8,7 +8,7 @@ from polymatrix.polymatrix.polymatrix import PolyMatrix
from polymatrix.expressionstate.expressionstate import ExpressionState
-class ToSortedVariablesMixin(ExpressionBaseMixin):
+class ToSortedVariablesExprMixin(ExpressionBaseMixin):
@property
@abc.abstractmethod
def underlying(self) -> ExpressionBaseMixin:
diff --git a/polymatrix/expression/mixins/transposeexprmixin.py b/polymatrix/expression/mixins/transposeexprmixin.py
index 4153518..5aa59e2 100644
--- a/polymatrix/expression/mixins/transposeexprmixin.py
+++ b/polymatrix/expression/mixins/transposeexprmixin.py
@@ -2,7 +2,7 @@
import abc
import dataclasses
import typing
-import dataclass_abc
+import dataclassabc
from polymatrix.polymatrix.mixins.polymatrixmixin import PolyMatrixMixin
from polymatrix.polymatrix.init.initpolymatrix import init_poly_matrix
@@ -24,7 +24,7 @@ class TransposeExprMixin(ExpressionBaseMixin):
) -> tuple[ExpressionState, PolyMatrix]:
state, underlying = self.underlying.apply(state=state)
- @dataclass_abc.dataclass_abc(frozen=True)
+ @dataclassabc.dataclassabc(frozen=True)
class TransposePolyMatrix(PolyMatrixMixin):
underlying: PolyMatrixMixin
shape: tuple[int, int]
diff --git a/polymatrix/expression/mixins/vstackexprmixin.py b/polymatrix/expression/mixins/vstackexprmixin.py
index 8d6c25d..fd68ca3 100644
--- a/polymatrix/expression/mixins/vstackexprmixin.py
+++ b/polymatrix/expression/mixins/vstackexprmixin.py
@@ -1,7 +1,7 @@
import abc
import itertools
-import dataclass_abc
+import dataclassabc
from polymatrix.polymatrix.mixins.polymatrixmixin import PolyMatrixMixin
from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
@@ -29,7 +29,7 @@ class VStackExprMixin(ExpressionBaseMixin):
for underlying in all_underlying:
assert underlying.shape[1] == all_underlying[0].shape[1], f'{underlying.shape[1]} not equal {all_underlying[0].shape[1]}'
- @dataclass_abc.dataclass_abc(frozen=True)
+ @dataclassabc.dataclassabc(frozen=True)
class VStackPolyMatrix(PolyMatrixMixin):
all_underlying: tuple[PolyMatrixMixin]
underlying_row_range: tuple[tuple[int, int], ...]
diff --git a/polymatrix/expression/parametrizeexpr.py b/polymatrix/expression/parametrizeexpr.py
deleted file mode 100644
index f98fdcd..0000000
--- a/polymatrix/expression/parametrizeexpr.py
+++ /dev/null
@@ -1,4 +0,0 @@
-from polymatrix.expression.mixins.parametrizeexprmixin import ParametrizeExprMixin
-
-class ParametrizeExpr(ParametrizeExprMixin):
- pass
diff --git a/polymatrix/expression/quadraticinexpr.py b/polymatrix/expression/quadraticinexpr.py
deleted file mode 100644
index bab76f6..0000000
--- a/polymatrix/expression/quadraticinexpr.py
+++ /dev/null
@@ -1,4 +0,0 @@
-from polymatrix.expression.mixins.quadraticinexprmixin import QuadraticInExprMixin
-
-class QuadraticInExpr(QuadraticInExprMixin):
- pass
diff --git a/polymatrix/expression/quadraticmonomialsexpr.py b/polymatrix/expression/quadraticmonomialsexpr.py
deleted file mode 100644
index 77753a5..0000000
--- a/polymatrix/expression/quadraticmonomialsexpr.py
+++ /dev/null
@@ -1,4 +0,0 @@
-from polymatrix.expression.mixins.quadraticmonomialsexprmixin import QuadraticMonomialsExprMixin
-
-class QuadraticMonomialsExpr(QuadraticMonomialsExprMixin):
- pass
diff --git a/polymatrix/expression/repmatexpr.py b/polymatrix/expression/repmatexpr.py
deleted file mode 100644
index bb983be..0000000
--- a/polymatrix/expression/repmatexpr.py
+++ /dev/null
@@ -1,4 +0,0 @@
-from polymatrix.expression.mixins.repmatexprmixin import RepMatExprMixin
-
-class RepMatExpr(RepMatExprMixin):
- pass
diff --git a/polymatrix/expression/reshapeexpr.py b/polymatrix/expression/reshapeexpr.py
deleted file mode 100644
index 01ea7dd..0000000
--- a/polymatrix/expression/reshapeexpr.py
+++ /dev/null
@@ -1,4 +0,0 @@
-from polymatrix.expression.mixins.reshapeexprmixin import ReshapeExprMixin
-
-class ReshapeExpr(ReshapeExprMixin):
- pass
diff --git a/polymatrix/expression/setelementatexpr.py b/polymatrix/expression/setelementatexpr.py
deleted file mode 100644
index 147d1f8..0000000
--- a/polymatrix/expression/setelementatexpr.py
+++ /dev/null
@@ -1,4 +0,0 @@
-from polymatrix.expression.mixins.setelementatexprmixin import SetElementAtExprMixin
-
-class SetElementAtExpr(SetElementAtExprMixin):
- pass
diff --git a/polymatrix/expression/squeezeexpr.py b/polymatrix/expression/squeezeexpr.py
deleted file mode 100644
index 5472764..0000000
--- a/polymatrix/expression/squeezeexpr.py
+++ /dev/null
@@ -1,4 +0,0 @@
-from polymatrix.expression.mixins.squeezeexprmixin import SqueezeExprMixin
-
-class SqueezeExpr(SqueezeExprMixin):
- pass
diff --git a/polymatrix/expression/substituteexpr.py b/polymatrix/expression/substituteexpr.py
deleted file mode 100644
index 3fd4916..0000000
--- a/polymatrix/expression/substituteexpr.py
+++ /dev/null
@@ -1,4 +0,0 @@
-from polymatrix.expression.mixins.substituteexprmixin import SubstituteExprMixin
-
-class SubstituteExpr(SubstituteExprMixin):
- pass
diff --git a/polymatrix/expression/subtractmonomialsexpr.py b/polymatrix/expression/subtractmonomialsexpr.py
deleted file mode 100644
index 9bc92ea..0000000
--- a/polymatrix/expression/subtractmonomialsexpr.py
+++ /dev/null
@@ -1,4 +0,0 @@
-from polymatrix.expression.mixins.subtractmonomialsexprmixin import SubtractMonomialsExprMixin
-
-class SubtractMonomialsExpr(SubtractMonomialsExprMixin):
- pass
diff --git a/polymatrix/expression/sumexpr.py b/polymatrix/expression/sumexpr.py
deleted file mode 100644
index 7b62e59..0000000
--- a/polymatrix/expression/sumexpr.py
+++ /dev/null
@@ -1,4 +0,0 @@
-from polymatrix.expression.mixins.sumexprmixin import SumExprMixin
-
-class SumExpr(SumExprMixin):
- pass
diff --git a/polymatrix/expression/symmetricexpr.py b/polymatrix/expression/symmetricexpr.py
deleted file mode 100644
index ffbaa90..0000000
--- a/polymatrix/expression/symmetricexpr.py
+++ /dev/null
@@ -1,4 +0,0 @@
-from polymatrix.expression.mixins.symmetricexprmixin import SymmetricExprMixin
-
-class SymmetricExpr(SymmetricExprMixin):
- pass
diff --git a/polymatrix/expression/toconstantexpr.py b/polymatrix/expression/toconstantexpr.py
deleted file mode 100644
index d1fb2a9..0000000
--- a/polymatrix/expression/toconstantexpr.py
+++ /dev/null
@@ -1,4 +0,0 @@
-from polymatrix.expression.mixins.toconstantexprmixin import ToConstantExprMixin
-
-class ToConstantExpr(ToConstantExprMixin):
- pass
diff --git a/polymatrix/expression/toquadraticexpr.py b/polymatrix/expression/toquadraticexpr.py
deleted file mode 100644
index ff78d8c..0000000
--- a/polymatrix/expression/toquadraticexpr.py
+++ /dev/null
@@ -1,4 +0,0 @@
-from polymatrix.expression.mixins.toquadraticexprmixin import ToQuadraticExprMixin
-
-class ToQuadraticExpr(ToQuadraticExprMixin):
- pass
diff --git a/polymatrix/expression/tosortedvariables.py b/polymatrix/expression/tosortedvariables.py
deleted file mode 100644
index 89ca315..0000000
--- a/polymatrix/expression/tosortedvariables.py
+++ /dev/null
@@ -1,4 +0,0 @@
-from polymatrix.expression.mixins.tosortedvariablesmixin import ToSortedVariablesMixin
-
-class ToSortedVariables(ToSortedVariablesMixin):
- pass
diff --git a/polymatrix/expression/tosymmetricmatrixexpr.py b/polymatrix/expression/tosymmetricmatrixexpr.py
deleted file mode 100644
index 119e13b..0000000
--- a/polymatrix/expression/tosymmetricmatrixexpr.py
+++ /dev/null
@@ -1,4 +0,0 @@
-from polymatrix.expression.mixins.tosymmetricmatrixexprmixin import ToSymmetricMatrixExprMixin
-
-class ToSymmetricMatrixExpr(ToSymmetricMatrixExprMixin):
- pass
diff --git a/polymatrix/expression/transposeexpr.py b/polymatrix/expression/transposeexpr.py
deleted file mode 100644
index 908a9e4..0000000
--- a/polymatrix/expression/transposeexpr.py
+++ /dev/null
@@ -1,4 +0,0 @@
-from polymatrix.expression.mixins.transposeexprmixin import TransposeExprMixin
-
-class TransposeExpr(TransposeExprMixin):
- pass
diff --git a/polymatrix/expression/truncateexpr.py b/polymatrix/expression/truncateexpr.py
deleted file mode 100644
index b555480..0000000
--- a/polymatrix/expression/truncateexpr.py
+++ /dev/null
@@ -1,4 +0,0 @@
-from polymatrix.expression.mixins.truncateexprmixin import TruncateExprMixin
-
-class TruncateExpr(TruncateExprMixin):
- pass
diff --git a/polymatrix/expression/vstackexpr.py b/polymatrix/expression/vstackexpr.py
deleted file mode 100644
index 7e9a1d7..0000000
--- a/polymatrix/expression/vstackexpr.py
+++ /dev/null
@@ -1,4 +0,0 @@
-from polymatrix.expression.mixins.vstackexprmixin import VStackExprMixin
-
-class VStackExpr(VStackExprMixin):
- pass
diff --git a/polymatrix/expressionstate/impl/expressionstateimpl.py b/polymatrix/expressionstate/impl/expressionstateimpl.py
index 31710fb..3890a27 100644
--- a/polymatrix/expressionstate/impl/expressionstateimpl.py
+++ b/polymatrix/expressionstate/impl/expressionstateimpl.py
@@ -1,10 +1,10 @@
from functools import cached_property
-import dataclass_abc
+import dataclassabc
from polymatrix.expressionstate.expressionstate import ExpressionState
from typing import Optional
-@dataclass_abc.dataclass_abc(frozen=True)
+@dataclassabc.dataclassabc(frozen=True)
class ExpressionStateImpl(ExpressionState):
n_param: int
offset_dict: dict
diff --git a/polymatrix/polymatrix/impl/polymatriximpl.py b/polymatrix/polymatrix/impl/polymatriximpl.py
index 0c269ca..cfca663 100644
--- a/polymatrix/polymatrix/impl/polymatriximpl.py
+++ b/polymatrix/polymatrix/impl/polymatriximpl.py
@@ -1,8 +1,8 @@
-import dataclass_abc
+import dataclassabc
from polymatrix.polymatrix.polymatrix import PolyMatrix
-@dataclass_abc.dataclass_abc(frozen=True)
+@dataclassabc.dataclassabc(frozen=True)
class PolyMatrixImpl(PolyMatrix):
terms: dict
shape: tuple[int, ...]
diff --git a/polymatrix/statemonad/impl/statemonadimpl.py b/polymatrix/statemonad/impl/statemonadimpl.py
index 5f8c6b8..6b9270a 100644
--- a/polymatrix/statemonad/impl/statemonadimpl.py
+++ b/polymatrix/statemonad/impl/statemonadimpl.py
@@ -1,8 +1,8 @@
-import dataclass_abc
+import dataclassabc
from polymatrix.statemonad.statemonad import StateMonad
from typing import Callable
-@dataclass_abc.dataclass_abc(frozen=True)
+@dataclassabc.dataclassabc(frozen=True)
class StateMonadImpl(StateMonad):
apply_func: Callable