Esempio n. 1
0
    lambda u, v, s: unify_MetaSymbol(u, metatize(v), s),
)
_unify.add(
    (tf_class_abstractions, TFlowMetaSymbol, Mapping),
    lambda u, v, s: unify_MetaSymbol(metatize(u), v, s),
)
_unify.add(
    (tf_class_abstractions, tf_class_abstractions, Mapping),
    lambda u, v, s: unify_MetaSymbol(metatize(u), metatize(v), s),
)


def _reify_TFlowClasses(o, s):
    meta_obj = metatize(o)
    return reify(meta_obj, s)


_reify.add((tf_class_abstractions, Mapping), _reify_TFlowClasses)


_car.add((tf.Tensor,), lambda x: operator(metatize(x)))
operator.add((tf.Tensor,), lambda x: operator(metatize(x)))

_cdr.add((tf.Tensor,), lambda x: arguments(metatize(x)))
arguments.add((tf.Tensor,), lambda x: arguments(metatize(x)))

etuplize.add(tf_class_abstractions, lambda x, shallow=False: etuplize(metatize(x), shallow))


__all__ = []
Esempio n. 2
0
)
_unify.add(
    (tt_class_abstractions, TheanoMetaSymbol, Mapping),
    lambda u, v, s: unify_MetaSymbol(metatize(u), v, s),
)
_unify.add(
    (tt_class_abstractions, tt_class_abstractions, Mapping),
    lambda u, v, s: unify_MetaSymbol(metatize(u), metatize(v), s),
)


def _reify_TheanoClasses(o, s):
    meta_obj = metatize(o)
    return reify(meta_obj, s)


_reify.add((tt_class_abstractions, Mapping), _reify_TheanoClasses)

operator.add((tt.Variable, ), lambda x: operator(metatize(x)))
_car.add((tt.Variable, ), lambda x: operator(metatize(x)))

arguments.add((tt.Variable, ), lambda x: arguments(metatize(x)))
_cdr.add((tt.Variable, ), lambda x: arguments(metatize(x)))

term.add((tt.Op, ExpressionTuple), lambda op, args: term(metatize(op), args))

etuplize.add(tt_class_abstractions,
             lambda x, shallow=False: etuplize(metatize(x), shallow))

__all__ = []
Esempio n. 3
0
#     original object is later reconstructed and evaluated (e.g. using
#     `term`).
#
#     """
#     try:
#         x_e = etuple(_car(x), *x.rands, eval_obj=x)
#     except NotImplementedError:
#         raise ConsError("Not a cons pair.")
#
#     return x_e[1:]


def cdr_MetaVariable(x):
    """Return the arguments/tail/CDR of a variable object.

    See `cdr_MetaSymbol`
    """
    try:
        x_e = etuple(_car(x), *x.base_arguments, eval_obj=x)
    except NotImplementedError:
        raise ConsError("Not a cons pair.")

    return x_e[1:]


# _cdr.add((MetaSymbol,), cdr_MetaSymbol)
_cdr.add((MetaVariable, ), cdr_MetaVariable)

# arguments.add((MetaSymbol,), cdr_MetaSymbol)
arguments.add((MetaVariable, ), cdr_MetaVariable)
Esempio n. 4
0

_reify.add((MetaSymbol, dict), _reify_MetaSymbol)

_tuple__reify = _reify.dispatch(tuple, dict)

_reify.add((ExpressionTuple, dict), lambda x, s: _tuple__reify(x, s))

_isvar = isvar.dispatch(object)

isvar.add((MetaSymbol, ),
          lambda x: _isvar(x) or (not isinstance(x.obj, Var) and isvar(x.obj)))

# We don't want to lose special functionality (and caching) because `cdr` uses
# `islice`.
_cdr.add((ExpressionTuple, ), itemgetter(slice(1, None)))


def operator_MetaSymbol(x):
    """Return the operator/head/CAR of a meta symbol."""
    return type(x)


def operator_MetaVariable(x):
    """Return the operator/head/CAR of a meta variable."""
    return x.base_operator


operator.add((MetaSymbol, ), operator_MetaSymbol)
operator.add((MetaVariable, ), operator_MetaVariable)
operator.add((ExpressionTuple, ), itemgetter(0))
Esempio n. 5
0
        raise ConsError("Not a cons pair.")


_car.add((Variable, ), car_Variable)


def cdr_Variable(x):
    if x.owner:
        x_e = etuple(_car(x), *x.owner.inputs, evaled_obj=x)
    else:
        raise ConsError("Not a cons pair.")

    return x_e[1:]


_cdr.add((Variable, ), cdr_Variable)


def car_Op(x):
    if hasattr(x, "__props__"):
        return type(x)

    raise ConsError("Not a cons pair.")


_car.add((Op, ), car_Op)


def cdr_Op(x):
    if not hasattr(x, "__props__"):
        raise ConsError("Not a cons pair.")