Skip to content

Conversation

@edwinsolisf
Copy link
Contributor

Fixes issue where array indexing with a sequence whose step is not 1 is handled as a sequence with step 1.

Description

  • Is this a new feature or a bug fix?: Bug fix
  • More detail if necessary to describe all commits in pull request.: Adds a member variable to all index structs to pass the step into the different kernels and compute the correct index.
  • Why these changes are necessary: Incorrect behavior of af::seq in array indexing
  • Potential impact on specific hardware, software or backends: affects all backends
  • New functions and their functionality.: None
  • Can this PR be backported to older versions?: All backends except oneAPI can be backported
  • Future changes not implemented in this PR.: None

Fixes: #3525

Changes to Users

  • Additional options added to the build.: None
  • No action required by the user

Checklist

  • Rebased on latest master
  • Code compiles
  • Tests pass
  • Functions added to unified API
  • Functions documented

int i =
p.strds[0] * trimIndex(s0 ? gx + p.offs[0] : ptr0[gx], in.dims[0]);
p.strds[0] *
trimIndex(s0 ? gx * p.steps[0] + p.offs[0] : ptr0[gx], in.dims[0]);
Copy link
Member

Choose a reason for hiding this comment

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

Do you need to update the condition on 42? looks like you would read out of bounds here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The condition is still correct because gx gy gz gw refer to indices in the output array, and the given check makes sure they are always inside the output array dimensions. The changes affect the indexing of the input array being sampled and the function trimIndex makes sure it's inside the input array dimensions.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ran tests with compute sanitizer. No issues found.

Copy link
Contributor

@christophe-murphy christophe-murphy left a comment

Choose a reason for hiding this comment

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

Looks good, tests are passing.

@christophe-murphy christophe-murphy merged commit 18028c0 into arrayfire:master Feb 11, 2025
christophe-murphy added a commit that referenced this pull request Feb 15, 2025
…cludes the new test data needed for the test added in pull requests #3585 and #3587.
christophe-murphy added a commit that referenced this pull request Feb 20, 2025
…cludes the new test data needed for the test added in pull requests #3585 and #3587. (#3635)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] indexing the second dim with af::seq ignores step

4 participants