MCPcopy Create free account
hub / github.com/hyperopt/hyperopt / SymbolTable

Class SymbolTable

hyperopt/pyll/base.py:35–175  ·  view source on GitHub ↗

An object whose methods generally allocate Apply nodes. _impls is a dictionary containing implementations for those nodes. >>> self.add(a, b) # -- creates a new 'add' Apply node >>> self._impl['add'](a, b) # -- this computes a + b

Source from the content-addressed store, hash-verified

33
34
35class SymbolTable:
36 """
37 An object whose methods generally allocate Apply nodes.
38
39 _impls is a dictionary containing implementations for those nodes.
40
41 >>> self.add(a, b) # -- creates a new 'add' Apply node
42 >>> self._impl['add'](a, b) # -- this computes a + b
43 """
44
45 def __init__(self):
46 # -- list and dict are special because they are Python builtins
47 self._impls = {
48 "list": list,
49 "dict": dict,
50 "range": range,
51 "len": len,
52 "int": int,
53 "float": float,
54 "map": map,
55 "max": max,
56 "min": min,
57 "getattr": getattr,
58 }
59
60 def _new_apply(self, name, args, kwargs, o_len, pure):
61 pos_args = [as_apply(a) for a in args]
62 named_args = [(k, as_apply(v)) for (k, v) in list(kwargs.items())]
63 named_args.sort()
64 return Apply(
65 name, pos_args=pos_args, named_args=named_args, o_len=o_len, pure=pure
66 )
67
68 def dict(self, *args, **kwargs):
69 # XXX: figure out len
70 return self._new_apply("dict", args, kwargs, o_len=None, pure=True)
71
72 def int(self, arg):
73 return self._new_apply("int", [as_apply(arg)], {}, o_len=None, pure=True)
74
75 def float(self, arg):
76 return self._new_apply("float", [as_apply(arg)], {}, o_len=None, pure=True)
77
78 def len(self, obj):
79 return self._new_apply("len", [obj], {}, o_len=None, pure=True)
80
81 def list(self, init):
82 return self._new_apply("list", [as_apply(init)], {}, o_len=None, pure=True)
83
84 def map(self, fn, seq, pure=False):
85 """
86 pure - True is assertion that fn does not modify seq[i]
87 """
88 return self._new_apply(
89 "map", [as_apply(fn), as_apply(seq)], {}, o_len=seq.o_len, pure=pure
90 )
91
92 def range(self, *args):

Callers 1

base.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…