diff options
author | Michael Schneeberger <michael.schneeberger@fhnw.ch> | 2024-03-27 14:52:22 +0100 |
---|---|---|
committer | Michael Schneeberger <michael.schneeberger@fhnw.ch> | 2024-03-27 14:52:22 +0100 |
commit | ebc557009b5343be74d1ef8e3a9e1c9b44d24a8f (patch) | |
tree | c1e6c67fb86e7afd864b3188db6829a463b47aba /polymatrix/expression/mixins/derivativeexprmixin.py | |
parent | add minimal documentation to the expression mixins (diff) | |
download | polymatrix-ebc557009b5343be74d1ef8e3a9e1c9b44d24a8f.tar.gz polymatrix-ebc557009b5343be74d1ef8e3a9e1c9b44d24a8f.zip |
format Python files with ruff
Diffstat (limited to 'polymatrix/expression/mixins/derivativeexprmixin.py')
-rw-r--r-- | polymatrix/expression/mixins/derivativeexprmixin.py | 36 |
1 files changed, 16 insertions, 20 deletions
diff --git a/polymatrix/expression/mixins/derivativeexprmixin.py b/polymatrix/expression/mixins/derivativeexprmixin.py index 64f2640..31a1e31 100644 --- a/polymatrix/expression/mixins/derivativeexprmixin.py +++ b/polymatrix/expression/mixins/derivativeexprmixin.py @@ -1,4 +1,3 @@ - import abc import typing @@ -7,7 +6,9 @@ from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin from polymatrix.polymatrix.abc import PolyMatrix from polymatrix.expressionstate.abc import ExpressionState from polymatrix.expression.utils.getderivativemonomials import differentiate_polynomial -from polymatrix.expression.utils.getvariableindices import get_variable_indices_from_variable +from polymatrix.expression.utils.getvariableindices import ( + get_variable_indices_from_variable, +) from polymatrix.utils.getstacklines import FrameSummary from polymatrix.utils.tooperatorexception import to_operator_exception @@ -23,43 +24,39 @@ class DerivativeExprMixin(ExpressionBaseMixin): @property @abc.abstractmethod - def underlying(self) -> ExpressionBaseMixin: - ... + def underlying(self) -> ExpressionBaseMixin: ... @property @abc.abstractmethod - def variables(self) -> ExpressionBaseMixin: - ... + def variables(self) -> ExpressionBaseMixin: ... @property @abc.abstractmethod - def introduce_derivatives(self) -> bool: - ... + def introduce_derivatives(self) -> bool: ... @property @abc.abstractmethod - def stack(self) -> tuple[FrameSummary]: - ... + def stack(self) -> tuple[FrameSummary]: ... # overwrites the abstract method of `ExpressionBaseMixin` def apply( - self, + self, state: ExpressionState, ) -> tuple[ExpressionState, PolyMatrix]: - - state, underlying = self.underlying.apply(state=state) + state, underlying = self.underlying.apply(state=state) state, variables = get_variable_indices_from_variable(state, self.variables) if not (underlying.shape[1] == 1): - raise AssertionError(to_operator_exception( - message=f'{underlying.shape[1]=} is not 1', - stack=self.stack, - )) + raise AssertionError( + to_operator_exception( + message=f"{underlying.shape[1]=} is not 1", + stack=self.stack, + ) + ) poly_matrix_data = {} for row in range(underlying.shape[0]): - underlying_poly = underlying.get_poly(row, 0) if underlying_poly is None: @@ -67,7 +64,6 @@ class DerivativeExprMixin(ExpressionBaseMixin): # derivate each variable and map result to the corresponding column for col, variable in enumerate(variables): - state, diff_polynomial = differentiate_polynomial( polynomial=underlying_poly, diff_wrt_variable=variable, @@ -84,4 +80,4 @@ class DerivativeExprMixin(ExpressionBaseMixin): shape=(underlying.shape[0], len(variables)), ) - return state, poly_matrix + return state, poly_matrix |