xtensor icon indicating copy to clipboard operation
xtensor copied to clipboard

Fixing some iterator issues

Open vakokako opened this issue 2 years ago • 1 comments

This merge request fixes some issues with iterators.

  • [x] xfunctor_view::crbegin was returning non const iterator
  • [x] xiterator_adaptor::data was returning iterator, not a pointer
  • [x] xt::reshape_view().rbegin() didn't compile

Fixing multidimensional index of end xiterator

  • [x] multidimensional index of xiterator for end() iterator would be always set to shape(), which made *rbegin() be out of bounds access. I changed the index of end() to be shape[i] - 1 for all dimensions, except the last one in row-major case, and except the first one in column-major case
xarray<int> a = { {{0, 1, 2, 3},
                   {4, 5, 6, 7},
                   {8, 9, 10, 11}},
                  {{12, 13, 14, 15},
                   {16, 17, 18, 19},
                   {20, 21, 22, 23}} };

auto view = dynamic_view(a, { 1, keep(0, 2), range(1, 4) });
// shape: {1, 2, 3}

// old version
view.end(); // index {1, 2, 3}
std::prev(view.end()); // index {1, 2, 2}
// out of bounds access
*view.rbegin(); // index {1, 2, 2}

// new version
view.end(); // index {0, 1, 3}
std::prev(view.end()); // index {0, 1, 2}
// correct access
*view.rbegin(); // index {0, 1, 2}

vakokako avatar Aug 04 '22 16:08 vakokako

Sorry for missing this, I have been swamped with a lot of other tasks. There is an issue in this PR that I want to comment on since it is not trivial. I'll try to do it next week.

JohanMabille avatar Sep 23 '22 14:09 JohanMabille

This pr is stale because it has been open for 60 days with no activity. It will be automatically closed in 14 days.

github-actions[bot] avatar Jun 19 '23 01:06 github-actions[bot]

Hey, are there any updates on including this in xtensor?

vakokako avatar Jun 26 '23 12:06 vakokako

Sorry for missing this, I have been swamped with a lot of other tasks. There is an issue in this PR that I want to comment on since it is not trivial. I'll try to do it next week.

Hey @JohanMabille , you said there are some issues with this PR, can you tell us a hint where to look?

emmenlau avatar Jul 13 '23 08:07 emmenlau

@JohanMabille I updated the merge request, removed the changes to buffer adaptor's API. There is a failing 'pretty format json' pre-commit check, I'm not sure what does that mean and how to deal with that?

vakokako avatar Aug 11 '23 14:08 vakokako

[... ] There is a failing 'pretty format json' pre-commit check, I'm not sure what does that mean and how to deal with that?

I think running pre-commit run --all-files and push the changes should fix the issue. This failure is probably due to an update of pre-commit since your PR does not change anything regarding the notebooks.

JohanMabille avatar Aug 21 '23 07:08 JohanMabille

Actually this also requires updating the config, let's merge this one and I'll fix the build on master directly.

JohanMabille avatar Aug 21 '23 07:08 JohanMabille

Thanks!

vakokako avatar Aug 31 '23 08:08 vakokako