MCPcopy
hub / github.com/hyperopt/hyperopt / Literal

Class Literal

hyperopt/pyll/base.py:531–578  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

529
530
531class Literal(Apply):
532 def __init__(self, obj=None):
533 try:
534 o_len = len(obj)
535 except TypeError:
536 o_len = None
537 Apply.__init__(self, "literal", [], {}, o_len, pure=True)
538 self._obj = obj
539
540 def eval(self, memo=None):
541 if memo is None:
542 memo = {}
543 return memo.setdefault(id(self), self._obj)
544
545 @property
546 def obj(self):
547 return self._obj
548
549 @property
550 def arg(self):
551 return {}
552
553 def pprint(self, ofile, lineno=None, indent=0, memo=None):
554 if lineno is None:
555 lineno = [0]
556 if memo is None:
557 memo = {}
558 if self in memo:
559 print(lineno[0], " " * indent + memo[self], file=ofile)
560 else:
561 # TODO: set up a registry for this
562 if isinstance(self._obj, np.ndarray):
563 msg = "Literal{{np.ndarray,shape={},min={:f},max={:f}}}".format(
564 self._obj.shape,
565 self._obj.min(),
566 self._obj.max(),
567 )
568 else:
569 msg = "Literal{%s}" % str(self._obj)
570 memo[self] = "%s [line:%i]" % (msg, lineno[0])
571 print(lineno[0], " " * indent + msg, file=ofile)
572 lineno[0] += 1
573
574 def replace_input(self, old_node, new_node):
575 return []
576
577 def clone_from_inputs(self, inputs, o_len="same"):
578 return self.__class__(self._obj)
579
580
581class Lambda:

Callers 7

test_literal_pprintFunction · 0.90
test_literal_applyFunction · 0.90
test_literal_unpackingFunction · 0.90
test_switch_and_RaiseFunction · 0.90
test_kwswitchFunction · 0.90
as_applyFunction · 0.85
base.pyFile · 0.85

Calls

no outgoing calls

Tested by 5

test_literal_pprintFunction · 0.72
test_literal_applyFunction · 0.72
test_literal_unpackingFunction · 0.72
test_switch_and_RaiseFunction · 0.72
test_kwswitchFunction · 0.72