(s1, s2, rtol=1e-5, atol=1e-8)
| 62 | |
| 63 | |
| 64 | def compare_structures(s1, s2, rtol=1e-5, atol=1e-8): |
| 65 | if type(s1) != type(s2): |
| 66 | return False |
| 67 | if isinstance(s1, dict): |
| 68 | if set(s1.keys()) != set(s2.keys()): |
| 69 | return False |
| 70 | return all(compare_structures(s1[k], s2[k], rtol, atol) for k in s1.keys()) |
| 71 | if isinstance(s1, list): |
| 72 | if len(s1) != len(s2): |
| 73 | return False |
| 74 | return all(compare_structures(i1, i2, rtol, atol) for i1, i2 in zip(s1, s2)) |
| 75 | if isinstance(s1, torch.Tensor): |
| 76 | return torch.allclose(s1, s2, rtol=rtol, atol=atol) |
| 77 | return s1 == s2 |
| 78 | |
| 79 | |
| 80 | def test_packer(): |
no outgoing calls
no test coverage detected