| 107 | |
| 108 | |
| 109 | def 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 | |
| 124 | def get_tests_dir(append_path=None): |