A helper function to create an operator and add it to self.
(self, op_type, inputs, outputs=None, **kwargs)
| 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('__'): |
no test coverage detected