summaryrefslogtreecommitdiffstats
path: root/polymatrix/expression/utils/getvariableindices.py
diff options
context:
space:
mode:
authorMichael Schneeberger <michael.schneeberger@fhnw.ch>2024-03-27 14:52:22 +0100
committerMichael Schneeberger <michael.schneeberger@fhnw.ch>2024-03-27 14:52:22 +0100
commitebc557009b5343be74d1ef8e3a9e1c9b44d24a8f (patch)
treec1e6c67fb86e7afd864b3188db6829a463b47aba /polymatrix/expression/utils/getvariableindices.py
parentadd minimal documentation to the expression mixins (diff)
downloadpolymatrix-ebc557009b5343be74d1ef8e3a9e1c9b44d24a8f.tar.gz
polymatrix-ebc557009b5343be74d1ef8e3a9e1c9b44d24a8f.zip
format Python files with ruff
Diffstat (limited to 'polymatrix/expression/utils/getvariableindices.py')
-rw-r--r--polymatrix/expression/utils/getvariableindices.py23
1 files changed, 12 insertions, 11 deletions
diff --git a/polymatrix/expression/utils/getvariableindices.py b/polymatrix/expression/utils/getvariableindices.py
index d61da57..9799da3 100644
--- a/polymatrix/expression/utils/getvariableindices.py
+++ b/polymatrix/expression/utils/getvariableindices.py
@@ -6,31 +6,33 @@ from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
def get_variable_indices_from_variable(
- state: ExpressionState,
- variable: ExpressionBaseMixin | int | typing.Any,
+ state: ExpressionState,
+ variable: ExpressionBaseMixin | int | typing.Any,
) -> tuple[int, ...] | None:
-
if isinstance(variable, ExpressionBaseMixin):
state, variable_polynomial = variable.apply(state)
assert variable_polynomial.shape[1] == 1
def gen_variables_indices():
-
for row in range(variable_polynomial.shape[0]):
row_terms = variable_polynomial.get_poly(row, 0)
- assert len(row_terms) == 1, f'{row_terms} does not contain a single term'
-
+ assert (
+ len(row_terms) == 1
+ ), f"{row_terms} does not contain a single term"
+
for monomial in row_terms.keys():
- assert len(monomial) <= 1, f'{monomial=} contains more than one variable'
+ assert (
+ len(monomial) <= 1
+ ), f"{monomial=} contains more than one variable"
if len(monomial) == 0:
continue
-
- assert monomial[0][1] == 1, f'{monomial[0]=}'
+
+ assert monomial[0][1] == 1, f"{monomial[0]=}"
yield monomial[0][0]
-
+
variable_indices = tuple(gen_variables_indices())
elif isinstance(variable, int):
@@ -47,7 +49,6 @@ def get_variable_indices_from_variable(
# not used, remove?
def get_variable_indices(state, variables):
-
if not isinstance(variables, tuple):
variables = (variables,)