Exemple #1
0
    def test_set_value(self):

        ts = TensorShape(IntVector(lpx.IntVector([1, 2, 3, 4])))

        ts.set_value(0, -1)

        assert len(ts) == 4
        assert ts[0] == -1
        assert ts[1] == 2
def relay_op(op_name, expr, in_xlayers):
    # type: (str, tvm.relay.expr.Expr, List[XLayer]) -> XLayer
    """ Insert generic relay op operator """

    logger.debug("-- op_name: {}".format(op_name))
    logger.debug("-- expr: {}".format(expr.op))

    ty = expr.checked_type
    if isinstance(ty, relay.ty.TensorType):
        relay_shape = TensorShape([int(i) for i in list(ty.shape)])
        dtype = str(ty.dtype)
    else:
        relay_shape = TupleShape([
            TensorShape([int(i) for i in list(t_ty.shape)])
            for t_ty in ty.fields
        ])
        dtype = [str(t_ty.dtype) for t_ty in ty.fields]

    # TODO
    relay_shape.set_value(axis=0, value=-1)

    attrs = {}
    for attr in dir(expr.attrs):
        value = getattr(expr.attrs, attr)
        attrs[attr] = str(value)

    if 'dtype' in attrs:
        dtype = attrs['dtype']
        del attrs['dtype']

    X = xlf.get_xop_factory_func('RelayOp')(op_name,
                                            in_xlayers,
                                            relay_shape=relay_shape.tolist(),
                                            dtype=dtype,
                                            relay_id=[hash(expr)],
                                            **attrs)

    return X