MCPcopy
hub / github.com/hyperopt/hyperopt / Apply

Class Apply

hyperopt/pyll/base.py:222–521  ·  view source on GitHub ↗

Represent a symbolic application of a symbol to arguments. o_len - None or int if the function is guaranteed to return a fixed number `o_len` of outputs if it returns successfully pure - True only if the function has no relevant side-effects

Source from the content-addressed store, hash-verified

220
221
222class Apply:
223 """
224 Represent a symbolic application of a symbol to arguments.
225
226 o_len - None or int if the function is guaranteed to return a fixed number
227 `o_len` of outputs if it returns successfully
228 pure - True only if the function has no relevant side-effects
229 """
230
231 def __init__(
232 self, name, pos_args, named_args, o_len=None, pure=False, define_params=None
233 ):
234 self.name = name
235 # -- tuples or arrays -> lists
236 self.pos_args = list(pos_args)
237 self.named_args = [[kw, arg] for (kw, arg) in named_args]
238 # -- o_len is attached this early to support tuple unpacking and
239 # list coercion.
240 self.o_len = o_len
241 self.pure = pure
242 # -- define_params lets us cope with stuff that may be in the
243 # SymbolTable on the master but not on the worker.
244 self.define_params = define_params
245 assert all(isinstance(v, Apply) for v in pos_args)
246 assert all(isinstance(v, Apply) for k, v in named_args)
247 assert all(isinstance(k, str) for k, v in named_args)
248
249 def __setstate__(self, state):
250 self.__dict__.update(state)
251 # -- On deserialization, update scope if need be.
252 if self.define_params:
253 scope.define_if_new(**self.define_params)
254
255 def eval(self, memo=None):
256 """
257 Recursively evaluate an expression graph.
258
259 This method operates directly on the graph of extended inputs to this
260 node, making no attempt to modify or optimize the expression graph.
261
262 Caveats:
263
264 * If there are nodes in the graph that do not represent expressions,
265 (e.g. nodes that correspond to statement blocks or assertions)
266 then it's not clear what this routine should do, and you should
267 probably not call it.
268
269 * If there are Lambdas in the graph, this procedure will not evluate
270 them -- see rec_eval for that.
271
272 However, for many cases that are pure expression graphs, this
273 offers a quick and simple way to evaluate them.
274 """
275 if memo is None:
276 memo = {}
277 if id(self) in memo:
278 return memo[id(self)]
279 else:

Callers 5

vectorize_stochasticFunction · 0.85
_new_applyMethod · 0.85
as_applyFunction · 0.85
applyFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected