MCPcopy Create free account
hub / github.com/NVIDIA/SOL-ExecBench / _infer_dps

Function _infer_dps

scripts/run_dataset.py:85–114  ·  view source on GitHub ↗

Infer destination-passing style by checking the ``run()`` signature. If the last parameter of ``run()`` matches the last output name in the definition, the solution writes into pre-allocated output buffers (DPS).

(code: str, definition: dict)

Source from the content-addressed store, hash-verified

83
84
85def _infer_dps(code: str, definition: dict) -> bool:
86 """Infer destination-passing style by checking the ``run()`` signature.
87
88 If the last parameter of ``run()`` matches the last output name in the
89 definition, the solution writes into pre-allocated output buffers (DPS).
90 """
91 output_names = list(definition.get("outputs", {}).keys())
92 if not output_names:
93 return False
94
95 last_output = output_names[-1]
96
97 try:
98 tree = ast.parse(code)
99 except SyntaxError:
100 return False
101
102 for node in ast.walk(tree):
103 if (
104 isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef))
105 and node.name == "run"
106 ):
107 args = node.args
108 # Last positional arg name
109 if args.args:
110 last_param = args.args[-1].arg
111 return last_param == last_output
112 break
113
114 return False
115
116
117def build_solution_for_problem(

Callers 2

build_custom_solutionFunction · 0.85
build_reference_solutionFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected