summaryrefslogtreecommitdiffstats
path: root/polymatrix/expression/mixins/determinantexprmixin.py
diff options
context:
space:
mode:
authorMichael Schneeberger <michael.schneeberger@fhnw.ch>2022-04-08 08:51:19 +0200
committerMichael Schneeberger <michael.schneeberger@fhnw.ch>2022-04-08 08:51:19 +0200
commit19ab60ad70e7d8478609a47a2e937fef3720dac9 (patch)
tree8836fbae02718948a45a6bd2e4c3d1f55548c7c5 /polymatrix/expression/mixins/determinantexprmixin.py
parentimplement polynomial matrix as an expression (diff)
downloadpolymatrix-19ab60ad70e7d8478609a47a2e937fef3720dac9.tar.gz
polymatrix-19ab60ad70e7d8478609a47a2e937fef3720dac9.zip
remove shape property, introduce accumulate function, reimplement derivative expression
Diffstat (limited to 'polymatrix/expression/mixins/determinantexprmixin.py')
-rw-r--r--polymatrix/expression/mixins/determinantexprmixin.py27
1 files changed, 14 insertions, 13 deletions
diff --git a/polymatrix/expression/mixins/determinantexprmixin.py b/polymatrix/expression/mixins/determinantexprmixin.py
index 8fe2536..048b263 100644
--- a/polymatrix/expression/mixins/determinantexprmixin.py
+++ b/polymatrix/expression/mixins/determinantexprmixin.py
@@ -16,10 +16,10 @@ class DeterminantExprMixin(ExpressionBaseMixin):
def underlying(self) -> ExpressionBaseMixin:
...
- # overwrites abstract method of `ExpressionBaseMixin`
- @property
- def shape(self) -> tuple[int, int]:
- return self.underlying.shape[0], 1
+ # # overwrites abstract method of `ExpressionBaseMixin`
+ # @property
+ # def shape(self) -> tuple[int, int]:
+ # return self.underlying.shape[0], 1
# overwrites abstract method of `ExpressionBaseMixin`
def apply(
@@ -34,12 +34,12 @@ class DeterminantExprMixin(ExpressionBaseMixin):
assert underlying.shape[0] == underlying.shape[1]
inequality_terms = {}
- auxillary_terms = []
+ auxillary_equations = {}
index_start = state.n_param
rel_index = 0
- for row in range(self.shape[0]):
+ for row in range(underlying.shape[0]):
current_inequality_terms = collections.defaultdict(float)
@@ -66,13 +66,15 @@ class DeterminantExprMixin(ExpressionBaseMixin):
new_monomial = monomial + (index_start + rel_index + inner_row,)
current_inequality_terms[new_monomial] -= value
+ # auxillary terms
+ # ---------------
+
auxillary_term = collections.defaultdict(float)
for inner_col in range(row):
# P@x in P@x-v
key = tuple(reversed(sorted((inner_row, inner_col))))
- # terms = underlying.get_poly(*key)
try:
underlying_terms = underlying.get_poly(*key)
except KeyError:
@@ -83,7 +85,6 @@ class DeterminantExprMixin(ExpressionBaseMixin):
auxillary_term[new_monomial] += value
# -v in P@x-v
- # terms = underlying.get_poly(row, inner_row)
try:
underlying_terms = underlying.get_poly(row, inner_row)
except KeyError:
@@ -92,23 +93,23 @@ class DeterminantExprMixin(ExpressionBaseMixin):
for monomial, value in underlying_terms.items():
auxillary_term[monomial] -= value
- auxillary_terms.append(dict(auxillary_term))
+ x_variable = index_start + rel_index + inner_row
+ assert x_variable not in state.auxillary_equations
+ auxillary_equations[x_variable] = dict(auxillary_term)
rel_index += row
inequality_terms[row, 0] = dict(current_inequality_terms)
state = state.register(rel_index)
- # print(f'{auxillary_terms=}')
-
poly_matrix = init_poly_matrix(
terms=inequality_terms,
- shape=self.shape,
+ shape=(underlying.shape[0], 1),
)
state = dataclasses.replace(
state,
- auxillary_terms=state.auxillary_terms + tuple(auxillary_terms),
+ auxillary_equations=state.auxillary_equations | auxillary_equations,
cached_polymatrix=state.cached_polymatrix | {self: poly_matrix},
)