Skip to content

Fix argsort for views with nonzero data offsets - #2941

Open
vera-rubin wants to merge 1 commit into
xtensor-stack:masterfrom
vera-rubin:fix/argsort-view-offset
Open

vera-rubin wants to merge 1 commit into
xtensor-stack:masterfrom
vera-rubin:fix/argsort-view-offset

Conversation

@vera-rubin

Copy link
Copy Markdown

Checklist

  • The title and commit message(s) are descriptive.
  • Small commits made to fix your PR have been squashed to avoid history pollution.
  • Tests have been added for new features or bug fixes.
  • API of new functions and classes are documented. (Not applicable, no new API.)

Description

xt::argsort reads the parent's first row for a contiguous sliced view with a nonzero data offset. This returns {{0, 1, 2}} below, while the documented sorted-order contract requires {{2, 1, 0}} for the selected values {3, 2, 1}. xt::strided_view has the same problem.

xt::xarray<int> a = {{1, 2, 3}, {3, 2, 1}};
auto v = xt::view(a, xt::range(1, 2), xt::all());
auto indices = xt::argsort(v);

We add the input's data_offset() when starting leading-axis traversal.

We verified that the regression fails before the change and passes afterward alongside the existing sorting tests.

— ChipLab

This branch has not been deployed

No deployments
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.

1 participant