MCPcopy
hub / github.com/hyperopt/hyperopt / Lambda

Class Lambda

hyperopt/pyll/base.py:581–603  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

579
580
581class Lambda:
582
583 # XXX: Extend Lambda objects to have a list of exception clauses.
584 # If the code of the expr() throws an error, these clauses convert
585 # that error to a return value.
586
587 def __init__(self, name, params, expr):
588 self.__name__ = name # like a python function
589 self.params = params # list of (name, symbol[, default_value]) tuples
590 self.expr = expr # pyll graph defining this Lambda
591
592 def __call__(self, *args, **kwargs):
593 # -- return `expr` cloned from given args and kwargs
594 if len(args) > len(self.params):
595 raise TypeError("too many arguments")
596 memo = {}
597 for arg, param in zip(args, self.params):
598 # print('applying with arg', param, arg)
599 memo[param[1]] = as_apply(arg)
600 if len(args) != len(self.params) or kwargs:
601 raise NotImplementedError("named / default arguments", (args, self.params))
602 rval = clone(self.expr, memo)
603 return rval
604
605
606class UndefinedValue:

Callers 2

test_recursionFunction · 0.90
partialFunction · 0.85

Calls

no outgoing calls

Tested by 1

test_recursionFunction · 0.72