Coder Social home page Coder Social logo

Comments (5)

hanfeng0114 avatar hanfeng0114 commented on June 11, 2024

Like the following feature:
'
@vsc.constraint
def basic_c(self):
with vsc.foreach(self.GroupList, idx=True, it=False) as idx:
self.GroupList[idx]<= self.mThreadNum
with vsc.foreach(self.GroupList, idx=True, it=False) as idx:
self.GroupList[idx]<= self.mThreadNum
with vsc.foreach(self.GroupList, idx=True, it=False) as idx:
with vsc.if_then(self.GroupList[idx] > 1):
self.GroupListScore[idx] == 1
with vsc.else_then():
self.GroupListScore[idx] == 0
self.GroupListScore.sum < self.getSum(self.GroupListScore)
self.GroupList.sum == self.mThreadNum

        def getSum(self, aList):
            return sum(aList)

'

from pyvsc.

mballance avatar mballance commented on June 11, 2024

Can you provide a full example that includes the definition of data fields?
Currently, PyVSC invokes functions when the constraint is built. So, getSum would be invoked once to obtain the size of the GroupListScore. Obviously, this behavior might not be what is desired.

from pyvsc.

hanfeng0114 avatar hanfeng0114 commented on June 11, 2024

For example, The following code doesn't run well for line 94:
image

Line 94 doesn't have caculation functions.
My question is how to meet similar requirement?

from pyvsc.

mballance avatar mballance commented on June 11, 2024

Hi @hanfeng0114,
Thank you for the full example. I created a small testcase based on the example. The error I receive from running this testcase is shown below:

  File "/project/fun/pyvsc/pyvsc-20230821/src/vsc/rand_obj.py", line 208, in build_field_model
    fo.c(self)
  File "/project/fun/pyvsc/pyvsc-20230821/ve/unit/test_scalar_array.py", line 348, in basic_c
    self.GroupList.sum == self.mThreadNum * self.mSharePercent/100
  File "/project/fun/pyvsc/pyvsc-20230821/src/vsc/types.py", line 84, in __eq__
    return self.bin_expr(BinExprType.Eq, rhs)
  File "/project/fun/pyvsc/pyvsc-20230821/src/vsc/types.py", line 72, in bin_expr
    to_expr(rhs)
  File "/project/fun/pyvsc/pyvsc-20230821/src/vsc/types.py", line 338, in to_expr
    raise Exception("Element \"" + str(t) + "\" isn't recognized, and doesn't provide to_expr (type=%s)" % str(type(t)))
Exception: Element "6.4" isn't recognized, and doesn't provide to_expr (type=<class 'float'>)

The core issue is that the right-hand side of the equation produces a floating-point result and PyVSC doesn't currently handle this. I receive proper results if I explicitly convert the right-hand side to an integer:

    self.GroupList.sum == int(self.mThreadNum * self.mSharePercent/100)

I recommend using explicit conversion for now. In the future, I will either improve the error messaging or provide direct support for using floating-point expressions in integer constraint expressions.

from pyvsc.

mballance avatar mballance commented on June 11, 2024

The 0.8.4 release contains changes to automatically convert floating-point number used in constraints to integers. I believe this is the best way to address this issue.
Thank you for the issue report!

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.