Skip to content

Commit

Permalink
Fix sympy comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
david-zwicker committed Aug 12, 2024
1 parent 5b1a7d1 commit 93a8964
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions pde/tools/expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,11 +282,11 @@ def __eq__(self, other):
return False

# compare the expressions themselves by checking their difference
diff = sympy.simplify(self._sympy_expr - other._sympy_expr)
difference = sympy.simplify(self._sympy_expr - other._sympy_expr)
if isinstance(self._sympy_expr, sympy.NDimArray):
return diff == sympy.Array(np.zeros(self._sympy_expr.shape))
return difference == sympy.Array(np.zeros(self._sympy_expr.shape, int))
else:
return diff == 0
return difference == 0

@property
def _free_symbols(self) -> set:
Expand Down
2 changes: 1 addition & 1 deletion tests/tools/test_expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def test_tensor_expression():
assert e.constant
np.testing.assert_allclose(e.get_compiled_array()(), [[0, 1], [2, 3]])
np.testing.assert_allclose(e.get_compiled_array()(tuple()), [[0, 1], [2, 3]])
assert e.differentiate("a") == TensorExpression("[[0., 0.], [0., 0.]]")
assert e.differentiate("a") == TensorExpression("[[0, 0], [0, 0]]")
np.testing.assert_allclose(e.value, np.arange(4).reshape(2, 2))

e = TensorExpression("[a, 2*a]")
Expand Down

0 comments on commit 93a8964

Please sign in to comment.