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

Function test_random_backends

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

Source from the content-addressed store, hash-verified

734
735
736def test_random_backends(nx):
737 tmp_u = nx.rand()
738
739 assert tmp_u < 1
740
741 tmp_n = nx.randn()
742
743 nx.seed(0)
744 M1 = nx.to_numpy(nx.rand(5, 2))
745 nx.seed(0)
746 M2 = nx.to_numpy(nx.rand(5, 2, type_as=tmp_n))
747
748 assert np.all(M1 >= 0)
749 assert np.all(M1 < 1)
750 assert M1.shape == (5, 2)
751 assert np.allclose(M1, M2)
752
753 nx.seed(0)
754 M1 = nx.to_numpy(nx.randn(5, 2))
755 nx.seed(0)
756 M2 = nx.to_numpy(nx.randn(5, 2, type_as=tmp_u))
757
758 nx.seed(42)
759 v1 = nx.randn()
760 v2 = nx.randn()
761 assert v1 != v2
762
763 nx.seed(0)
764 M1 = nx.to_numpy(nx.randperm(5))
765 nx.seed(0)
766 M2 = nx.to_numpy(nx.randperm(5, type_as=tmp_u))
767 M3 = nx.arange(5)
768 M4 = nx.sort(nx.randperm(5))
769 assert np.allclose(M3, M4)
770
771 with pytest.raises(ValueError, match="size must be"):
772 res = nx.randperm(size=[5, 12])
773
774
775def test_gradients_backends():

Callers

nothing calls this directly

Calls 8

to_numpyMethod · 0.80
randMethod · 0.45
randnMethod · 0.45
seedMethod · 0.45
allcloseMethod · 0.45
randpermMethod · 0.45
arangeMethod · 0.45
sortMethod · 0.45

Tested by

no test coverage detected