summaryrefslogtreecommitdiffstats
path: root/polymatrix/expression/init
diff options
context:
space:
mode:
Diffstat (limited to 'polymatrix/expression/init')
-rw-r--r--polymatrix/expression/init/initderivativeexpr.py17
-rw-r--r--polymatrix/expression/init/initderivativekey.py11
-rw-r--r--polymatrix/expression/init/initdeterminantexpr.py10
-rw-r--r--polymatrix/expression/init/initdivisionexpr.py12
-rw-r--r--polymatrix/expression/init/initelemmultexpr.py12
-rw-r--r--polymatrix/expression/init/initevalexpr.py21
-rw-r--r--polymatrix/expression/init/initexpression.py10
-rw-r--r--polymatrix/expression/init/initexpressionstate.py19
-rw-r--r--polymatrix/expression/init/initforallexpr.py12
-rw-r--r--polymatrix/expression/init/initfromarrayexpr.py31
-rw-r--r--polymatrix/expression/init/initgetitemexpr.py12
-rw-r--r--polymatrix/expression/init/initkktexpr.py15
-rw-r--r--polymatrix/expression/init/initparametrizesymbolsexpr.py14
-rw-r--r--polymatrix/expression/init/initpolymatrix.py16
-rw-r--r--polymatrix/expression/init/initquadraticinexpr.py12
-rw-r--r--polymatrix/expression/init/initrepmatexpr.py12
-rw-r--r--polymatrix/expression/init/inittransposeexpr.py10
-rw-r--r--polymatrix/expression/init/initvstackexpr.py9
18 files changed, 255 insertions, 0 deletions
diff --git a/polymatrix/expression/init/initderivativeexpr.py b/polymatrix/expression/init/initderivativeexpr.py
new file mode 100644
index 0000000..c640f47
--- /dev/null
+++ b/polymatrix/expression/init/initderivativeexpr.py
@@ -0,0 +1,17 @@
+from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
+from polymatrix.expression.impl.derivativeexprimpl import DerivativeExprImpl
+
+
+def init_derivative_expr(
+ underlying: ExpressionBaseMixin,
+ variables: tuple,
+ introduce_derivatives: bool = None,
+):
+ if introduce_derivatives is None:
+ introduce_derivatives = False
+
+ return DerivativeExprImpl(
+ underlying=underlying,
+ variables=variables,
+ introduce_derivatives=introduce_derivatives,
+)
diff --git a/polymatrix/expression/init/initderivativekey.py b/polymatrix/expression/init/initderivativekey.py
new file mode 100644
index 0000000..db249ec
--- /dev/null
+++ b/polymatrix/expression/init/initderivativekey.py
@@ -0,0 +1,11 @@
+from polymatrix.expression.impl.derivativekeyimpl import DerivativeKeyImpl
+
+
+def init_derivative_key(
+ variable: int,
+ with_respect_to: int
+):
+ return DerivativeKeyImpl(
+ variable=variable,
+ with_respect_to=with_respect_to,
+)
diff --git a/polymatrix/expression/init/initdeterminantexpr.py b/polymatrix/expression/init/initdeterminantexpr.py
new file mode 100644
index 0000000..f0d1bb5
--- /dev/null
+++ b/polymatrix/expression/init/initdeterminantexpr.py
@@ -0,0 +1,10 @@
+from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
+from polymatrix.expression.impl.determinantexprimpl import DeterminantExprImpl
+
+
+def init_determinant_expr(
+ underlying: ExpressionBaseMixin,
+):
+ return DeterminantExprImpl(
+ underlying=underlying,
+)
diff --git a/polymatrix/expression/init/initdivisionexpr.py b/polymatrix/expression/init/initdivisionexpr.py
new file mode 100644
index 0000000..2a701a9
--- /dev/null
+++ b/polymatrix/expression/init/initdivisionexpr.py
@@ -0,0 +1,12 @@
+from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
+from polymatrix.expression.impl.divisionexprimpl import DivisionExprImpl
+
+
+def init_division_expr(
+ left: ExpressionBaseMixin,
+ right: ExpressionBaseMixin,
+):
+ return DivisionExprImpl(
+ left=left,
+ right=right,
+)
diff --git a/polymatrix/expression/init/initelemmultexpr.py b/polymatrix/expression/init/initelemmultexpr.py
new file mode 100644
index 0000000..ae0e85f
--- /dev/null
+++ b/polymatrix/expression/init/initelemmultexpr.py
@@ -0,0 +1,12 @@
+from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
+from polymatrix.expression.impl.elemmultexprimpl import ElemMultExprImpl
+
+
+def init_elem_mult_expr(
+ left: ExpressionBaseMixin,
+ right: ExpressionBaseMixin,
+):
+ return ElemMultExprImpl(
+ left=left,
+ right=right,
+)
diff --git a/polymatrix/expression/init/initevalexpr.py b/polymatrix/expression/init/initevalexpr.py
new file mode 100644
index 0000000..deeb4e9
--- /dev/null
+++ b/polymatrix/expression/init/initevalexpr.py
@@ -0,0 +1,21 @@
+from tkinter import Variable
+from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
+from polymatrix.expression.impl.evalexprimpl import EvalExprImpl
+
+
+def init_eval_expr(
+ underlying: ExpressionBaseMixin,
+ variables: tuple,
+ eval_values: tuple,
+):
+ if not isinstance(variables, tuple):
+ variables = (variables,)
+
+ if not isinstance(eval_values, tuple):
+ eval_values = (eval_values,)
+
+ return EvalExprImpl(
+ underlying=underlying,
+ variables=variables,
+ eval_values=eval_values,
+)
diff --git a/polymatrix/expression/init/initexpression.py b/polymatrix/expression/init/initexpression.py
new file mode 100644
index 0000000..7262e47
--- /dev/null
+++ b/polymatrix/expression/init/initexpression.py
@@ -0,0 +1,10 @@
+from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
+from polymatrix.expression.impl.expressionimpl import ExpressionImpl
+
+
+def init_expression(
+ underlying: ExpressionBaseMixin,
+):
+ return ExpressionImpl(
+ underlying=underlying,
+)
diff --git a/polymatrix/expression/init/initexpressionstate.py b/polymatrix/expression/init/initexpressionstate.py
new file mode 100644
index 0000000..a7d3aac
--- /dev/null
+++ b/polymatrix/expression/init/initexpressionstate.py
@@ -0,0 +1,19 @@
+from polymatrix.expression.impl.expressionstateimpl import ExpressionStateImpl
+
+
+def init_expression_state(
+ n_param: int = None,
+ offset_dict: dict = None,
+):
+ if n_param is None:
+ n_param = 0
+
+ if offset_dict is None:
+ offset_dict = {}
+
+ return ExpressionStateImpl(
+ n_param=n_param,
+ offset_dict=offset_dict,
+ auxillary_terms=tuple(),
+ cached_polymatrix={},
+)
diff --git a/polymatrix/expression/init/initforallexpr.py b/polymatrix/expression/init/initforallexpr.py
new file mode 100644
index 0000000..84388d2
--- /dev/null
+++ b/polymatrix/expression/init/initforallexpr.py
@@ -0,0 +1,12 @@
+from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
+from polymatrix.expression.impl.forallexprimpl import ForAllExprImpl
+
+
+def init_for_all_expr(
+ underlying: ExpressionBaseMixin,
+ variables: tuple,
+):
+ return ForAllExprImpl(
+ underlying=underlying,
+ variables=variables,
+)
diff --git a/polymatrix/expression/init/initfromarrayexpr.py b/polymatrix/expression/init/initfromarrayexpr.py
new file mode 100644
index 0000000..6aab26c
--- /dev/null
+++ b/polymatrix/expression/init/initfromarrayexpr.py
@@ -0,0 +1,31 @@
+import typing
+import numpy as np
+
+from polymatrix.expression.impl.fromarrayexprimpl import FromArrayExprImpl
+
+
+def init_from_array_expr(
+ data: typing.Union[np.ndarray, tuple[tuple[float]]],
+):
+
+ match data:
+ case np.ndarray():
+ data = tuple(tuple(i for i in row) for row in data)
+
+ case tuple():
+
+ match data[0]:
+
+ case tuple():
+ n_col = len(data[0])
+ assert all(len(col) == n_col for col in data)
+
+ case _:
+ data = (data,)
+
+ case _:
+ data = ((data,),)
+
+ return FromArrayExprImpl(
+ data=data,
+ )
diff --git a/polymatrix/expression/init/initgetitemexpr.py b/polymatrix/expression/init/initgetitemexpr.py
new file mode 100644
index 0000000..140fa3a
--- /dev/null
+++ b/polymatrix/expression/init/initgetitemexpr.py
@@ -0,0 +1,12 @@
+from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
+from polymatrix.expression.impl.getitemexprimpl import GetItemExprImpl
+
+
+def init_get_item_expr(
+ underlying: ExpressionBaseMixin,
+ index: tuple,
+):
+ return GetItemExprImpl(
+ underlying=underlying,
+ index=index,
+)
diff --git a/polymatrix/expression/init/initkktexpr.py b/polymatrix/expression/init/initkktexpr.py
new file mode 100644
index 0000000..d8bfba8
--- /dev/null
+++ b/polymatrix/expression/init/initkktexpr.py
@@ -0,0 +1,15 @@
+from polymatrix.expression.mixins.expressionmixin import ExpressionMixin
+from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
+from polymatrix.expression.impl.kktexprimpl import KKTExprImpl
+
+
+def init_kkt_expr(
+ cost: ExpressionMixin,
+ equality: ExpressionMixin,
+ variables: ExpressionBaseMixin,
+):
+ return KKTExprImpl(
+ cost=cost,
+ equality=equality,
+ variables=variables,
+)
diff --git a/polymatrix/expression/init/initparametrizesymbolsexpr.py b/polymatrix/expression/init/initparametrizesymbolsexpr.py
new file mode 100644
index 0000000..8d7db55
--- /dev/null
+++ b/polymatrix/expression/init/initparametrizesymbolsexpr.py
@@ -0,0 +1,14 @@
+from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
+from polymatrix.expression.impl.parametrizesymbolsexprimpl import ParametrizeSymbolsExprImpl
+
+
+def init_parametrize_symbols_expr(
+ name: str,
+ underlying: ExpressionBaseMixin,
+ variables: tuple,
+):
+ return ParametrizeSymbolsExprImpl(
+ name=name,
+ underlying=underlying,
+ variables=variables,
+)
diff --git a/polymatrix/expression/init/initpolymatrix.py b/polymatrix/expression/init/initpolymatrix.py
new file mode 100644
index 0000000..e6a6cde
--- /dev/null
+++ b/polymatrix/expression/init/initpolymatrix.py
@@ -0,0 +1,16 @@
+from polymatrix.expression.impl.polymatriximpl import PolyMatrixImpl
+
+
+def init_poly_matrix(
+ terms: dict,
+ shape: tuple,
+ aux_terms: tuple[dict[tuple[int, ...], float]] = None,
+):
+ if aux_terms is None:
+ aux_terms = tuple()
+
+ return PolyMatrixImpl(
+ terms=terms,
+ shape=shape,
+ # aux_terms=aux_terms,
+)
diff --git a/polymatrix/expression/init/initquadraticinexpr.py b/polymatrix/expression/init/initquadraticinexpr.py
new file mode 100644
index 0000000..1e73745
--- /dev/null
+++ b/polymatrix/expression/init/initquadraticinexpr.py
@@ -0,0 +1,12 @@
+from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
+from polymatrix.expression.impl.quadraticinexprimpl import QuadraticInExprImpl
+
+
+def init_quadratic_in_expr(
+ underlying: ExpressionBaseMixin,
+ variables: tuple,
+):
+ return QuadraticInExprImpl(
+ underlying=underlying,
+ variables=variables,
+)
diff --git a/polymatrix/expression/init/initrepmatexpr.py b/polymatrix/expression/init/initrepmatexpr.py
new file mode 100644
index 0000000..2f7fb7c
--- /dev/null
+++ b/polymatrix/expression/init/initrepmatexpr.py
@@ -0,0 +1,12 @@
+from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
+from polymatrix.expression.impl.repmatexprimpl import RepMatExprImpl
+
+
+def init_rep_mat_expr(
+ underlying: ExpressionBaseMixin,
+ repetition: tuple,
+):
+ return RepMatExprImpl(
+ underlying=underlying,
+ repetition=repetition,
+)
diff --git a/polymatrix/expression/init/inittransposeexpr.py b/polymatrix/expression/init/inittransposeexpr.py
new file mode 100644
index 0000000..9ca9d91
--- /dev/null
+++ b/polymatrix/expression/init/inittransposeexpr.py
@@ -0,0 +1,10 @@
+from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
+from polymatrix.expression.impl.transposeexprimpl import TransposeExprImpl
+
+
+def init_transpose_expr(
+ underlying: ExpressionBaseMixin,
+):
+ return TransposeExprImpl(
+ underlying=underlying,
+)
diff --git a/polymatrix/expression/init/initvstackexpr.py b/polymatrix/expression/init/initvstackexpr.py
new file mode 100644
index 0000000..1d7834e
--- /dev/null
+++ b/polymatrix/expression/init/initvstackexpr.py
@@ -0,0 +1,9 @@
+from polymatrix.expression.impl.vstackexprimpl import VStackExprImpl
+
+
+def init_v_stack_expr(
+ underlying: tuple,
+):
+ return VStackExprImpl(
+ underlying=underlying,
+)