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

Method test_sparse

python/tests/test_init.py:92–107  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

90 self.assertEqual(result.dtype, dtype)
91
92 def test_sparse(self):
93 mean = 0.0
94 std = 1.0
95 sparsity = 0.5
96 for dtype in [mx.float32, mx.float16]:
97 initializer = init.sparse(sparsity, mean, std, dtype=dtype)
98 for shape in [(3, 2), (2, 2), (4, 3)]:
99 result = initializer(mx.array(np.empty(shape)))
100 with self.subTest(shape=shape):
101 self.assertEqual(result.shape, shape)
102 self.assertEqual(result.dtype, dtype)
103 self.assertEqual(
104 (mx.sum(result == 0) >= 0.5 * shape[0] * shape[1]), True
105 )
106 with self.assertRaises(ValueError):
107 result = initializer(mx.zeros((1,)))
108
109 def test_orthogonal(self):
110 initializer = init.orthogonal(gain=1.0, dtype=mx.float32)

Callers

nothing calls this directly

Calls 3

initializerFunction · 0.85
arrayMethod · 0.60
emptyMethod · 0.45

Tested by

no test coverage detected