class TransactionOp(graph.Operator): Input1 = graph.InputSlot() # required slot Input2 = graph.InputSlot(optional=True) # optional slot Input3 = graph.InputSlot(value=3) # required slot with default value, i.e. already connected Output1 = graph.OutputSlot() setupOutputs = mock.Mock() def propagateDirty(self, slot, roid, index): pass
class OpTesting5ToMulti(graph.Operator): name = "OpTesting5ToMulti" Input0 = graph.InputSlot(optional=True) Input1 = graph.InputSlot(optional=True) Input2 = graph.InputSlot(optional=True) Input3 = graph.InputSlot(optional=True) Input4 = graph.InputSlot(optional=True) Outputs = graph.OutputSlot(level=1) def setupOutputs(self): length = 0 for slot in list(self.inputs.values()): if slot.connected(): length += 1 self.outputs["Outputs"].resize(length) i = 0 for sname in sorted(self.inputs.keys()): slot = self.inputs[sname] if slot.connected(): self.outputs["Outputs"][i].meta.assignFrom(slot.meta) i += 1 def execute(self, slot, subindex, roi, result): key = roiToSlice(roi.start, roi.stop) index = subindex[0] i = 0 for sname in sorted(self.inputs.keys()): slot = self.inputs[sname] if slot.connected(): if i == index: return slot[key].wait() i += 1 def propagateDirty(self, islot, subindex, roi): i = 0 for sname in sorted(self.inputs.keys()): slot = self.inputs[sname] if slot == islot: self.outputs["Outputs"][i].setDirty(roi) break if slot.connected(): self.outputs["Outputs"][i].meta.assignFrom(slot.meta) i += 1
class OpB(graph.Operator): Input = graph.InputSlot() # required slot Output = graph.OutputSlot() setupOutputs = mock.Mock() def propagateDirty(self, *a, **kw): pass
class OpA(graph.Operator): Input = graph.InputSlot() # required slot def setupOutputs(self): pass def propagateDirty(self, *a, **kw): pass
class OpDirectConnection(graph.Operator): Input = graph.InputSlot() Output = graph.OutputSlot() def propagateDirty(self, inputSlot, subindex, roi): pass def setupOutputs(self): self.Output.connect(self.Input)
class OpA(graph.Operator): name = "OpA" Input1 = graph.InputSlot() # required slot Input2 = graph.InputSlot(optional=True) # optional slot Input3 = graph.InputSlot( value=3) # required slot with default value, i.e. already connected Input4 = graph.InputSlot( level=1) # required slot with default value, i.e. already connected Output1 = graph.OutputSlot() Output2 = graph.OutputSlot() Output3 = graph.OutputSlot() def __init__(self, *args, **kwargs): graph.Operator.__init__(self, *args, **kwargs) self._configured = False def setupOutputs(self): self._configured = True self.Output1.meta.shape = self.Input1.meta.shape self.Output1.meta.dtype = self.Input1.meta.dtype self.Output2.meta.shape = self.Input1.meta.shape self.Output2.meta.dtype = self.Input1.meta.dtype self.Output3.meta.shape = self.Input1.meta.shape self.Output3.meta.dtype = self.Input1.meta.dtype # print "OpInternal shape=%r, dtype=%r" % (self.Input1.meta.shape, self.Input1.meta.dtype) def execute(self, slot, subindex, roi, result): if slot == self.Output1: result[0] = self.Input1[:].wait()[0] elif slot == self.Output2: result[0] = self.Input2[:].wait()[0] elif slot == self.Output3: result[0] = self.Input3[:].wait()[0] return result def propagateDirty(self, inputSlot, subindex, roi): if inputSlot == self.Input1: self.Output1.setDirty(roi) if inputSlot == self.Input1: self.Output2.setDirty(roi) if inputSlot == self.Input3: self.Output3.setDirty(roi)
class OpWithMultiInputs(graph.Operator): Input = graph.InputSlot(level=1) Output = graph.OutputSlot(level=1) def setupOutputs(self): self.Output.resize(len(self.Input)) def execute(self, slot, subindex, roi, result): key = roi.toSlice() index = subindex[0] if slot.name == "Output": result[...] = self.Input[index][key]
class OpMultiOutput(graph.Operator): Input = graph.InputSlot() Outputs = graph.OutputSlot(level=3) def __init__(self, *args, **kwargs): super(OpMultiOutput, self).__init__(*args, **kwargs) def setupOutputs(self): self.Outputs.resize(4) for i, s in enumerate(self.Outputs): s.resize(4) for j, t in enumerate(s): t.resize(4) for k, u in enumerate(t): u.meta.assignFrom(self.Input.meta) def execute(self, slot, subindex, roi, result): """Result of the output slot is the subslot's subindex.""" assert slot == self.Outputs result[0] = subindex return result def propagateDirty(self, inputSlot, subindex, roi): pass
class OpA(graph.Operator): Input = graph.InputSlot(level=2)
class OpSimple(graph.Operator): Input = graph.InputSlot() Output = graph.OutputSlot() def setupOutputs(self): pass