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

Method test_slice_negative_step

python/tests/test_array.py:1550–1618  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1548 self.assertEqualArray(a, update)
1549
1550 def test_slice_negative_step(self):
1551 a_np = np.arange(20)
1552 a_mx = mx.array(a_np)
1553
1554 # Basic negative slice
1555 b_np = a_np[::-1]
1556 b_mx = a_mx[::-1]
1557 self.assertTrue(np.array_equal(b_np, b_mx))
1558
1559 # Bounds negative slice
1560 b_np = a_np[-3:3:-1]
1561 b_mx = a_mx[-3:3:-1]
1562 self.assertTrue(np.array_equal(b_np, b_mx))
1563
1564 # Bounds negative slice
1565 b_np = a_np[25:-50:-1]
1566 b_mx = a_mx[25:-50:-1]
1567 self.assertTrue(np.array_equal(b_np, b_mx))
1568
1569 # Jumping negative slice
1570 b_np = a_np[::-3]
1571 b_mx = a_mx[::-3]
1572 self.assertTrue(np.array_equal(b_np, b_mx))
1573
1574 # Bounds and negative slice
1575 b_np = a_np[-3:3:-3]
1576 b_mx = a_mx[-3:3:-3]
1577 self.assertTrue(np.array_equal(b_np, b_mx))
1578
1579 # Bounds and negative slice
1580 b_np = a_np[25:-50:-3]
1581 b_mx = a_mx[25:-50:-3]
1582 self.assertTrue(np.array_equal(b_np, b_mx))
1583
1584 # Negative slice and ascending bounds
1585 b_np = a_np[0:20:-3]
1586 b_mx = a_mx[0:20:-3]
1587 self.assertTrue(np.array_equal(b_np, b_mx))
1588
1589 # Multi-dim negative slices
1590 a_np = np.arange(3 * 6 * 4).reshape(3, 6, 4)
1591 a_mx = mx.array(a_np)
1592
1593 # Flip each dim
1594 b_np = a_np[..., ::-1]
1595 b_mx = a_mx[..., ::-1]
1596 self.assertTrue(np.array_equal(b_np, b_mx))
1597
1598 b_np = a_np[:, ::-1, :]
1599 b_mx = a_mx[:, ::-1, :]
1600 self.assertTrue(np.array_equal(b_np, b_mx))
1601
1602 b_np = a_np[::-1, ...]
1603 b_mx = a_mx[::-1, ...]
1604 self.assertTrue(np.array_equal(b_np, b_mx))
1605
1606 # Flip pairs of dims
1607 b_np = a_np[::-1, 1:5:2, ::-2]

Callers

nothing calls this directly

Calls 1

arrayMethod · 0.60

Tested by

no test coverage detected