From 9c3d713b99ff680ea7da024b9e0d7326f60223ec Mon Sep 17 00:00:00 2001 From: Matthew Ballance Date: Mon, 21 Aug 2023 17:06:09 -0700 Subject: [PATCH] 0.8.4 - (#188) - Automatically convert floating-point numbers used in constraints to integers Signed-off-by: Matthew Ballance --- doc/Changelog.md | 4 ++++ etc/ivpm.info | 2 +- src/vsc/types.py | 2 ++ ve/unit/test_scalar_array.py | 23 +++++++++++++++++++++++ 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/doc/Changelog.md b/doc/Changelog.md index b145d51..513cc5f 100644 --- a/doc/Changelog.md +++ b/doc/Changelog.md @@ -1,4 +1,8 @@ +## 0.8.4 +- (#188) - Automatically convert floating-point numbers used in constraints + to integers + ## 0.8.3 - (#176) [Resolved by Alex Wilson] Correctly handle soft constraints that are under conditions such as if/else. diff --git a/etc/ivpm.info b/etc/ivpm.info index 9a3d189..9654a68 100644 --- a/etc/ivpm.info +++ b/etc/ivpm.info @@ -1,4 +1,4 @@ name=pyvsc -version=0.8.3 +version=0.8.4 diff --git a/src/vsc/types.py b/src/vsc/types.py index 4a72b80..aa4d6ee 100644 --- a/src/vsc/types.py +++ b/src/vsc/types.py @@ -326,6 +326,8 @@ def to_expr(t): return t elif type(t) == int or type(t) == ValueInt: return expr(ExprLiteralModel(int(t), True, 32)) + elif type(t) == float: + return expr(ExprLiteralModel(int(round(t)), True, 32)) elif isinstance(type(t), (EnumMeta,IntEnum)): return expr(EnumInfo.get(type(t)).e2e(t)) elif isinstance(t, type): diff --git a/ve/unit/test_scalar_array.py b/ve/unit/test_scalar_array.py index 7d9b810..632abb3 100644 --- a/ve/unit/test_scalar_array.py +++ b/ve/unit/test_scalar_array.py @@ -328,3 +328,26 @@ def test_c(self): inst.randomize() self.assertEqual(inst.c1[0].a[0].enum_test, level_e.level_2) self.assertEqual(inst.c2[0].x[0].value, 3) + + def test_list_sum_eq_fp_literal(self): + + @vsc.randobj + class ThreadGroupConstraintItem(object): + + def __init__(self, aThreadNum, aSharePercent): + self.mThreadNum = aThreadNum + self.mSharePercent = aSharePercent + + self.GroupList = vsc.rand_list_t(vsc.rand_uint16_t(), self.mThreadNum) + self.GroupListScore = vsc.rand_list_t(vsc.rand_uint16_t(), self.mThreadNum) + self.GroupListId = vsc.rand_list_t(vsc.rand_uint16_t(), self.mThreadNum) + + @vsc.constraint + def basic_c(self): +# self.GroupList.sum == int(self.mThreadNum * self.mSharePercent/100) + self.GroupList.sum == self.mThreadNum * self.mSharePercent/100 + + obj = ThreadGroupConstraintItem(8, 80) + obj.randomize() + self.assertEqual(obj.GroupList.sum, 6) + print("GroupList.sum=%d eq=%f" % (obj.GroupList.sum, (obj.mThreadNum * obj.mSharePercent/100))) \ No newline at end of file