示例#1
0
 def __exit__(self, *args):
     interpreter.set_interpretation(self._old_interpretation)
     self._old_interpretation = None
示例#2
0
def moment_matching(cls, *args):
    """
    A moment matching interpretation of :class:`Reduce` expressions. This falls
    back to :class:`eager` in other cases.
    """
    result = moment_matching.dispatch(cls, *args)
    if result is None:
        result = eager.dispatch(cls, *args)
    if result is None:
        result = normalize.dispatch(cls, *args)
    if result is None:
        result = reflect(cls, *args)
    return result


interpreter.set_interpretation(eager)  # Use eager interpretation by default.


class FunsorMeta(type):
    """
    Metaclass for Funsors to perform four independent tasks:

    1.  Fill in default kwargs and convert kwargs to args before deferring to a
        nonstandard interpretation. This allows derived metaclasses to fill in
        defaults and do type conversion, thereby simplifying logic of
        interpretations.
    2.  Ensure each Funsor class has an attribute ``._ast_fields`` describing
        its input args and each Funsor instance has an attribute ``._ast_args``
        with values corresponding to its input args. This allows the instance
        to be reflectively reconstructed under a different interpretation, and
        is used by :func:`funsor.interpreter.reinterpret`.
示例#3
0
 def __enter__(self):
     self.tape = []
     self._old_interpretation = interpreter._INTERPRETATION
     interpreter.set_interpretation(self)
     return self