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

Method test_view

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

Source from the content-addressed store, hash-verified

2899 self.assertTrue(np.array_equal(np.array(jvps[0]), b.conj()))
2900
2901 def test_view(self):
2902 # Check scalar
2903 out = mx.array(1, mx.int8).view(mx.uint8).item()
2904 self.assertEqual(out, 1)
2905
2906 a = mx.random.randint(shape=(4, 2, 4), low=-100, high=100)
2907 a_np = np.array(a)
2908
2909 for t in ["bool_", "int16", "float32", "int64"]:
2910 out = a.view(getattr(mx, t))
2911 expected = a_np.view(getattr(np, t))
2912 self.assertTrue(np.array_equal(out, expected, equal_nan=True))
2913
2914 # Irregular strides
2915 a = mx.random.randint(shape=(2, 4), low=-100, high=100)
2916 a = mx.broadcast_to(a, shape=(4, 2, 4))
2917
2918 for t in ["bool_", "int16", "float32", "int64"]:
2919 out = a.view(getattr(mx, t))
2920 a_out = out.view(mx.int32)
2921 self.assertTrue(mx.array_equal(a_out, a, equal_nan=True))
2922
2923 a = mx.random.randint(shape=(4, 4), low=-100, high=100).T
2924 for t in ["bool_", "int16", "float32", "int64"]:
2925 out = a.view(getattr(mx, t))
2926 a_out = out.view(mx.int32)
2927 self.assertTrue(mx.array_equal(a_out, a, equal_nan=True))
2928
2929 def _hadamard(self, N):
2930 # Matches scipy.linalg.hadamard

Callers

nothing calls this directly

Calls 2

itemMethod · 0.80
arrayMethod · 0.60

Tested by

no test coverage detected