def gen_type_list(attr, name): if isinstance(attr, (list, tuple)): ret = pybind.AttrValue() ret.attr_type = pybind.AttrValue.Type.type_list ret.type_list = pybind.DataTypeVector(attr) return ret else: raise ValueError("Cannot parse attr[{0}] type[{1}] to a shape attr".format(name, attr.__class__))
def gen_type(attr, name): if isinstance(attr, DataType): ret = pybind.AttrValue() ret.attr_type = pybind.AttrValue.Type.type ret.type = attr return ret else: raise ValueError("Cannot parse attr[{0}] type[{1}] to a type attr".format(name, attr.__class__))
def gen_shape(attr, name): if isinstance(attr, (TensorShape, list, tuple)): ret = pybind.AttrValue() ret.attr_type = pybind.AttrValue.Type.shape ret.shape = pybind.TensorShape(pybind.SizeTVector(TensorShape(attr).dims())) return ret else: raise ValueError("Cannot parse attr[{0}] type[{1}] to a shape attr".format(name, attr.__class__))
def gen_int(attr, name): if isinstance(attr, (int, long)): ret = pybind.AttrValue() ret.attr_type = pybind.AttrValue.Type.int ret.i = attr return ret else: raise ValueError("Cannot parse attr[{0}] type[{1}] to a int attr".format(name, attr.__class__))
def gen_bool(attr, name): if isinstance(attr, bool): ret = pybind.AttrValue() ret.attr_type = pybind.AttrValue.Type.bool ret.b = attr return ret else: raise ValueError("Cannot parse attr[{0}] type[{1}] to a bool attr".format(name, attr.__class__))
def gen_str(attr, name): if isinstance(attr, (str, unicode, bytes)): ret = pybind.AttrValue() ret.attr_type = pybind.AttrValue.Type.string ret.s = attr return ret else: raise ValueError("Cannot parse attr[{0}] type[{1}] to a str attr".format(name, attr.__class__))