Giter VIP home page Giter VIP logo

Comments (8)

mballance avatar mballance commented on May 26, 2024

Hi @ShraddhaDevaiya,
A proper 'sum' method would be the right way to go about this. I'll look into enhancing the library to support that.

Best Regards,
Matthew

from pyvsc.

ShraddhaDevaiya avatar ShraddhaDevaiya commented on May 26, 2024

Hi @mballance , this issue is opened since many days. Just wanted to know, is this supported in the latest version 1.5 ?

from pyvsc.

mballance avatar mballance commented on May 26, 2024

Hi @ShraddhaDevaiya,
No, this issue is not implemented in 0.1.5. Perhaps I misunderstood the priority from your perspective.
From the example you supplied, it would appear that you can calculate the sum of the array elements in the 'post_randomize' method. Would this be an adequate approach for now?

Best Regards,
Matthew

from pyvsc.

ShraddhaDevaiya avatar ShraddhaDevaiya commented on May 26, 2024

Yeah we can do that thing, means to implement in post_randomize method. Thanks for updating.

Regards,
Shraddha Devaiya.

from pyvsc.

mballance avatar mballance commented on May 26, 2024

Hi @ShraddhaDevaiya,
I've added support for 'sum' and 'product' properties on arrays in the 0.1.8 release. In many cases, you will use these in procedural code and not in constraints.
The example above will not work directly, since the for loop is evaluated once when the constraints are constructed. Can you supply a testcase that illustrates your use model? I'll leave this issue open until we've agreed that your use model is supported.

Best Regards,
Matthew

from pyvsc.

ShraddhaDevaiya avatar ShraddhaDevaiya commented on May 26, 2024

Hi @mballance , We have an use-case like this :

import vsc


@vsc.randobj
class my_s(object):
    def __init__(self):
        self.main_program = vsc.rand_uint8_t()
        self.total = vsc.rand_uint8_t()
        self.sub_program = vsc.rand_list_t(vsc.uint8_t())

    @vsc.constraint
    def ab_c(self):
        self.total == 50
        self.main_program + self.sub_program.sum == self.total

my = my_s()

# Randomize
for i in range(5):
    my.randomize()
    print("MY ITEM : ",i+1)
    print(my.main_program , list(my.sub_program))

but rightnow for this, it is giving an output like this :

MY ITEM :  1
50 []
MY ITEM :  2
50 []
MY ITEM :  3
50 []
MY ITEM :  4
50 []
MY ITEM :  5
50 []

Can you please take a look into this ?

Thanks & Regards,
Shraddha Devaiya.

from pyvsc.

mballance avatar mballance commented on May 26, 2024

Hi @ShraddhaDevaiya,
Of course. The example above, as written, has a zero-sized 'sub_program' list. I changed the example to specify the list size (10) and ensure that sub-programs are >0 in size:

        @vsc.randobj
        class my_s(object):
            def __init__(self):
                self.main_program = vsc.rand_uint8_t()
                self.total = vsc.rand_uint8_t()
                self.sub_program = vsc.rand_list_t(vsc.uint8_t(), sz=10)

            @vsc.constraint
            def ab_c(self):
                self.total == 50
                with vsc.foreach(self.sub_program) as it:
                    it != 0
                self.main_program + self.sub_program.sum == self.total

        my = my_s()

        # Randomize
        for i in range(5):
            my.randomize()
            print("MY ITEM : ",i+1)
            print(my.main_program , list(my.sub_program))       

Here is the output I see:

MY ITEM :  1
25 [1, 1, 1, 1, 1, 1, 1, 4, 2, 12]
MY ITEM :  2
8 [1, 1, 1, 1, 1, 1, 1, 16, 8, 11]
MY ITEM :  3
25 [1, 1, 1, 1, 1, 1, 1, 3, 3, 12]
MY ITEM :  4
0 [2, 2, 4, 2, 2, 8, 4, 2, 1, 23]
MY ITEM :  5
1 [1, 1, 1, 11, 1, 22, 2, 4, 2, 4]

Best Regards,
Matthew

from pyvsc.

ShraddhaDevaiya avatar ShraddhaDevaiya commented on May 26, 2024

Yeah, it is working, I have not provided the "size" of list that's why. Thanks for helping!

Regards,
Shraddha Devaiya.

from pyvsc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.