MCPcopy Create free account
hub / github.com/PythonOT/POT / assert_allclose_sol

Function assert_allclose_sol

test/test_solvers.py:75–102  ·  view source on GitHub ↗
(sol1, sol2)

Source from the content-addressed store, hash-verified

73
74
75def assert_allclose_sol(sol1, sol2):
76 lst_attr = [
77 "value",
78 "value_linear",
79 "plan",
80 "potential_a",
81 "potential_b",
82 "marginal_a",
83 "marginal_b",
84 ]
85
86 nx1 = sol1._backend if sol1._backend is not None else ot.backend.NumpyBackend()
87 nx2 = sol2._backend if sol2._backend is not None else ot.backend.NumpyBackend()
88
89 for attr in lst_attr:
90 if getattr(sol1, attr) is not None and getattr(sol2, attr) is not None:
91 try:
92 np.allclose(
93 nx1.to_numpy(getattr(sol1, attr)),
94 nx2.to_numpy(getattr(sol2, attr)),
95 equal_nan=True,
96 )
97 except NotImplementedError:
98 pass
99 elif getattr(sol1, attr) is None and getattr(sol2, attr) is None:
100 return True
101 else:
102 return False
103
104
105def test_solve(nx):

Callers 8

test_solveFunction · 0.85
test_solve_gridFunction · 0.85
test_solve_gromovFunction · 0.85
test_solve_gromov_gridFunction · 0.85
test_solve_sampleFunction · 0.85
test_solve_sample_lazyFunction · 0.85

Calls 2

to_numpyMethod · 0.80
allcloseMethod · 0.45

Tested by

no test coverage detected