MCPcopy Create free account
hub / github.com/pytorch/executorch / tensor_to_cpp_code

Function tensor_to_cpp_code

kernels/test/test_case_gen.py:229–240  ·  view source on GitHub ↗
(tensor: torch.Tensor)

Source from the content-addressed store, hash-verified

227
228
229def tensor_to_cpp_code(tensor: torch.Tensor) -> str:
230 sizes = list(tensor.size())
231 sizes = [str(s) for s in sizes]
232 sizes_str = "{" + ", ".join(sizes) + "}"
233 data = torch.flatten(tensor).tolist()
234 data = [str(d) for d in data]
235 data_str = "{" + ", ".join(data) + "}"
236 if tensor.dtype == torch.bool:
237 return f"""tf_bool.make({sizes_str}, {data_str})""".replace(
238 "True", "true"
239 ).replace("False", "false")
240 return f"""tf.make({sizes_str}, {data_str})"""
241
242
243def argument_to_cpp_code(arg):

Callers 2

argument_to_cpp_codeFunction · 0.85
gen_test_casesFunction · 0.85

Calls 1

flattenMethod · 0.80

Tested by

no test coverage detected