def getvector(self, word): try: if isstring(word): return self.w[self.D[word]] elif isnumber(word): return self.w[word, :] except Exception: return None
def makemask(self, arg=0): # default: mask zero if isfunction(arg): self._mask = arg(self) elif isnumber(arg): self._mask = tensorops.eq(self, arg) else: raise Exception("wrong input argument type") return self
def wrapf(attr, root=None): if isfunction(attr): # real function innerwrap = prefwrap(attr, root) #lambda *args, **kwargs: fwrap(attr, root, *args, **kwargs) elif isnumber(attr) or isstring(attr): # or other literals/non-syms/modules/properties/... return attr elif isinstance(attr, ModuleType): innerwrap = pwrap(attr) elif isinstance(attr, theano.Variable): innerwrap = vwrap(attr, root) else: innerwrap = attr return innerwrap
def wrapf(attr, root=None): if isfunction(attr): # real function innerwrap = OpBlock(attr, root) elif isnumber(attr) or isstring(attr): # or other literals/non-syms/modules/properties/... return attr elif isinstance(attr, ModuleType): innerwrap = WrappedAttr(attr) elif isinstance(attr, theano.Variable): innerwrap = Var(attr) if isinstance(root, Var): # propagate params innerwrap.push_params(root._params) else: innerwrap = attr return innerwrap
def wrap(model, startsymbol=0, stopsymbol=None): assert(startsymbol is not None and isnumber(startsymbol)) if hasattr(model, "searchwrapper"): return model.searchwrapper(model, startsymbol=startsymbol, stopsymbol=stopsymbol) else: raise Exception("no search wrapper assigned to model")