Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix range clamping in subscript operator.#6242

Merged
mzient merged 1 commit into
NVIDIA:mainfrom
mzient:fix_subscript_clamp
Mar 4, 2026
Merged

Fix range clamping in subscript operator.#6242
mzient merged 1 commit into
NVIDIA:mainfrom
mzient:fix_subscript_clamp

Conversation

@mzient
Copy link
Copy Markdown
Contributor

@mzient mzient commented Mar 2, 2026

Category:

Bug fix (non-breaking change which fixes an issue)

Description:

This PR fixes the bug reported in #6234

Additional information:

Affected modules and functionalities:

Key points relevant for the review:

Tests:

  • Existing tests apply
  • New tests added
    • Python tests
    • GTests
    • Benchmark
    • Other
  • N/A

Checklist

Documentation

  • Existing documentation applies
  • Documentation updated
    • Docstring
    • Doxygen
    • RST
    • Jupyter
    • Other
  • N/A

DALI team only

Requirements

  • Implements new requirements
  • Affects existing requirements
  • N/A

REQ IDs: N/A

JIRA TASK: DALI-4627

@dali-automaton
Copy link
Copy Markdown
Collaborator

CI MESSAGE: [45132404]: BUILD STARTED

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Mar 2, 2026

Greptile Summary

Fixed a bug in the subscript operator where range bounds were incorrectly clamped when slice indices exceeded array bounds. The issue affected both forward and reverse slicing:

  • Forward slicing: Start index was incorrectly clamped to in_extent - 1 instead of in_extent, causing out-of-bounds slices like arr[50:150] on a 10-element array to return [9] instead of an empty array
  • Reverse slicing: Start index didn't allow -1 as a valid clamped value for reverse iteration, breaking reverse slices with out-of-bounds negative indices

The fix properly separates the clamping logic based on step direction, ensuring both lo and hi bounds are consistently clamped to match Python's slice semantics. New tests verify the fix works correctly for both edge cases.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The fix is a targeted bug correction with clear logic, comprehensive test coverage for the specific edge cases, and no unintended side effects. The change aligns the clamping behavior with Python semantics and is well-contained to the affected code path.
  • No files require special attention

Important Files Changed

Filename Overview
dali/operators/generic/slice/subscript.h Fixed range clamping logic to properly handle out-of-bounds slice indices for both forward and reverse iteration, matching Python semantics
dali/test/python/operator_2/test_subscript.py Added comprehensive test coverage for range truncation in both forward and reverse slicing with out-of-bounds indices

Last reviewed commit: b5b9b92

Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@dali-automaton
Copy link
Copy Markdown
Collaborator

CI MESSAGE: [45132404]: BUILD PASSED

@mzient mzient merged commit 5761247 into NVIDIA:main Mar 4, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants