From b44a196dd937680a744103e5297b8a946b6241fd Mon Sep 17 00:00:00 2001 From: iopapamanoglou Date: Mon, 2 Sep 2024 11:46:41 +0200 Subject: [PATCH 1/2] Fix: Paramters: Constant eq float error --- src/faebryk/library/Constant.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/faebryk/library/Constant.py b/src/faebryk/library/Constant.py index ea6cbc27..ec9c853a 100644 --- a/src/faebryk/library/Constant.py +++ b/src/faebryk/library/Constant.py @@ -3,6 +3,8 @@ from typing import Self, SupportsAbs +import numpy as np + from faebryk.core.parameter import Parameter, _resolved from faebryk.libs.units import Quantity @@ -32,6 +34,11 @@ def __eq__(self, other) -> bool: if not isinstance(other, Constant): return False + try: + return np.allclose(self.value, other.value) + except (TypeError, np.exceptions.DTypePromotionError): + ... + return self.value == other.value def __hash__(self) -> int: From 884628fac27b19c7cd4390e5ff565be4d04dd874 Mon Sep 17 00:00:00 2001 From: iopapamanoglou Date: Mon, 2 Sep 2024 11:50:31 +0200 Subject: [PATCH 2/2] Add test --- test/core/test_parameters.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/core/test_parameters.py b/test/core/test_parameters.py index f7bf74bf..428d0f5b 100644 --- a/test/core/test_parameters.py +++ b/test/core/test_parameters.py @@ -359,6 +359,9 @@ def __preinit__(self) -> None: r = r.get_most_narrow() self.assertIsInstance(r, Range, f"{type(r)}") + def test_units(self): + self.assertEqual(Constant(1e-9 * P.F), 1 * P.nF) + if __name__ == "__main__": unittest.main()