Code Monkey home page Code Monkey logo

Comments (2)

mballance avatar mballance commented on June 19, 2024 1

Hi @aneels3,
I've completed support for rand_mode on scalar fields. Support will be available in the 0.0.7 release. See the Constraints section for more information on how to use rand_mode. You can also see a short example below:

        @vsc.randobj
        class my_cls(object):
            
            def __init__(self):
                self.a = vsc.rand_uint8_t()
                self.b = vsc.rand_uint8_t()
                
        # First, test that values vary
        init_a = 0
        init_b = 0
        it = my_cls()
        
        for i in range(20):
            with it.randomize_with():
                it.a != init_a
                it.b != init_b
                
            self.assertNotEqual(it.a, init_a)
            self.assertNotEqual(it.b, init_b)
            init_a = it.a 
            init_b = it.b 
            
        # Now, disable rand_mode for a
        with vsc.raw_mode():
            it.a.rand_mode = False
        
            self.assertEqual(it.a.rand_mode, False)
            self.assertEqual(it.b.rand_mode, True)
        
        for i in range(20):
            with it.randomize_with():
                it.b != init_b
                
            self.assertEqual(it.a, init_a)
            self.assertNotEqual(it.b, init_b)
            init_a = it.a 
            init_b = it.b 
            
        # Now, go back
        with vsc.raw_mode():
            it.a.rand_mode = True
        
            self.assertEqual(it.a.rand_mode, True)
            self.assertEqual(it.b.rand_mode, True)

        for i in range(20):
            with it.randomize_with():
                it.a != init_a
                it.b != init_b
                
            self.assertNotEqual(it.a, init_a)
            self.assertNotEqual(it.b, init_b)
            init_a = it.a 
            init_b = it.b         

from pyvsc.

mballance avatar mballance commented on June 19, 2024

Hi @aneels3,
Agreed, support for rand_mode makes sense and should be feasible. After a bit of investigation, I'm aware of one small user-interface difficulty. Because of the operator overloading that PyVSC provides that allows users to obtain the value of scalar fields directly, it's most likely that the user will need to switch to an explicit mode when changing the rand-mode of scalar fields. Something like the following:

with vsc.raw_mode():
    it.a.rand_mode = False

I'm still looking at options to see if there is a better way to handle this. Thanks for the suggestion!

Best Regards,
Matthew

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.