Operator Transform for single-output callables
Changes
This MR adds:
-
InputPull
mixin class for Operators that keeps the "pull frames to inputs dict" logic DRY -
OperatorTransform
class for wrapping general python callables as operators
Examples
This example creates an operator that adds two inputs, then scales the result by 2 (the latter step representing some post-processing)
add_t_2 = OperatorTransform(name='add_times_2',
source_pad_names=('O1',),
sink_pad_names=('I1', 'I2'),
func=operator.add,
input_processor=lambda frame: frame.data,
output_processor=lambda data: data * 2)
# Place Frames on input Pads
add_t_2.inputs[add_t_2.sink_pads[0]] = Frame(data=10, metadata={'name': 'F1'})
add_t_2.inputs[add_t_2.sink_pads[1]] = Frame(data=20, metadata={'name': 'F2'})
frame = add_t_2.transform(add_t_2.source_pads[0])
assert frame.data == 60
Edited by James Kennington