def add_method(self, name, inputs=None, outputs=None, updates=None, givens=None, optimizer=None, ): """Add a theano function as self.<name> Parameters ---------- updates - a sequence of `(dest, expr)` pairs of theano variables When this function is called, it will update each workspace variable `dest` with the value computed for corresponding symbolic variable `expr`. """ if inputs or outputs or givens: raise NotImplementedError() if not updates: raise NotImplementedError() ufgraph = UpdateFGraph(updates) if optimizer: optimizer = optimizer_from_any(optimizer) optimizer.apply(ufgraph.fgraph) cu = CompiledUpdate(ufgraph, self.vals_memo) return self._add_compiled_update(name, cu)
def optimize_methods(ws, query): """Recompile methods so they run faster, if possible. """ optimizer = optimizer_from_any(query) for key, cu in ws.compiled_updates.items(): optimizer.apply(cu.ufgraph.fgraph) cu_opt = CompiledUpdate(cu.ufgraph, ws.vals_memo) ws._add_compiled_update(key, cu_opt) return ws