| 1682 | self.assertTrue(mx.array_equal(y1, y2)) |
| 1683 | |
| 1684 | def test_memoryless_copy(self): |
| 1685 | a_mx = mx.ones((2, 2)) |
| 1686 | b_mx = mx.broadcast_to(a_mx, (5, 2, 2)) |
| 1687 | |
| 1688 | # Make np arrays without copy |
| 1689 | a_np = np.array(a_mx, copy=False) |
| 1690 | b_np = np.array(b_mx, copy=False) |
| 1691 | |
| 1692 | # Check that we get read-only array that does not own the underlying data |
| 1693 | self.assertFalse(a_np.flags.owndata) |
| 1694 | self.assertTrue(a_np.flags.writeable) |
| 1695 | |
| 1696 | # Check contents |
| 1697 | self.assertTrue(np.array_equal(np.ones((2, 2), dtype=np.float32), a_np)) |
| 1698 | self.assertTrue(np.array_equal(np.ones((5, 2, 2), dtype=np.float32), b_np)) |
| 1699 | |
| 1700 | # Check strides |
| 1701 | self.assertSequenceEqual(b_np.strides, (0, 8, 4)) |
| 1702 | |
| 1703 | def test_np_array_conversion_copies_by_default(self): |
| 1704 | a_mx = mx.ones((2, 2)) |