summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Schneeberger <michael.schneeberger@fhnw.ch>2024-05-07 15:03:28 +0200
committerMichael Schneeberger <michael.schneeberger@fhnw.ch>2024-05-07 15:03:28 +0200
commit1a8e0493e5d351fa1f54d00b38be1d793587bc41 (patch)
tree06e5d2a4a2416b41b9c1137a986b18a13b7adc07
parentadd comments and remove unused code in denserepr module (diff)
downloadpolymatrix-1a8e0493e5d351fa1f54d00b38be1d793587bc41.tar.gz
polymatrix-1a8e0493e5d351fa1f54d00b38be1d793587bc41.zip
rename and comment monomial_to_monomial_vector_indices
-rw-r--r--polymatrix/denserepr/from_.py4
-rw-r--r--polymatrix/denserepr/utils/monomialtoindex.py15
2 files changed, 15 insertions, 4 deletions
diff --git a/polymatrix/denserepr/from_.py b/polymatrix/denserepr/from_.py
index 7936c97..1eda6fe 100644
--- a/polymatrix/denserepr/from_.py
+++ b/polymatrix/denserepr/from_.py
@@ -9,7 +9,7 @@ from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
from polymatrix.expression.utils.getvariableindices import (
get_variable_indices_from_variable,
)
-from polymatrix.denserepr.utils.monomialtoindex import variable_indices_to_column_index
+from polymatrix.denserepr.utils.monomialtoindex import monomial_to_monomial_vector_indices
from polymatrix.denserepr.impl import DenseReprBufferImpl, DenseReprImpl
# NP: create a dense representation from a polymatrix expression
@@ -150,7 +150,7 @@ def from_polymatrix(
# converts (2, 1) to (1, 2)
# converts (1, 2) to (3,)
# the cols correspond to the column of the dense matrix w.r.t. Z
- cols = variable_indices_to_column_index(
+ cols = monomial_to_monomial_vector_indices(
n_param, new_variable_indices
)
diff --git a/polymatrix/denserepr/utils/monomialtoindex.py b/polymatrix/denserepr/utils/monomialtoindex.py
index a41b9fc..151e8bf 100644
--- a/polymatrix/denserepr/utils/monomialtoindex.py
+++ b/polymatrix/denserepr/utils/monomialtoindex.py
@@ -2,10 +2,21 @@ import itertools
# NP: document this function, especially magic return line
-def variable_indices_to_column_index(
+def monomial_to_monomial_vector_indices(
n_var: int,
variable_indices: tuple[int, ...],
-) -> int:
+) -> set[int]:
+ """
+ Given a monomial of degree d, this function returns the indices of a monomial
+ vector containing monomial of the same degree.
+
+ Given the variable mapping {x : 0, y : 1}, the monomial x*y of the monomial vector
+
+ z = [x**2 x*y x*y y**2]
+
+ results in indices = (1, 2).
+ """
+
variable_indices_perm = itertools.permutations(variable_indices)
return set(