Skip to content

Commit

Permalink
Fix downward slices for positive base arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
BCSharp authored and slozier committed Dec 6, 2024
1 parent 84de081 commit 699824b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Src/IronPython/Runtime/Operations/ArrayOps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ private static void FixSlice(Slice slice, Array a, out int ostart, out int ostop
if (ostop < 0 && lb >= 0) {
ostop += ub + 1;
}
if (ostop < 0) {
if (ostop < lb) {
ostop = ostep > 0 ? lb : lb - 1;
}
} else if (ostop > ub) {
Expand Down
16 changes: 16 additions & 0 deletions Tests/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,4 +497,20 @@ def test_equality_rank(self):
self.assertTrue(c != d)
self.assertFalse(d != d1)

def test_slice_down(self):
#arr = System.Array[int]((2, 3, 4), base=2)
arr = System.Array.CreateInstance(int, (3,), (2,))
for i in range(2, 2 + 3):
arr[i] = i

self.assertEqual(arr[-1:-4:-1], System.Array[int]((4, 3, 2)))
self.assertEqual(arr[-1:-5:-1], System.Array[int]((4, 3, 2)))
self.assertEqual(arr[-1:-6:-1], System.Array[int]((4, 3, 2)))

self.assertEqual(arr[2:1:-1], System.Array[int]((2,)))
self.assertEqual(arr[2:-5:-1], System.Array[int]((2,)))
self.assertEqual(arr[2:-6:-1], System.Array[int]((2,)))
self.assertEqual(arr[1:-5:-1], System.Array[int](()))
self.assertEqual(arr[0:-5:-1], System.Array[int](()))

run_test(__name__)

0 comments on commit 699824b

Please sign in to comment.