Replies: 2 comments 1 reply
-
Hi Jon, PyVSC supports 'sum' on scalar arrays, but not on object arrays. Sounds like I should have a look at how it's described (or not) in the docs. Because PyVSC does not support the SystemVerilog with constraint, you have to create a temporary scalar array that you can then sum. Here is my take on the memory-segment question: import vsc
@vsc.randobj
class mem_segment(object):
def __init__(self):
self.capacity = vsc.rand_uint16_t()
@vsc.randobj
class mem_segments(object):
def __init__(self):
self.max_total_capacity = vsc.rand_uint16_t()
self.mem_segments = vsc.rand_list_t(mem_segment())
for _ in range(10):
self.mem_segments.append(mem_segment())
self.sz_array = vsc.rand_list_t(vsc.rand_uint16_t(), 10)
@vsc.constraint
def sz_c(self):
self.max_total_capacity >= 100
self.max_total_capacity <= 200
with vsc.foreach(self.mem_segments, idx=True, it=False) as idx:
self.sz_array[idx] == self.mem_segments[idx].capacity
self.mem_segments[idx].capacity <= self.max_total_capacity
self.sz_array.sum == self.max_total_capacity
ms = mem_segments()
ms.randomize()
print("max_total_capacity: %d" % ms.max_total_capacity)
for i,s in enumerate(ms.mem_segments):
print("[%d] %d" % (i, s.capacity)) Less than ideal, but reasonably functional... |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
(After writing this up, I do notice that array sum isn't actually listed as supported in the pyvsc documentation. Is it limited to lists of ints? or not supported entirely https://pyvsc.readthedocs.io/en/latest/features.html).
For fun, I was attempting to reproduce this constraint in pyvsc based on a linked post:
https://www.linkedin.com/feed/update/urn:li:activity:6989140189193359360/
I was unable to figure out how I would use pyvsc to create a constraint like this:
pyvsc has a sum property for list_t and I see one example of it in the repo.
The key difference is constraint is a list of objects with the "capacity" property instead of a list of ints.
It is also dynamically sizes, so I can't just write out the constraint explicitly.
I don't see how I could use sum to create a constraint based on the sum of a class's property instead of the list item as a whole.
Any suggestions?
Would there be a way to use foreach that I'm not thinking of?
Cheers,
Jon
Beta Was this translation helpful? Give feedback.
All reactions