MCPcopy Create free account
hub / github.com/TencentARC/BrushNet / print_tensor_test

Function print_tensor_test

src/diffusers/utils/testing_utils.py:109–121  ·  view source on GitHub ↗
(tensor, filename="test_corrections.txt", expected_tensor_name="expected_slice")

Source from the content-addressed store, hash-verified

107
108
109def print_tensor_test(tensor, filename="test_corrections.txt", expected_tensor_name="expected_slice"):
110 test_name = os.environ.get("PYTEST_CURRENT_TEST")
111 if not torch.is_tensor(tensor):
112 tensor = torch.from_numpy(tensor)
113
114 tensor_str = str(tensor.detach().cpu().flatten().to(torch.float32)).replace("\n", "")
115 # format is usually:
116 # expected_slice = np.array([-0.5713, -0.3018, -0.9814, 0.04663, -0.879, 0.76, -1.734, 0.1044, 1.161])
117 output_str = tensor_str.replace("tensor", f"{expected_tensor_name} = np.array")
118 test_file, test_class, test_fn = test_name.split("::")
119 test_fn = test_fn.split()[0]
120 with open(filename, "a") as f:
121 print(";".join([test_file, test_class, test_fn, output_str]), file=f)
122
123
124def get_tests_dir(append_path=None):

Callers 1

test_i2vgen_xlMethod · 0.90

Calls 1

toMethod · 0.45

Tested by

no test coverage detected