(self)
| 107 | result = initializer(mx.zeros((1,))) |
| 108 | |
| 109 | def test_orthogonal(self): |
| 110 | initializer = init.orthogonal(gain=1.0, dtype=mx.float32) |
| 111 | |
| 112 | # Test with a square matrix |
| 113 | shape = (4, 4) |
| 114 | result = initializer(mx.zeros(shape, dtype=mx.float32)) |
| 115 | self.assertEqual(result.shape, shape) |
| 116 | self.assertEqual(result.dtype, mx.float32) |
| 117 | |
| 118 | I = result @ result.T |
| 119 | eye = mx.eye(shape[0], dtype=mx.float32) |
| 120 | self.assertTrue( |
| 121 | mx.allclose(I, eye, atol=1e-5), "Orthogonal init failed on a square matrix." |
| 122 | ) |
| 123 | |
| 124 | # Test with a rectangular matrix: more rows than cols |
| 125 | shape = (6, 4) |
| 126 | result = initializer(mx.zeros(shape, dtype=mx.float32)) |
| 127 | self.assertEqual(result.shape, shape) |
| 128 | self.assertEqual(result.dtype, mx.float32) |
| 129 | |
| 130 | I = result.T @ result |
| 131 | eye = mx.eye(shape[1], dtype=mx.float32) |
| 132 | self.assertTrue( |
| 133 | mx.allclose(I, eye, atol=1e-5), |
| 134 | "Orthogonal init failed on a rectangular matrix.", |
| 135 | ) |
| 136 | |
| 137 | |
| 138 | if __name__ == "__main__": |
nothing calls this directly
no test coverage detected