MCPcopy Create free account
hub / github.com/pytorch/pytorch / op_func

Method op_func

caffe2/python/functional.py:31–108  ·  view source on GitHub ↗
(*inputs, **args)

Source from the content-addressed store, hash-verified

29class _Functional:
30 def __getattribute__(self, op_type):
31 def op_func(*inputs, **args):
32 ws = Workspace()
33 schema = OpSchema.get(op_type)
34 input_prefix = 'input_'
35 output_prefix = 'output_'
36
37 def get_name_list(prefix, num, max_num):
38 return [prefix + str(x) for x in range(min(num, max_num))]
39
40 input_names, output_names = [], []
41 input_names = get_name_list(
42 input_prefix, len(inputs), schema.max_input
43 )
44 # verify the length of input name is in range
45 # of schema
46 num_input = len(input_names)
47 if num_input > schema.max_input or num_input < \
48 schema.min_input or not schema.num_inputs_allowed(num_input):
49 raise ValueError(
50 "Functional C2: Number of inputs not in \
51 range: {} - {} or not allowed."
52 .format(schema.min_input, schema.max_input)
53 )
54
55 if 'num_output' in args:
56 num_output = args['num_output']
57 if num_output > schema.max_output or \
58 num_output < schema.min_output or \
59 not schema.num_outputs_allowed(num_output) or \
60 not schema.num_inputs_outputs_allowed(num_input,
61 num_output):
62 raise ValueError(
63 "Functional C2: Number of output \
64 not in range: {} - {} or not allowed"
65 .format(schema.min_output, schema.max_output)
66 )
67 output_names = get_name_list(
68 output_prefix, num_output, schema.max_output
69 )
70 args.pop('num_output')
71 calculated = schema.CalculateOutput(num_input)
72 if not output_names and calculated != -1:
73 output_names = get_name_list(
74 output_prefix, calculated, schema.max_output
75 )
76
77 if not output_names:
78 max_output = schema.max_output
79 # For an op with max_output == inf
80 # and no Output defined in schema
81 # user should pass output_size explicitly
82 if schema.inf == max_output:
83 raise ValueError(
84 "For operators with max_output == inf,\
85 user should pass num_output explicitly."
86 )
87 output_names = get_name_list(
88 output_prefix, max_output, max_output

Callers 15

forwardMethod · 0.45
forwardMethod · 0.45
forwardMethod · 0.45
forwardMethod · 0.45
forwardMethod · 0.45
forwardMethod · 0.45
forwardMethod · 0.45
forwardMethod · 0.45
forwardMethod · 0.45
forwardMethod · 0.45
forwardMethod · 0.45
forwardMethod · 0.45

Calls 6

WorkspaceClass · 0.90
namedtupledictFunction · 0.85
rangeFunction · 0.50
getMethod · 0.45
formatMethod · 0.45
popMethod · 0.45

Tested by 15

forwardMethod · 0.36
forwardMethod · 0.36
forwardMethod · 0.36
forwardMethod · 0.36
forwardMethod · 0.36
forwardMethod · 0.36
forwardMethod · 0.36
forwardMethod · 0.36
forwardMethod · 0.36
forwardMethod · 0.36
forwardMethod · 0.36
forwardMethod · 0.36