Exemplo n.º 1
0
 def _get_next(self):
     """Generate and return the next RNG value."""
     val_int = xmath.int(DeferredExpression(self.var_name))
     val = ((val_int * 58321 + 11113)) % 65535
     self.__set__(self, val)
     container = inspect.currentframe().f_back.f_locals['obj']
     self.bsca.deferred_write(container)
Exemplo n.º 2
0
 def __init__(self, val=None, name="var"):
     """Initialize base class features."""
     super(Variable, self).__init__()
     self.fallback_name = name
     self.base_class = Variable
     if val is None:
         raise XenticaException("Variable should have an initial value.")
     self._init_val = DeferredExpression(str(val))
Exemplo n.º 3
0
 def uniform(self):
     """Get a random value from the uniform distribution."""
     return xmath.float(DeferredExpression(self.var_name)) / 65535
Exemplo n.º 4
0
 def min(*args):
     """Calculate the minimum over list of args."""
     expr = str(args[0])
     for arg in args[1:]:
         expr = "(({a}) < ({b})) ? ({a}) : ({b})".format(a=expr, b=arg)
     return DeferredExpression("(%s)" % expr)
Exemplo n.º 5
0
 def exp(val):
     """Calculate exponent."""
     return DeferredExpression("(exp(%s))" % val)
Exemplo n.º 6
0
 def popc(val):
     """Count the number of bits that are set to '1' in a 32 bit integer."""
     return DeferredExpression("(__popc(%s))" % val)
Exemplo n.º 7
0
 def int(val):
     """Cast a value to int."""
     return DeferredExpression("((unsigned int) (%s))" % val)
Exemplo n.º 8
0
 def float(val):
     """Cast a value to float."""
     return DeferredExpression("((float) (%s))" % val)
Exemplo n.º 9
0
 def __get__(self, obj, objtype):
     """Implement custom logic when param is get as class descriptor."""
     self._declare_once()
     if self._interactive:
         return DeferredExpression(self._name)
     return self._value