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
    """Get a tuple of the arguments used to construct this meta object.

    This applies a special consideration for Theano `Variable`s: if it has a
    non-`None` `owner` with non-`None` `op` and `inputs`, then the `Variable`
    is more aptly given as the output of `op(inputs)`.

    Otherwise, considering the `Variable` in isolation, it can be constructed
    directly using its `type` constructor.
    """
    x_owner = getattr(x, 'owner', None)
    if x_owner and hasattr(x_owner, 'op'):
        return x_owner.op
    return operator_MetaSymbol(x)


operator.add((MetaSymbol, ), operator_MetaSymbol)
operator.add((MetaVariable, ), operator_MetaVariable)
operator.add((tt.Variable, ), lambda x: operator(MetaVariable.from_obj(x)))


def arguments_MetaSymbol(x):
    return tuple(x.rands())


def arguments_MetaVariable(x):
    """Get a tuple of the arguments used to construct this meta object.

    This applies a special consideration for Theano `Variable`s: if it has a
    non-`None` `owner` with non-`None` `op` and `inputs`, then the `Variable`
    is more aptly given as the output of `op(inputs)`.
Esempio n. 4
0
# 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))


def arguments_MetaSymbol(x):
    """Return the arguments/tail/CDR of a meta symbol.

    We build the full `etuple` for the argument, then return the
    `cdr`/tail, so that the original object is retained when/if the
    original object is later reconstructed and evaluated (e.g. using
    `term`).

    """
    x_e = etuple(type(x), *x.rands, eval_obj=x)
    return x_e[1:]
Esempio n. 5
0
#     return type(x)


def car_MetaVariable(x):
    """Return the operator/head/CAR of a meta variable."""
    try:
        return x.base_operator
    except NotImplementedError:
        raise ConsError("Not a cons pair.")


# _car.add((MetaSymbol,), car_MetaSymbol)
_car.add((MetaVariable, ), car_MetaVariable)

# operator.add((MetaSymbol,), car_MetaSymbol)
operator.add((MetaVariable, ), car_MetaVariable)

# def cdr_MetaSymbol(x):
#     """Return the arguments/tail/CDR of a meta symbol.
#
#     We build the full `etuple` for the argument, then return the
#     `cdr`/tail, so that the original object is retained when/if the
#     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.")
#