(self)
| 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) |
nothing calls this directly
no test coverage detected