function_to_module: creates a dummy module, with the same input / output…

function_to_module: creates a dummy module, with the same input / output parameters as the function, and with the same behaviour
上级 7d3461bf
...@@ -1012,3 +1012,22 @@ class KitComponent(Component): ...@@ -1012,3 +1012,22 @@ class KitComponent(Component):
def build(self, mode, memo): def build(self, mode, memo):
return [memo[i.result].value for i in self.kit.sinputs] return [memo[i.result].value for i in self.kit.sinputs]
def func_to_mod(f):
"""
Creates a dummy module, with external member variables for the input
parameters required by the function f, and a member output defined as:
output <= f(**kwinit)
"""
def make(**kwinit):
m = Module()
outputs = f(**kwinit)
if isinstance(outputs, list):
for i,o in enumerate(outputs):
setattr(m, 'output%(i)i', o)
else:
m.output = outputs
return m
return make
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论