def grad_list(args, direction): if direction == 0: return [0 for _ in args] else: (list_, tail) = direction.asPossiblyImproperList() assert tail is None or tail == 0 or tail == v.VentureInteger(0) tails = [0 for _ in range(len(args) - len(list_))] return list_ + tails
def asVentureValue(self, thing): if isinstance(thing, bool) or isinstance(thing, np.bool_): return vv.VentureBool(thing) if isinstance(thing, int): return vv.VentureInteger(thing) if isinstance(thing, numbers.Number): return vv.VentureNumber(thing) if isinstance(thing, vv.VentureAtom): return thing if isinstance(thing, str): return vv.VentureSymbol(thing) if hasattr(thing, "__getitem__"): # Already not a string return vv.VentureArray([self.asVentureValue(val) for val in thing]) if isinstance(thing, vv.VentureValue): return thing else: raise Exception("Cannot convert Python object %r to a Venture " \ "Expression" % thing)
def asVentureValue(self, thing): if isinstance(thing, bool) or isinstance(thing, np.bool_): return vv.VentureBool(thing) if isinstance(thing, int): return vv.VentureInteger(thing) if isinstance(thing, numbers.Number): return vv.VentureNumber(thing) if isinstance(thing, str): return vv.VentureString(thing) if isinstance(thing, dict): return vv.VentureDict( OrderedDict([(self.asVentureValue(key), self.asVentureValue(val)) for (key, val) in thing.iteritems()])) if hasattr(thing, "__getitem__"): # Already not a string return vv.VentureArray([self.asVentureValue(val) for val in thing]) if isinstance(thing, vv.VentureValue): return thing else: raise Exception("Cannot convert Python object %r to a Venture " \ "Expression" % thing)
def asVentureValue(self, thing): assert thing >= 0 return vv.VentureInteger(thing)
def count(self, **_kwargs): return v.VentureInteger(npr.choice(range(10)))
def integer(self, **_kwargs): return v.VentureInteger(npr.choice(range(-10, 10)))