diff options
author | Michael Schneeberger <michael.schneeberger@fhnw.ch> | 2022-08-17 17:30:07 +0200 |
---|---|---|
committer | Michael Schneeberger <michael.schneeberger@fhnw.ch> | 2022-08-17 17:30:07 +0200 |
commit | 46557acb1de979fe30654d6debf1f3a9c51494a1 (patch) | |
tree | 94d5c97b5b861f2ca1b0d23960abd446f65c42c9 | |
parent | 'parametrize' method accepts any size matrix, not only vectors (diff) | |
download | polymatrix-46557acb1de979fe30654d6debf1f3a9c51494a1.tar.gz polymatrix-46557acb1de979fe30654d6debf1f3a9c51494a1.zip |
bugfix: 'set_element_at' works with value=0
Diffstat (limited to '')
-rw-r--r-- | polymatrix/expression/mixins/setelementatexprmixin.py | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/polymatrix/expression/mixins/setelementatexprmixin.py b/polymatrix/expression/mixins/setelementatexprmixin.py index 9d552bc..2bb0bfe 100644 --- a/polymatrix/expression/mixins/setelementatexprmixin.py +++ b/polymatrix/expression/mixins/setelementatexprmixin.py @@ -39,9 +39,14 @@ class SetElementAtExprMixin(ExpressionBaseMixin): state: ExpressionState, ) -> tuple[ExpressionState, PolyMatrix]: state, underlying = self.underlying.apply(state=state) - state, value = self.value.apply(state=state) + state, value_expr = self.value.apply(state=state) - assert value.shape == (1, 1) + assert value_expr.shape == (1, 1) + + try: + value = value_expr.get_poly(0, 0) + except KeyError: + value = 0 @dataclass_abc.dataclass_abc(frozen=True) class SetElementAtPolyMatrix(PolyMatrixMixin): @@ -49,10 +54,6 @@ class SetElementAtExprMixin(ExpressionBaseMixin): shape: tuple[int, int] index: tuple[int, int] value: dict - - # @property - # def shape(self) -> tuple[int, int]: - # return self.shape def get_poly(self, row: int, col: int) -> dict[tuple[int, ...], float]: if (row, col) == self.index: @@ -64,6 +65,6 @@ class SetElementAtExprMixin(ExpressionBaseMixin): underlying=underlying, index=self.index, shape=underlying.shape, - value=value.get_poly(0, 0) + value=value, )
\ No newline at end of file |