From 738ce853aa3c3fd9ccf70e61fb86536b61e56243 Mon Sep 17 00:00:00 2001 From: Michael Schneeberger Date: Tue, 20 Feb 2024 10:05:30 +0100 Subject: flatten polymatrix.expressionstate for better readibility --- polymatrix/__init__.py | 4 +- polymatrix/denserepr/from_.py | 2 +- polymatrix/denserepr/impl.py | 2 +- polymatrix/expression/expression.py | 2 +- polymatrix/expression/mixins/additionexprmixin.py | 2 +- polymatrix/expression/mixins/blockdiagexprmixin.py | 2 +- polymatrix/expression/mixins/cacheexprmixin.py | 2 +- .../expression/mixins/combinationsexprmixin.py | 2 +- .../expression/mixins/derivativeexprmixin.py | 2 +- .../expression/mixins/determinantexprmixin.py | 2 +- polymatrix/expression/mixins/diagexprmixin.py | 2 +- .../expression/mixins/divergenceexprmixin.py | 2 +- polymatrix/expression/mixins/divisionexprmixin.py | 2 +- polymatrix/expression/mixins/elemmultexprmixin.py | 2 +- polymatrix/expression/mixins/evalexprmixin.py | 2 +- .../expression/mixins/expressionbasemixin.py | 2 +- polymatrix/expression/mixins/eyeexprmixin.py | 2 +- polymatrix/expression/mixins/filterexprmixin.py | 2 +- .../expression/mixins/filterlinearpartexprmixin.py | 2 +- .../mixins/fromsymmetricmatrixexprmixin.py | 2 +- polymatrix/expression/mixins/fromtermsexprmixin.py | 2 +- polymatrix/expression/mixins/fromtupleexprmixin.py | 2 +- polymatrix/expression/mixins/getitemexprmixin.py | 2 +- .../mixins/halfnewtonpolytopeexprmixin.py | 2 +- .../expression/mixins/legendreseriesmixin.py | 2 +- polymatrix/expression/mixins/linearinexprmixin.py | 2 +- .../expression/mixins/linearmatrixinexprmixin.py | 2 +- .../expression/mixins/linearmonomialsexprmixin.py | 2 +- .../expression/mixins/matrixmultexprmixin.py | 2 +- polymatrix/expression/mixins/maxdegreeexprmixin.py | 2 +- polymatrix/expression/mixins/maxexprmixin.py | 2 +- .../expression/mixins/parametrizeexprmixin.py | 2 +- .../mixins/parametrizematrixexprmixin.py | 2 +- polymatrix/expression/mixins/productexprmixin.py | 2 +- .../expression/mixins/quadraticinexprmixin.py | 2 +- .../mixins/quadraticmonomialsexprmixin.py | 2 +- polymatrix/expression/mixins/repmatexprmixin.py | 2 +- polymatrix/expression/mixins/reshapeexprmixin.py | 2 +- .../expression/mixins/setelementatexprmixin.py | 2 +- polymatrix/expression/mixins/squeezeexprmixin.py | 2 +- .../expression/mixins/substituteexprmixin.py | 2 +- .../mixins/subtractmonomialsexprmixin.py | 2 +- polymatrix/expression/mixins/sumexprmixin.py | 2 +- polymatrix/expression/mixins/symmetricexprmixin.py | 2 +- .../expression/mixins/toconstantexprmixin.py | 2 +- .../expression/mixins/toquadraticexprmixin.py | 2 +- .../expression/mixins/tosortedvariablesmixin.py | 2 +- .../mixins/tosymmetricmatrixexprmixin.py | 2 +- polymatrix/expression/mixins/transposeexprmixin.py | 2 +- polymatrix/expression/mixins/truncateexprmixin.py | 2 +- polymatrix/expression/mixins/vstackexprmixin.py | 2 +- polymatrix/expression/to.py | 2 +- .../expression/utils/getderivativemonomials.py | 2 +- polymatrix/expression/utils/getmonomialindices.py | 2 +- polymatrix/expressionstate/abc.py | 4 ++ polymatrix/expressionstate/expressionstate.py | 4 -- polymatrix/expressionstate/impl.py | 11 ++++ polymatrix/expressionstate/impl/__init__.py | 0 .../expressionstate/impl/expressionstateimpl.py | 12 ---- polymatrix/expressionstate/init.py | 19 ++++++ polymatrix/expressionstate/init/__init__.py | 0 .../expressionstate/init/initexpressionstate.py | 19 ------ polymatrix/expressionstate/mixins.py | 68 +++++++++++++++++++++ polymatrix/expressionstate/mixins/__init__.py | 0 .../expressionstate/mixins/expressionstatemixin.py | 71 ---------------------- 65 files changed, 157 insertions(+), 161 deletions(-) create mode 100644 polymatrix/expressionstate/abc.py delete mode 100644 polymatrix/expressionstate/expressionstate.py create mode 100644 polymatrix/expressionstate/impl.py delete mode 100644 polymatrix/expressionstate/impl/__init__.py delete mode 100644 polymatrix/expressionstate/impl/expressionstateimpl.py create mode 100644 polymatrix/expressionstate/init.py delete mode 100644 polymatrix/expressionstate/init/__init__.py delete mode 100644 polymatrix/expressionstate/init/initexpressionstate.py create mode 100644 polymatrix/expressionstate/mixins.py delete mode 100644 polymatrix/expressionstate/mixins/__init__.py delete mode 100644 polymatrix/expressionstate/mixins/expressionstatemixin.py diff --git a/polymatrix/__init__.py b/polymatrix/__init__.py index 6c927d1..e513300 100644 --- a/polymatrix/__init__.py +++ b/polymatrix/__init__.py @@ -1,5 +1,5 @@ -from polymatrix.expressionstate.expressionstate import ExpressionState as internal_ExpressionState -from polymatrix.expressionstate.init.initexpressionstate import init_expression_state as internal_init_expression_state +from polymatrix.expressionstate.abc import ExpressionState as internal_ExpressionState +from polymatrix.expressionstate.init import init_expression_state as internal_init_expression_state from polymatrix.expression.expression import Expression as internal_Expression from polymatrix.expression.from_ import from_ as internal_from # from polymatrix.expression.from_ import from_sympy as internal_from_sympy diff --git a/polymatrix/denserepr/from_.py b/polymatrix/denserepr/from_.py index 52fda35..13b77b7 100644 --- a/polymatrix/denserepr/from_.py +++ b/polymatrix/denserepr/from_.py @@ -7,7 +7,7 @@ from polymatrix.denserepr.impl import DenseReprBufferImpl, DenseReprImpl from polymatrix.expression.expression import Expression from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin -from polymatrix.expressionstate.expressionstate import ExpressionState +from polymatrix.expressionstate.abc import ExpressionState from polymatrix.expression.utils.getvariableindices import get_variable_indices_from_variable from polymatrix.statemonad.init.initstatemonad import init_state_monad from polymatrix.statemonad.mixins.statemonadmixin import StateMonadMixin diff --git a/polymatrix/denserepr/impl.py b/polymatrix/denserepr/impl.py index 2b57e2a..5f54f86 100644 --- a/polymatrix/denserepr/impl.py +++ b/polymatrix/denserepr/impl.py @@ -4,7 +4,7 @@ import typing import numpy as np import scipy.sparse -from polymatrix.expressionstate.expressionstate import ExpressionState +from polymatrix.expressionstate.abc import ExpressionState from polymatrix.expression.utils.getvariableindices import get_variable_indices_from_variable diff --git a/polymatrix/expression/expression.py b/polymatrix/expression/expression.py index 22349c2..8cfcb82 100644 --- a/polymatrix/expression/expression.py +++ b/polymatrix/expression/expression.py @@ -11,7 +11,7 @@ from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin from polymatrix.expression.op import diff, linear_in, linear_monomials, legendre from polymatrix.polymatrix.polymatrix import PolyMatrix -from polymatrix.expressionstate.expressionstate import ExpressionState +from polymatrix.expressionstate.abc import ExpressionState class Expression( diff --git a/polymatrix/expression/mixins/additionexprmixin.py b/polymatrix/expression/mixins/additionexprmixin.py index 6257d55..cf64254 100644 --- a/polymatrix/expression/mixins/additionexprmixin.py +++ b/polymatrix/expression/mixins/additionexprmixin.py @@ -8,7 +8,7 @@ from polymatrix.utils.tooperatorexception import to_operator_exception from polymatrix.polymatrix.init.initpolymatrix import init_poly_matrix from polymatrix.polymatrix.mixins.polymatrixmixin import PolyMatrixMixin from polymatrix.polymatrix.polymatrix import PolyMatrix -from polymatrix.expressionstate.expressionstate import ExpressionState +from polymatrix.expressionstate.abc import ExpressionState from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin diff --git a/polymatrix/expression/mixins/blockdiagexprmixin.py b/polymatrix/expression/mixins/blockdiagexprmixin.py index 0bafd0d..2226025 100644 --- a/polymatrix/expression/mixins/blockdiagexprmixin.py +++ b/polymatrix/expression/mixins/blockdiagexprmixin.py @@ -6,7 +6,7 @@ from polymatrix.polymatrix.mixins.polymatrixmixin import PolyMatrixMixin from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin from polymatrix.polymatrix.polymatrix import PolyMatrix -from polymatrix.expressionstate.expressionstate import ExpressionState +from polymatrix.expressionstate.abc import ExpressionState class BlockDiagExprMixin(ExpressionBaseMixin): diff --git a/polymatrix/expression/mixins/cacheexprmixin.py b/polymatrix/expression/mixins/cacheexprmixin.py index 7a92259..55df49e 100644 --- a/polymatrix/expression/mixins/cacheexprmixin.py +++ b/polymatrix/expression/mixins/cacheexprmixin.py @@ -5,7 +5,7 @@ from polymatrix.polymatrix.mixins.polymatrixasdictmixin import PolyMatrixAsDictM from polymatrix.polymatrix.init.initpolymatrix import init_poly_matrix from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin -from polymatrix.expressionstate.mixins.expressionstatemixin import ExpressionStateMixin +from polymatrix.expressionstate.mixins import ExpressionStateMixin from polymatrix.polymatrix.mixins.polymatrixmixin import PolyMatrixMixin diff --git a/polymatrix/expression/mixins/combinationsexprmixin.py b/polymatrix/expression/mixins/combinationsexprmixin.py index a9cc247..e513e8b 100644 --- a/polymatrix/expression/mixins/combinationsexprmixin.py +++ b/polymatrix/expression/mixins/combinationsexprmixin.py @@ -5,7 +5,7 @@ import itertools from polymatrix.polymatrix.init.initpolymatrix import init_poly_matrix from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin from polymatrix.polymatrix.polymatrix import PolyMatrix -from polymatrix.expressionstate.expressionstate import ExpressionState +from polymatrix.expressionstate.abc import ExpressionState from polymatrix.expression.utils.multiplymonomials import multiply_monomials diff --git a/polymatrix/expression/mixins/derivativeexprmixin.py b/polymatrix/expression/mixins/derivativeexprmixin.py index 15873b6..940516a 100644 --- a/polymatrix/expression/mixins/derivativeexprmixin.py +++ b/polymatrix/expression/mixins/derivativeexprmixin.py @@ -5,7 +5,7 @@ import typing from polymatrix.polymatrix.init.initpolymatrix import init_poly_matrix from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin from polymatrix.polymatrix.polymatrix import PolyMatrix -from polymatrix.expressionstate.expressionstate import ExpressionState +from polymatrix.expressionstate.abc import ExpressionState from polymatrix.expression.utils.getderivativemonomials import get_derivative_monomials from polymatrix.expression.utils.getvariableindices import get_variable_indices_from_variable from polymatrix.utils.getstacklines import FrameSummary diff --git a/polymatrix/expression/mixins/determinantexprmixin.py b/polymatrix/expression/mixins/determinantexprmixin.py index 79defa9..0adc589 100644 --- a/polymatrix/expression/mixins/determinantexprmixin.py +++ b/polymatrix/expression/mixins/determinantexprmixin.py @@ -7,7 +7,7 @@ from numpy import var from polymatrix.polymatrix.init.initpolymatrix import init_poly_matrix from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin from polymatrix.polymatrix.polymatrix import PolyMatrix -from polymatrix.expressionstate.expressionstate import ExpressionState +from polymatrix.expressionstate.abc import ExpressionState class DeterminantExprMixin(ExpressionBaseMixin): diff --git a/polymatrix/expression/mixins/diagexprmixin.py b/polymatrix/expression/mixins/diagexprmixin.py index 6651e13..497fa08 100644 --- a/polymatrix/expression/mixins/diagexprmixin.py +++ b/polymatrix/expression/mixins/diagexprmixin.py @@ -2,7 +2,7 @@ import abc import dataclassabc from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin -from polymatrix.expressionstate.mixins.expressionstatemixin import ExpressionStateMixin +from polymatrix.expressionstate.mixins import ExpressionStateMixin from polymatrix.polymatrix.mixins.polymatrixmixin import PolyMatrixMixin class DiagExprMixin(ExpressionBaseMixin): diff --git a/polymatrix/expression/mixins/divergenceexprmixin.py b/polymatrix/expression/mixins/divergenceexprmixin.py index 8ada607..1cf55b9 100644 --- a/polymatrix/expression/mixins/divergenceexprmixin.py +++ b/polymatrix/expression/mixins/divergenceexprmixin.py @@ -6,7 +6,7 @@ import typing from polymatrix.polymatrix.init.initpolymatrix import init_poly_matrix from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin from polymatrix.polymatrix.polymatrix import PolyMatrix -from polymatrix.expressionstate.expressionstate import ExpressionState +from polymatrix.expressionstate.abc import ExpressionState from polymatrix.expression.utils.getderivativemonomials import get_derivative_monomials from polymatrix.expression.utils.getvariableindices import get_variable_indices_from_variable diff --git a/polymatrix/expression/mixins/divisionexprmixin.py b/polymatrix/expression/mixins/divisionexprmixin.py index 29f6d6d..2321fe7 100644 --- a/polymatrix/expression/mixins/divisionexprmixin.py +++ b/polymatrix/expression/mixins/divisionexprmixin.py @@ -8,7 +8,7 @@ from polymatrix.utils.tooperatorexception import to_operator_exception from polymatrix.polymatrix.init.initpolymatrix import init_poly_matrix from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin from polymatrix.polymatrix.polymatrix import PolyMatrix -from polymatrix.expressionstate.expressionstate import ExpressionState +from polymatrix.expressionstate.abc import ExpressionState class DivisionExprMixin(ExpressionBaseMixin): diff --git a/polymatrix/expression/mixins/elemmultexprmixin.py b/polymatrix/expression/mixins/elemmultexprmixin.py index 37c6f6f..4ea6cfa 100644 --- a/polymatrix/expression/mixins/elemmultexprmixin.py +++ b/polymatrix/expression/mixins/elemmultexprmixin.py @@ -8,7 +8,7 @@ from polymatrix.polymatrix.init.initpolymatrix import init_poly_matrix from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin from polymatrix.polymatrix.mixins.polymatrixmixin import PolyMatrixMixin from polymatrix.polymatrix.polymatrix import PolyMatrix -from polymatrix.expressionstate.expressionstate import ExpressionState +from polymatrix.expressionstate.abc import ExpressionState from polymatrix.expression.utils.mergemonomialindices import merge_monomial_indices diff --git a/polymatrix/expression/mixins/evalexprmixin.py b/polymatrix/expression/mixins/evalexprmixin.py index e769d8b..7c8ac67 100644 --- a/polymatrix/expression/mixins/evalexprmixin.py +++ b/polymatrix/expression/mixins/evalexprmixin.py @@ -6,7 +6,7 @@ import math from polymatrix.polymatrix.init.initpolymatrix import init_poly_matrix from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin from polymatrix.polymatrix.polymatrix import PolyMatrix -from polymatrix.expressionstate.expressionstate import ExpressionState +from polymatrix.expressionstate.abc import ExpressionState from polymatrix.expression.utils.getvariableindices import get_variable_indices_from_variable diff --git a/polymatrix/expression/mixins/expressionbasemixin.py b/polymatrix/expression/mixins/expressionbasemixin.py index 8aedc25..58d6aba 100644 --- a/polymatrix/expression/mixins/expressionbasemixin.py +++ b/polymatrix/expression/mixins/expressionbasemixin.py @@ -1,6 +1,6 @@ import abc -from polymatrix.expressionstate.expressionstate import ExpressionState +from polymatrix.expressionstate.abc import ExpressionState from polymatrix.polymatrix.polymatrix import PolyMatrix diff --git a/polymatrix/expression/mixins/eyeexprmixin.py b/polymatrix/expression/mixins/eyeexprmixin.py index 7d844ce..d036e82 100644 --- a/polymatrix/expression/mixins/eyeexprmixin.py +++ b/polymatrix/expression/mixins/eyeexprmixin.py @@ -6,7 +6,7 @@ from polymatrix.polymatrix.mixins.polymatrixmixin import PolyMatrixMixin from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin from polymatrix.polymatrix.polymatrix import PolyMatrix -from polymatrix.expressionstate.expressionstate import ExpressionState +from polymatrix.expressionstate.abc import ExpressionState class EyeExprMixin(ExpressionBaseMixin): diff --git a/polymatrix/expression/mixins/filterexprmixin.py b/polymatrix/expression/mixins/filterexprmixin.py index ec549a8..07089a0 100644 --- a/polymatrix/expression/mixins/filterexprmixin.py +++ b/polymatrix/expression/mixins/filterexprmixin.py @@ -4,7 +4,7 @@ import abc from polymatrix.polymatrix.init.initpolymatrix import init_poly_matrix from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin from polymatrix.polymatrix.polymatrix import PolyMatrix -from polymatrix.expressionstate.expressionstate import ExpressionState +from polymatrix.expressionstate.abc import ExpressionState class FilterExprMixin(ExpressionBaseMixin): diff --git a/polymatrix/expression/mixins/filterlinearpartexprmixin.py b/polymatrix/expression/mixins/filterlinearpartexprmixin.py index 6b80006..01891c6 100644 --- a/polymatrix/expression/mixins/filterlinearpartexprmixin.py +++ b/polymatrix/expression/mixins/filterlinearpartexprmixin.py @@ -5,7 +5,7 @@ import collections from polymatrix.polymatrix.init.initpolymatrix import init_poly_matrix from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin from polymatrix.polymatrix.polymatrix import PolyMatrix -from polymatrix.expressionstate.expressionstate import ExpressionState +from polymatrix.expressionstate.abc import ExpressionState # is this class needed? diff --git a/polymatrix/expression/mixins/fromsymmetricmatrixexprmixin.py b/polymatrix/expression/mixins/fromsymmetricmatrixexprmixin.py index 395eda9..78ca85b 100644 --- a/polymatrix/expression/mixins/fromsymmetricmatrixexprmixin.py +++ b/polymatrix/expression/mixins/fromsymmetricmatrixexprmixin.py @@ -6,7 +6,7 @@ from polymatrix.expression.utils.getvariableindices import get_variable_indices_ from polymatrix.polymatrix.init.initpolymatrix import init_poly_matrix from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin -from polymatrix.expressionstate.mixins.expressionstatemixin import ExpressionStateMixin +from polymatrix.expressionstate.mixins import ExpressionStateMixin from polymatrix.polymatrix.mixins.polymatrixmixin import PolyMatrixMixin diff --git a/polymatrix/expression/mixins/fromtermsexprmixin.py b/polymatrix/expression/mixins/fromtermsexprmixin.py index 9d1c220..e979434 100644 --- a/polymatrix/expression/mixins/fromtermsexprmixin.py +++ b/polymatrix/expression/mixins/fromtermsexprmixin.py @@ -5,7 +5,7 @@ import sympy from polymatrix.polymatrix.init.initpolymatrix import init_poly_matrix from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin -from polymatrix.expressionstate.mixins.expressionstatemixin import ExpressionStateMixin +from polymatrix.expressionstate.mixins import ExpressionStateMixin from polymatrix.polymatrix.mixins.polymatrixmixin import PolyMatrixMixin diff --git a/polymatrix/expression/mixins/fromtupleexprmixin.py b/polymatrix/expression/mixins/fromtupleexprmixin.py index 551b20e..fa3dc43 100644 --- a/polymatrix/expression/mixins/fromtupleexprmixin.py +++ b/polymatrix/expression/mixins/fromtupleexprmixin.py @@ -8,7 +8,7 @@ from polymatrix.utils.getstacklines import FrameSummary from polymatrix.utils.tooperatorexception import to_operator_exception from polymatrix.polymatrix.init.initpolymatrix import init_poly_matrix from polymatrix.polymatrix.mixins.polymatrixmixin import PolyMatrixMixin -from polymatrix.expressionstate.mixins.expressionstatemixin import ExpressionStateMixin +from polymatrix.expressionstate.mixins import ExpressionStateMixin from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin diff --git a/polymatrix/expression/mixins/getitemexprmixin.py b/polymatrix/expression/mixins/getitemexprmixin.py index 4ac9aff..d5d2279 100644 --- a/polymatrix/expression/mixins/getitemexprmixin.py +++ b/polymatrix/expression/mixins/getitemexprmixin.py @@ -7,7 +7,7 @@ from polymatrix.polymatrix.mixins.polymatrixmixin import PolyMatrixMixin from polymatrix.polymatrix.init.initpolymatrix import init_poly_matrix from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin from polymatrix.polymatrix.polymatrix import PolyMatrix -from polymatrix.expressionstate.expressionstate import ExpressionState +from polymatrix.expressionstate.abc import ExpressionState class GetItemExprMixin(ExpressionBaseMixin): diff --git a/polymatrix/expression/mixins/halfnewtonpolytopeexprmixin.py b/polymatrix/expression/mixins/halfnewtonpolytopeexprmixin.py index ed1f6d9..ce5abcf 100644 --- a/polymatrix/expression/mixins/halfnewtonpolytopeexprmixin.py +++ b/polymatrix/expression/mixins/halfnewtonpolytopeexprmixin.py @@ -8,7 +8,7 @@ from polymatrix.expression.utils.getvariableindices import get_variable_indices_ from polymatrix.polymatrix.init.initpolymatrix import init_poly_matrix from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin -from polymatrix.expressionstate.mixins.expressionstatemixin import ExpressionStateMixin +from polymatrix.expressionstate.mixins import ExpressionStateMixin from polymatrix.polymatrix.mixins.polymatrixmixin import PolyMatrixMixin diff --git a/polymatrix/expression/mixins/legendreseriesmixin.py b/polymatrix/expression/mixins/legendreseriesmixin.py index 3232207..22b7253 100644 --- a/polymatrix/expression/mixins/legendreseriesmixin.py +++ b/polymatrix/expression/mixins/legendreseriesmixin.py @@ -3,7 +3,7 @@ import abc from polymatrix.utils.getstacklines import FrameSummary from polymatrix.polymatrix.polymatrix import PolyMatrix from polymatrix.polymatrix.init.initpolymatrix import init_poly_matrix -from polymatrix.expressionstate.expressionstate import ExpressionState +from polymatrix.expressionstate.abc import ExpressionState from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin diff --git a/polymatrix/expression/mixins/linearinexprmixin.py b/polymatrix/expression/mixins/linearinexprmixin.py index 9bcabbe..dedbd70 100644 --- a/polymatrix/expression/mixins/linearinexprmixin.py +++ b/polymatrix/expression/mixins/linearinexprmixin.py @@ -5,7 +5,7 @@ import collections from polymatrix.polymatrix.init.initpolymatrix import init_poly_matrix from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin from polymatrix.polymatrix.polymatrix import PolyMatrix -from polymatrix.expressionstate.expressionstate import ExpressionState +from polymatrix.expressionstate.abc import ExpressionState from polymatrix.expression.utils.getmonomialindices import get_monomial_indices from polymatrix.expression.utils.getvariableindices import get_variable_indices_from_variable diff --git a/polymatrix/expression/mixins/linearmatrixinexprmixin.py b/polymatrix/expression/mixins/linearmatrixinexprmixin.py index f5bd18f..aa728d0 100644 --- a/polymatrix/expression/mixins/linearmatrixinexprmixin.py +++ b/polymatrix/expression/mixins/linearmatrixinexprmixin.py @@ -6,7 +6,7 @@ from numpy import var from polymatrix.polymatrix.init.initpolymatrix import init_poly_matrix from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin from polymatrix.polymatrix.polymatrix import PolyMatrix -from polymatrix.expressionstate.expressionstate import ExpressionState +from polymatrix.expressionstate.abc import ExpressionState from polymatrix.expression.utils.getvariableindices import get_variable_indices_from_variable diff --git a/polymatrix/expression/mixins/linearmonomialsexprmixin.py b/polymatrix/expression/mixins/linearmonomialsexprmixin.py index 350ac6d..1020946 100644 --- a/polymatrix/expression/mixins/linearmonomialsexprmixin.py +++ b/polymatrix/expression/mixins/linearmonomialsexprmixin.py @@ -4,7 +4,7 @@ import dataclasses from polymatrix.polymatrix.init.initpolymatrix import init_poly_matrix from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin -from polymatrix.expressionstate.mixins.expressionstatemixin import ExpressionStateMixin +from polymatrix.expressionstate.mixins import ExpressionStateMixin from polymatrix.polymatrix.mixins.polymatrixmixin import PolyMatrixMixin from polymatrix.expression.utils.getvariableindices import get_variable_indices_from_variable from polymatrix.expression.utils.sortmonomials import sort_monomials diff --git a/polymatrix/expression/mixins/matrixmultexprmixin.py b/polymatrix/expression/mixins/matrixmultexprmixin.py index 98527e7..cede447 100644 --- a/polymatrix/expression/mixins/matrixmultexprmixin.py +++ b/polymatrix/expression/mixins/matrixmultexprmixin.py @@ -5,7 +5,7 @@ from polymatrix.utils.getstacklines import FrameSummary from polymatrix.polymatrix.init.initpolymatrix import init_poly_matrix from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin from polymatrix.polymatrix.polymatrix import PolyMatrix -from polymatrix.expressionstate.expressionstate import ExpressionState +from polymatrix.expressionstate.abc import ExpressionState from polymatrix.expression.utils.multiplypolynomial import multiply_polynomial from polymatrix.utils.tooperatorexception import to_operator_exception diff --git a/polymatrix/expression/mixins/maxdegreeexprmixin.py b/polymatrix/expression/mixins/maxdegreeexprmixin.py index b21c157..9f8d647 100644 --- a/polymatrix/expression/mixins/maxdegreeexprmixin.py +++ b/polymatrix/expression/mixins/maxdegreeexprmixin.py @@ -4,7 +4,7 @@ import abc from polymatrix.polymatrix.init.initpolymatrix import init_poly_matrix from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin from polymatrix.polymatrix.polymatrix import PolyMatrix -from polymatrix.expressionstate.expressionstate import ExpressionState +from polymatrix.expressionstate.abc import ExpressionState class MaxDegreeExprMixin(ExpressionBaseMixin): diff --git a/polymatrix/expression/mixins/maxexprmixin.py b/polymatrix/expression/mixins/maxexprmixin.py index 2ab4cad..884c911 100644 --- a/polymatrix/expression/mixins/maxexprmixin.py +++ b/polymatrix/expression/mixins/maxexprmixin.py @@ -3,7 +3,7 @@ import abc from polymatrix.polymatrix.init.initpolymatrix import init_poly_matrix from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin -from polymatrix.expressionstate.mixins.expressionstatemixin import ExpressionStateMixin +from polymatrix.expressionstate.mixins import ExpressionStateMixin from polymatrix.polymatrix.mixins.polymatrixmixin import PolyMatrixMixin diff --git a/polymatrix/expression/mixins/parametrizeexprmixin.py b/polymatrix/expression/mixins/parametrizeexprmixin.py index 198877e..ad2fce1 100644 --- a/polymatrix/expression/mixins/parametrizeexprmixin.py +++ b/polymatrix/expression/mixins/parametrizeexprmixin.py @@ -4,7 +4,7 @@ import dataclasses from polymatrix.polymatrix.init.initpolymatrix import init_poly_matrix from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin -from polymatrix.expressionstate.mixins.expressionstatemixin import ExpressionStateMixin +from polymatrix.expressionstate.mixins import ExpressionStateMixin from polymatrix.polymatrix.mixins.polymatrixmixin import PolyMatrixMixin diff --git a/polymatrix/expression/mixins/parametrizematrixexprmixin.py b/polymatrix/expression/mixins/parametrizematrixexprmixin.py index de7be88..d3d2694 100644 --- a/polymatrix/expression/mixins/parametrizematrixexprmixin.py +++ b/polymatrix/expression/mixins/parametrizematrixexprmixin.py @@ -4,7 +4,7 @@ import dataclasses from polymatrix.polymatrix.init.initpolymatrix import init_poly_matrix from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin -from polymatrix.expressionstate.mixins.expressionstatemixin import ExpressionStateMixin +from polymatrix.expressionstate.mixins import ExpressionStateMixin from polymatrix.polymatrix.mixins.polymatrixmixin import PolyMatrixMixin diff --git a/polymatrix/expression/mixins/productexprmixin.py b/polymatrix/expression/mixins/productexprmixin.py index 8299683..c11c416 100644 --- a/polymatrix/expression/mixins/productexprmixin.py +++ b/polymatrix/expression/mixins/productexprmixin.py @@ -6,7 +6,7 @@ from polymatrix.utils.getstacklines import FrameSummary from polymatrix.utils.tooperatorexception import to_operator_exception from polymatrix.polymatrix.init.initpolymatrix import init_poly_matrix from polymatrix.polymatrix.polymatrix import PolyMatrix -from polymatrix.expressionstate.expressionstate import ExpressionState +from polymatrix.expressionstate.abc import ExpressionState from polymatrix.expression.utils.multiplymonomials import multiply_monomials from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin diff --git a/polymatrix/expression/mixins/quadraticinexprmixin.py b/polymatrix/expression/mixins/quadraticinexprmixin.py index 052124f..da7d130 100644 --- a/polymatrix/expression/mixins/quadraticinexprmixin.py +++ b/polymatrix/expression/mixins/quadraticinexprmixin.py @@ -5,7 +5,7 @@ import collections from polymatrix.polymatrix.init.initpolymatrix import init_poly_matrix from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin from polymatrix.polymatrix.polymatrix import PolyMatrix -from polymatrix.expressionstate.expressionstate import ExpressionState +from polymatrix.expressionstate.abc import ExpressionState from polymatrix.expression.utils.getmonomialindices import get_monomial_indices from polymatrix.expression.utils.getvariableindices import get_variable_indices_from_variable from polymatrix.expression.utils.splitmonomialindices import split_monomial_indices diff --git a/polymatrix/expression/mixins/quadraticmonomialsexprmixin.py b/polymatrix/expression/mixins/quadraticmonomialsexprmixin.py index 81fbcb9..71abc93 100644 --- a/polymatrix/expression/mixins/quadraticmonomialsexprmixin.py +++ b/polymatrix/expression/mixins/quadraticmonomialsexprmixin.py @@ -4,7 +4,7 @@ import dataclasses from polymatrix.polymatrix.init.initpolymatrix import init_poly_matrix from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin -from polymatrix.expressionstate.mixins.expressionstatemixin import ExpressionStateMixin +from polymatrix.expressionstate.mixins import ExpressionStateMixin from polymatrix.polymatrix.mixins.polymatrixmixin import PolyMatrixMixin from polymatrix.expression.utils.getvariableindices import get_variable_indices_from_variable from polymatrix.expression.utils.splitmonomialindices import split_monomial_indices diff --git a/polymatrix/expression/mixins/repmatexprmixin.py b/polymatrix/expression/mixins/repmatexprmixin.py index 8ed4811..00eaee2 100644 --- a/polymatrix/expression/mixins/repmatexprmixin.py +++ b/polymatrix/expression/mixins/repmatexprmixin.py @@ -2,7 +2,7 @@ import abc import dataclassabc from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin -from polymatrix.expressionstate.mixins.expressionstatemixin import ExpressionStateMixin +from polymatrix.expressionstate.mixins import ExpressionStateMixin from polymatrix.polymatrix.mixins.polymatrixmixin import PolyMatrixMixin class RepMatExprMixin(ExpressionBaseMixin): diff --git a/polymatrix/expression/mixins/reshapeexprmixin.py b/polymatrix/expression/mixins/reshapeexprmixin.py index 3f2e837..4377e31 100644 --- a/polymatrix/expression/mixins/reshapeexprmixin.py +++ b/polymatrix/expression/mixins/reshapeexprmixin.py @@ -6,7 +6,7 @@ import dataclassabc import numpy as np from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin -from polymatrix.expressionstate.mixins.expressionstatemixin import ExpressionStateMixin +from polymatrix.expressionstate.mixins import ExpressionStateMixin from polymatrix.polymatrix.mixins.polymatrixmixin import PolyMatrixMixin class ReshapeExprMixin(ExpressionBaseMixin): diff --git a/polymatrix/expression/mixins/setelementatexprmixin.py b/polymatrix/expression/mixins/setelementatexprmixin.py index 8af695c..4757a72 100644 --- a/polymatrix/expression/mixins/setelementatexprmixin.py +++ b/polymatrix/expression/mixins/setelementatexprmixin.py @@ -8,7 +8,7 @@ from polymatrix.polymatrix.mixins.polymatrixmixin import PolyMatrixMixin from polymatrix.polymatrix.init.initpolymatrix import init_poly_matrix from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin from polymatrix.polymatrix.polymatrix import PolyMatrix -from polymatrix.expressionstate.expressionstate import ExpressionState +from polymatrix.expressionstate.abc import ExpressionState class SetElementAtExprMixin(ExpressionBaseMixin): diff --git a/polymatrix/expression/mixins/squeezeexprmixin.py b/polymatrix/expression/mixins/squeezeexprmixin.py index 6800890..2a8d849 100644 --- a/polymatrix/expression/mixins/squeezeexprmixin.py +++ b/polymatrix/expression/mixins/squeezeexprmixin.py @@ -4,7 +4,7 @@ import abc from polymatrix.polymatrix.init.initpolymatrix import init_poly_matrix from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin from polymatrix.polymatrix.polymatrix import PolyMatrix -from polymatrix.expressionstate.expressionstate import ExpressionState +from polymatrix.expressionstate.abc import ExpressionState # remove? diff --git a/polymatrix/expression/mixins/substituteexprmixin.py b/polymatrix/expression/mixins/substituteexprmixin.py index 432c9c6..b2e086d 100644 --- a/polymatrix/expression/mixins/substituteexprmixin.py +++ b/polymatrix/expression/mixins/substituteexprmixin.py @@ -7,7 +7,7 @@ import typing from polymatrix.polymatrix.init.initpolymatrix import init_poly_matrix from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin from polymatrix.polymatrix.polymatrix import PolyMatrix -from polymatrix.expressionstate.expressionstate import ExpressionState +from polymatrix.expressionstate.abc import ExpressionState from polymatrix.expression.utils.getvariableindices import get_variable_indices_from_variable from polymatrix.expression.utils.multiplypolynomial import multiply_polynomial diff --git a/polymatrix/expression/mixins/subtractmonomialsexprmixin.py b/polymatrix/expression/mixins/subtractmonomialsexprmixin.py index 09f71b1..e48482e 100644 --- a/polymatrix/expression/mixins/subtractmonomialsexprmixin.py +++ b/polymatrix/expression/mixins/subtractmonomialsexprmixin.py @@ -4,7 +4,7 @@ import dataclasses from polymatrix.polymatrix.init.initpolymatrix import init_poly_matrix from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin -from polymatrix.expressionstate.mixins.expressionstatemixin import ExpressionStateMixin +from polymatrix.expressionstate.mixins import ExpressionStateMixin from polymatrix.polymatrix.mixins.polymatrixmixin import PolyMatrixMixin from polymatrix.expression.utils.getmonomialindices import get_monomial_indices from polymatrix.expression.utils.sortmonomials import sort_monomials diff --git a/polymatrix/expression/mixins/sumexprmixin.py b/polymatrix/expression/mixins/sumexprmixin.py index 9e12e07..e60255e 100644 --- a/polymatrix/expression/mixins/sumexprmixin.py +++ b/polymatrix/expression/mixins/sumexprmixin.py @@ -5,7 +5,7 @@ import dataclasses from polymatrix.polymatrix.init.initpolymatrix import init_poly_matrix from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin -from polymatrix.expressionstate.mixins.expressionstatemixin import ExpressionStateMixin +from polymatrix.expressionstate.mixins import ExpressionStateMixin from polymatrix.polymatrix.mixins.polymatrixmixin import PolyMatrixMixin diff --git a/polymatrix/expression/mixins/symmetricexprmixin.py b/polymatrix/expression/mixins/symmetricexprmixin.py index 2b191db..1624acc 100644 --- a/polymatrix/expression/mixins/symmetricexprmixin.py +++ b/polymatrix/expression/mixins/symmetricexprmixin.py @@ -7,7 +7,7 @@ from polymatrix.polymatrix.mixins.polymatrixmixin import PolyMatrixMixin from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin from polymatrix.polymatrix.polymatrix import PolyMatrix -from polymatrix.expressionstate.expressionstate import ExpressionState +from polymatrix.expressionstate.abc import ExpressionState class SymmetricExprMixin(ExpressionBaseMixin): diff --git a/polymatrix/expression/mixins/toconstantexprmixin.py b/polymatrix/expression/mixins/toconstantexprmixin.py index 91fbb2b..d8c055b 100644 --- a/polymatrix/expression/mixins/toconstantexprmixin.py +++ b/polymatrix/expression/mixins/toconstantexprmixin.py @@ -5,7 +5,7 @@ import collections from polymatrix.polymatrix.init.initpolymatrix import init_poly_matrix from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin from polymatrix.polymatrix.polymatrix import PolyMatrix -from polymatrix.expressionstate.expressionstate import ExpressionState +from polymatrix.expressionstate.abc import ExpressionState class ToConstantExprMixin(ExpressionBaseMixin): diff --git a/polymatrix/expression/mixins/toquadraticexprmixin.py b/polymatrix/expression/mixins/toquadraticexprmixin.py index 2bcaacb..63f3343 100644 --- a/polymatrix/expression/mixins/toquadraticexprmixin.py +++ b/polymatrix/expression/mixins/toquadraticexprmixin.py @@ -6,7 +6,7 @@ import dataclasses from polymatrix.polymatrix.init.initpolymatrix import init_poly_matrix from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin from polymatrix.polymatrix.polymatrix import PolyMatrix -from polymatrix.expressionstate.expressionstate import ExpressionState +from polymatrix.expressionstate.abc import ExpressionState # to be deleted? diff --git a/polymatrix/expression/mixins/tosortedvariablesmixin.py b/polymatrix/expression/mixins/tosortedvariablesmixin.py index d0a5d79..65f27f1 100644 --- a/polymatrix/expression/mixins/tosortedvariablesmixin.py +++ b/polymatrix/expression/mixins/tosortedvariablesmixin.py @@ -5,7 +5,7 @@ from polymatrix.expression.utils.getvariableindices import get_variable_indices_ from polymatrix.polymatrix.init.initpolymatrix import init_poly_matrix from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin from polymatrix.polymatrix.polymatrix import PolyMatrix -from polymatrix.expressionstate.expressionstate import ExpressionState +from polymatrix.expressionstate.abc import ExpressionState # to be deleted? diff --git a/polymatrix/expression/mixins/tosymmetricmatrixexprmixin.py b/polymatrix/expression/mixins/tosymmetricmatrixexprmixin.py index a34c2b3..d8d1dbe 100644 --- a/polymatrix/expression/mixins/tosymmetricmatrixexprmixin.py +++ b/polymatrix/expression/mixins/tosymmetricmatrixexprmixin.py @@ -4,7 +4,7 @@ import abc from polymatrix.expression.utils.getvariableindices import get_variable_indices_from_variable from polymatrix.polymatrix.init.initpolymatrix import init_poly_matrix from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin -from polymatrix.expressionstate.mixins.expressionstatemixin import ExpressionStateMixin +from polymatrix.expressionstate.mixins import ExpressionStateMixin from polymatrix.polymatrix.mixins.polymatrixmixin import PolyMatrixMixin diff --git a/polymatrix/expression/mixins/transposeexprmixin.py b/polymatrix/expression/mixins/transposeexprmixin.py index 7c60daa..858136b 100644 --- a/polymatrix/expression/mixins/transposeexprmixin.py +++ b/polymatrix/expression/mixins/transposeexprmixin.py @@ -8,7 +8,7 @@ from polymatrix.polymatrix.mixins.polymatrixmixin import PolyMatrixMixin from polymatrix.polymatrix.init.initpolymatrix import init_poly_matrix from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin from polymatrix.polymatrix.polymatrix import PolyMatrix -from polymatrix.expressionstate.expressionstate import ExpressionState +from polymatrix.expressionstate.abc import ExpressionState class TransposeExprMixin(ExpressionBaseMixin): diff --git a/polymatrix/expression/mixins/truncateexprmixin.py b/polymatrix/expression/mixins/truncateexprmixin.py index cadc856..8e01cf9 100644 --- a/polymatrix/expression/mixins/truncateexprmixin.py +++ b/polymatrix/expression/mixins/truncateexprmixin.py @@ -4,7 +4,7 @@ import abc from polymatrix.polymatrix.init.initpolymatrix import init_poly_matrix from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin from polymatrix.polymatrix.polymatrix import PolyMatrix -from polymatrix.expressionstate.expressionstate import ExpressionState +from polymatrix.expressionstate.abc import ExpressionState from polymatrix.expression.utils.getvariableindices import get_variable_indices_from_variable diff --git a/polymatrix/expression/mixins/vstackexprmixin.py b/polymatrix/expression/mixins/vstackexprmixin.py index e787495..ef842e0 100644 --- a/polymatrix/expression/mixins/vstackexprmixin.py +++ b/polymatrix/expression/mixins/vstackexprmixin.py @@ -6,7 +6,7 @@ from polymatrix.polymatrix.mixins.polymatrixmixin import PolyMatrixMixin from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin from polymatrix.polymatrix.polymatrix import PolyMatrix -from polymatrix.expressionstate.expressionstate import ExpressionState +from polymatrix.expressionstate.abc import ExpressionState class VStackExprMixin(ExpressionBaseMixin): diff --git a/polymatrix/expression/to.py b/polymatrix/expression/to.py index 53cd8a8..6d6286e 100644 --- a/polymatrix/expression/to.py +++ b/polymatrix/expression/to.py @@ -5,7 +5,7 @@ from polymatrix.expression.expression import Expression from polymatrix.expression.mixins.parametrizeexprmixin import ParametrizeExprMixin from polymatrix.expression.mixins.parametrizematrixexprmixin import ParametrizeMatrixExprMixin from polymatrix.expression.utils.getvariableindices import get_variable_indices_from_variable -from polymatrix.expressionstate.expressionstate import ExpressionState +from polymatrix.expressionstate.abc import ExpressionState from polymatrix.statemonad.init.initstatemonad import init_state_monad from polymatrix.statemonad.mixins.statemonadmixin import StateMonadMixin diff --git a/polymatrix/expression/utils/getderivativemonomials.py b/polymatrix/expression/utils/getderivativemonomials.py index 9bc1e1e..0b74135 100644 --- a/polymatrix/expression/utils/getderivativemonomials.py +++ b/polymatrix/expression/utils/getderivativemonomials.py @@ -2,7 +2,7 @@ import collections import dataclasses import itertools -from polymatrix.expressionstate.expressionstate import ExpressionState +from polymatrix.expressionstate.abc import ExpressionState def get_derivative_monomials( diff --git a/polymatrix/expression/utils/getmonomialindices.py b/polymatrix/expression/utils/getmonomialindices.py index ac6d5f7..42f9ca7 100644 --- a/polymatrix/expression/utils/getmonomialindices.py +++ b/polymatrix/expression/utils/getmonomialindices.py @@ -1,4 +1,4 @@ -from polymatrix.expressionstate.expressionstate import ExpressionState +from polymatrix.expressionstate.abc import ExpressionState from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin diff --git a/polymatrix/expressionstate/abc.py b/polymatrix/expressionstate/abc.py new file mode 100644 index 0000000..a2e1154 --- /dev/null +++ b/polymatrix/expressionstate/abc.py @@ -0,0 +1,4 @@ +from polymatrix.expressionstate.mixins import ExpressionStateMixin + +class ExpressionState(ExpressionStateMixin): + pass diff --git a/polymatrix/expressionstate/expressionstate.py b/polymatrix/expressionstate/expressionstate.py deleted file mode 100644 index 342432a..0000000 --- a/polymatrix/expressionstate/expressionstate.py +++ /dev/null @@ -1,4 +0,0 @@ -from polymatrix.expressionstate.mixins.expressionstatemixin import ExpressionStateMixin - -class ExpressionState(ExpressionStateMixin): - pass diff --git a/polymatrix/expressionstate/impl.py b/polymatrix/expressionstate/impl.py new file mode 100644 index 0000000..3188b5d --- /dev/null +++ b/polymatrix/expressionstate/impl.py @@ -0,0 +1,11 @@ +import dataclassabc + +from polymatrix.expressionstate.abc import ExpressionState + + +@dataclassabc.dataclassabc(frozen=True) +class ExpressionStateImpl(ExpressionState): + n_param: int + offset_dict: dict + auxillary_equations: dict[int, dict[tuple[int], float]] + cache: dict diff --git a/polymatrix/expressionstate/impl/__init__.py b/polymatrix/expressionstate/impl/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/polymatrix/expressionstate/impl/expressionstateimpl.py b/polymatrix/expressionstate/impl/expressionstateimpl.py deleted file mode 100644 index 3890a27..0000000 --- a/polymatrix/expressionstate/impl/expressionstateimpl.py +++ /dev/null @@ -1,12 +0,0 @@ -from functools import cached_property -import dataclassabc -from polymatrix.expressionstate.expressionstate import ExpressionState - -from typing import Optional - -@dataclassabc.dataclassabc(frozen=True) -class ExpressionStateImpl(ExpressionState): - n_param: int - offset_dict: dict - auxillary_equations: dict[int, dict[tuple[int], float]] - cache: dict diff --git a/polymatrix/expressionstate/init.py b/polymatrix/expressionstate/init.py new file mode 100644 index 0000000..1748d43 --- /dev/null +++ b/polymatrix/expressionstate/init.py @@ -0,0 +1,19 @@ +from polymatrix.expressionstate.impl 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_equations={}, + cache={}, +) diff --git a/polymatrix/expressionstate/init/__init__.py b/polymatrix/expressionstate/init/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/polymatrix/expressionstate/init/initexpressionstate.py b/polymatrix/expressionstate/init/initexpressionstate.py deleted file mode 100644 index 7e868da..0000000 --- a/polymatrix/expressionstate/init/initexpressionstate.py +++ /dev/null @@ -1,19 +0,0 @@ -from polymatrix.expressionstate.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_equations={}, - cache={}, -) diff --git a/polymatrix/expressionstate/mixins.py b/polymatrix/expressionstate/mixins.py new file mode 100644 index 0000000..538f652 --- /dev/null +++ b/polymatrix/expressionstate/mixins.py @@ -0,0 +1,68 @@ +import abc +import dataclasses +import typing + +from polymatrix.statemonad.mixins.statemixin import StateCacheMixin + + +class ExpressionStateMixin( + StateCacheMixin, +): + + @property + @abc.abstractmethod + def n_param(self) -> int: + """ + number of parameters used in polynomial matrix expressions + """ + + ... + + @property + @abc.abstractmethod + def offset_dict(self) -> dict[tuple[typing.Any], tuple[int, int]]: + """ + a variable consists of one or more parameters indexed by a start + and an end index + """ + + ... + + @property + @abc.abstractmethod + def auxillary_equations(self) -> dict[int, dict[tuple[int], float]]: + ... + + def get_name_from_offset(self, offset: int): + for variable, (start, end) in self.offset_dict.items(): + if start <= offset < end: + return f'{str(variable)}_{offset-start}' + + def get_key_from_offset(self, offset: int): + for variable, (start, end) in self.offset_dict.items(): + if start <= offset < end: + return variable + + def register( + self, + n_param: int, + key: typing.Any = None, + ) -> 'ExpressionStateMixin': + + if key is None: + updated_state = dataclasses.replace( + self, + n_param=self.n_param + n_param, + ) + + elif key not in self.offset_dict: + updated_state = dataclasses.replace( + self, + offset_dict=self.offset_dict | {key: (self.n_param, self.n_param + n_param)}, + n_param=self.n_param + n_param, + ) + + else: + updated_state = self + + return updated_state diff --git a/polymatrix/expressionstate/mixins/__init__.py b/polymatrix/expressionstate/mixins/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/polymatrix/expressionstate/mixins/expressionstatemixin.py b/polymatrix/expressionstate/mixins/expressionstatemixin.py deleted file mode 100644 index aaaa8ba..0000000 --- a/polymatrix/expressionstate/mixins/expressionstatemixin.py +++ /dev/null @@ -1,71 +0,0 @@ -import abc -import itertools -import dataclasses -import typing - -import sympy - -from polymatrix.statemonad.mixins.statemixin import StateCacheMixin - - -class ExpressionStateMixin( - StateCacheMixin, -): - - @property - @abc.abstractmethod - def n_param(self) -> int: - """ - number of parameters used in polynomial matrix expressions - """ - - ... - - @property - @abc.abstractmethod - def offset_dict(self) -> dict[tuple[typing.Any], tuple[int, int]]: - """ - a variable consists of one or more parameters indexed by a start - and an end index - """ - - ... - - @property - @abc.abstractmethod - def auxillary_equations(self) -> dict[int, dict[tuple[int], float]]: - ... - - def get_name_from_offset(self, offset: int): - for variable, (start, end) in self.offset_dict.items(): - if start <= offset < end: - return f'{str(variable)}_{offset-start}' - - def get_key_from_offset(self, offset: int): - for variable, (start, end) in self.offset_dict.items(): - if start <= offset < end: - return variable - - def register( - self, - n_param: int, - key: typing.Any = None, - ) -> 'ExpressionStateMixin': - - if key is None: - updated_state = dataclasses.replace( - self, - n_param=self.n_param + n_param, - ) - - elif key not in self.offset_dict: - updated_state = dataclasses.replace( - self, - offset_dict=self.offset_dict | {key: (self.n_param, self.n_param + n_param)}, - n_param=self.n_param + n_param, - ) - - else: - updated_state = self - - return updated_state -- cgit v1.2.1