MCPcopy Index your code
hub / github.com/pytorch/pytorch / _CreateAndAddToSelf

Method _CreateAndAddToSelf

caffe2/python/core.py:2240–2270  ·  view source on GitHub ↗

A helper function to create an operator and add it to self.

(self, op_type, inputs, outputs=None, **kwargs)

Source from the content-addressed store, hash-verified

2238 self._net.device_option.CopyFrom(device_option)
2239
2240 def _CreateAndAddToSelf(self, op_type, inputs, outputs=None, **kwargs):
2241 """A helper function to create an operator and add it to self.
2242 """
2243 inputs = _RectifyInputOutput(inputs)
2244 for input in inputs:
2245 if not self.BlobIsDefined(input):
2246 assert input.Net() != self
2247 self.AddExternalInput(input)
2248 if outputs is None:
2249 # If we do not specify an output, we will assume that this op
2250 # produces one output in this case.
2251 outputs = self.NextName(prefix=op_type)
2252 elif type(outputs) is int:
2253 # In this case, we will auto-fill the given number of outputs
2254 # with auto-generated names.
2255 outputs = [
2256 self.NextName(prefix=op_type, output_id=i)
2257 for i in range(outputs)]
2258 outputs = _RectifyInputOutput(outputs, net=self)
2259 op = CreateOperator(op_type, inputs, outputs, **kwargs)
2260 self._ExtendOps([op])
2261
2262 workspace.operator_tracebacks[self.Name()][
2263 len(self._net.op) - 1] = _extract_stacktrace()
2264
2265 if len(op.output) == 0:
2266 return
2267 elif len(op.output) == 1:
2268 return BlobReference(op.output[0], self)
2269 else:
2270 return tuple(BlobReference(o, self) for o in op.output)
2271
2272 def __getattr__(self, op_type):
2273 if op_type.startswith('__'):

Callers 2

__getattr__Method · 0.95
PythonMethod · 0.95

Calls 11

BlobIsDefinedMethod · 0.95
AddExternalInputMethod · 0.95
NextNameMethod · 0.95
_ExtendOpsMethod · 0.95
NameMethod · 0.95
_RectifyInputOutputFunction · 0.85
CreateOperatorFunction · 0.85
_extract_stacktraceFunction · 0.85
BlobReferenceClass · 0.85
NetMethod · 0.80
rangeFunction · 0.50

Tested by

no test coverage detected