MCPcopy Create free account
hub / github.com/ml-explore/mlx / test_var

Method test_var

python/tests/test_ops.py:811–832  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

809 self.assertTrue(np.allclose(out, out_np))
810
811 def test_var(self):
812 x = mx.array(
813 [
814 [1, 2],
815 [3, 4],
816 ]
817 )
818 self.assertEqual(mx.var(x).item(), 1.25)
819 y = mx.var(x, keepdims=True)
820 self.assertEqual(y, mx.array(1.25))
821 self.assertEqual(y.shape, (1, 1))
822
823 self.assertEqual(mx.var(x, axis=0).tolist(), [1.0, 1.0])
824 self.assertEqual(mx.var(x, axis=1).tolist(), [0.25, 0.25])
825
826 x = mx.array([1.0, 2.0])
827 out = mx.var(x, ddof=2)
828 self.assertEqual(out.item(), float("inf"))
829
830 x = mx.array([1.0, 2.0])
831 out = mx.var(x, ddof=3)
832 self.assertEqual(out.item(), float("inf"))
833
834 def test_std(self):
835 x = mx.random.uniform(shape=(5, 5))

Callers

nothing calls this directly

Calls 2

itemMethod · 0.80
arrayMethod · 0.60

Tested by

no test coverage detected