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

Function test_get_backend

test/test_backend.py:46–75  ·  view source on GitHub ↗
(nx)

Source from the content-addressed store, hash-verified

44
45
46def test_get_backend(nx):
47 A = np.zeros((3, 2))
48 B = np.zeros((3, 1))
49
50 nx_np = get_backend(A)
51 assert nx_np.__name__ == "numpy"
52
53 A2, B2 = nx.from_numpy(A, B)
54
55 effective_nx = get_backend(A2)
56 assert effective_nx.__name__ == nx.__name__
57
58 effective_nx = get_backend(A2, B2)
59 assert effective_nx.__name__ == nx.__name__
60
61 if nx.__name__ != "numpy":
62 # test that types mathcing different backends in input raise an error
63 with pytest.raises(ValueError):
64 get_backend(A, B2)
65 else:
66 # Check that subclassing a numpy array does not break get_backend
67 # note: This is only tested for numpy as this is hard to be consistent
68 # with other backends
69 class nx_subclass(nx.__type__):
70 pass
71
72 A3 = nx_subclass(0)
73
74 effective_nx = get_backend(A3, B2)
75 assert effective_nx.__name__ == nx.__name__
76
77
78def test_convert_between_backends(nx):

Callers

nothing calls this directly

Calls 4

get_backendFunction · 0.90
nx_subclassClass · 0.85
from_numpyMethod · 0.80
zerosMethod · 0.45

Tested by

no test coverage detected