Skip to content

Fix xview data offsets with multiple leading newaxis slices - #2942

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

vera-rubin wants to merge 1 commit into
xtensor-stack:masterfrom
vera-rubin:fix/multiple-newaxis-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. (No API change.)

Description

As documented, newaxis() adds a dimension of length one, so this view should select the second row:

xt::xarray<int> a = {{0, 1}, {2, 3}};
auto v = xt::view(a, xt::newaxis(), xt::newaxis(), xt::range(1, 2), xt::all());
xt::xarray<int> copied = v;
v = 100;

Direct indexing returns {2,3}, but copying produces {1,2} and assignment leaves a as {{0,100},{100,3}} instead of {{0,1},{100,100}}.

We compute each slice offset using its original axis stride, accounting for preceding new axes. We added a regression covering the offset, copying and scalar assignment, and ran the existing xview and xview semantic 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