diff options
author | Michael Schneeberger <michael.schneeberger@fhnw.ch> | 2022-12-06 13:08:25 +0100 |
---|---|---|
committer | Michael Schneeberger <michael.schneeberger@fhnw.ch> | 2022-12-06 13:08:25 +0100 |
commit | 3832bf5cd17b456a28d816bee060e3d500b1f07b (patch) | |
tree | 7169ac38377d46631df436702f8866edb3501280 | |
parent | use dataclass __eq__ method (diff) | |
download | polymatrix-3832bf5cd17b456a28d816bee060e3d500b1f07b.tar.gz polymatrix-3832bf5cd17b456a28d816bee060e3d500b1f07b.zip |
remove polymatrix entry when two entries add up to zero
Diffstat (limited to '')
-rw-r--r-- | polymatrix/expression/mixins/additionexprmixin.py | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/polymatrix/expression/mixins/additionexprmixin.py b/polymatrix/expression/mixins/additionexprmixin.py index c4f3113..20ff5d0 100644 --- a/polymatrix/expression/mixins/additionexprmixin.py +++ b/polymatrix/expression/mixins/additionexprmixin.py @@ -1,6 +1,7 @@ import abc import collections +import math import typing import dataclass_abc @@ -83,7 +84,11 @@ class AdditionExprMixin(ExpressionBaseMixin): else: terms_row_col[monomial] += value - terms[row, col] = terms_row_col + if math.isclose(terms_row_col[monomial], 0): + del terms_row_col[monomial] + + if 0 < len(terms_row_col): + terms[row, col] = terms_row_col poly_matrix = init_poly_matrix( terms=terms, |