Skip to content

Commit

Permalink
0.8.4
Browse files Browse the repository at this point in the history
- (#188) - Automatically convert floating-point numbers used in constraints
  to integers

Signed-off-by: Matthew Ballance <matt.ballance@gmail.com>
  • Loading branch information
mballance committed Aug 22, 2023
1 parent ce70212 commit 9c3d713
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
4 changes: 4 additions & 0 deletions doc/Changelog.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion etc/ivpm.info
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

name=pyvsc
version=0.8.3
version=0.8.4

2 changes: 2 additions & 0 deletions src/vsc/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
23 changes: 23 additions & 0 deletions ve/unit/test_scalar_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)))

0 comments on commit 9c3d713

Please sign in to comment.