7 def _list_supported_ops():
11 def emit_arg(indent, i, arg):
12 v =
"{} : {}".format(arg.name, emit_type(arg.type))
13 default = arg.default_value
14 if default
is not None:
15 v =
"{}={}".format(v, str(default))
17 v =
"\n{}{}".format(
" " * indent, v)
20 def emit_args(indent, arguments):
21 return ",".join(emit_arg(indent, i, arg)
for i, arg
in enumerate(arguments))
24 return emit_type(ret.type)
26 def emit_rets(returns):
28 return emit_ret(returns[0])
29 return "Tuple[{}]".format(
", ".join(emit_ret(r)
for r
in returns))
31 def emit_schema(mod, name, schema, arg_start=0):
32 qualified_name =
"{}.{}".format(mod, name)
33 schema =
"{}({}) -> {}".format(qualified_name,
34 emit_args(len(qualified_name) + 1 + 4, schema.arguments[arg_start:]),
35 emit_rets(schema.returns))
39 return name.startswith(
'_')
and not name.startswith(
'__')
43 for mod
in torch.jit._modules_containing_builtins:
47 if builtin
is not None:
48 schemas = torch._C._jit_get_schemas_for_operator(builtin)
49 for schema
in schemas:
52 functions.append(emit_schema(name, elem, schema))
58 attr = getattr(mod, elem)
59 if not callable(attr)
or elem[0] ==
'_':
67 schema = scripted._get_method(
'forward').
schema()
68 functions.append(emit_schema(name, elem, schema))
70 def is_tensor_method(schema):
71 if len(schema.arguments) == 0:
73 self = schema.arguments[0]
74 if self.name !=
'self':
76 if not self.type.isSubtypeOf(torch._C.TensorType.get()):
82 for elem
in dir(torch.Tensor):
84 schemas = torch._C._jit_get_schemas_for_operator(
"aten::" + elem)
85 for schema
in schemas:
86 if is_tensor_method(schema):
87 methods.append(emit_schema(
'Tensor', elem, schema, arg_start=1))
89 def emit_block(decls):
90 return '\n::\n\n{}\n'.format(
''.join(
' {}\n\n'.format(d)
for d
in decls))
100 return body.format(emit_block(functions), emit_block(methods))
102 __doc__ = _list_supported_ops()
Module caffe2.python.schema.
def _try_compile_weak_script(fn)