Fix xaxis_*_iterator shape and strides types #2747
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Checklist
Description
Fixes #2116.
As described by @dchansen in #2723:
So I changed the type of the shape and strides members in the returned views/iterators as follows:
xaxis_iterator
:std::vector<T>
, whereT
is the value type of the input expression's shape or strides type.xaxis_slice_iterator
:std::array<T, 1>
, since the resulting view is always one-dimensional. Note that this is different from the currently returned shape and strides type in case ofxarray
input, so this breaks API/ABI for those cases. If that is not desired, this case should also usestd::vector<T>
.For both iterators, this loses some compile-time information in certain cases. E.g.:
xtensor_fixed
inputs, the resulting view could also have compile-time shape and strides, but some more metaprogramming magic would be required to correctly detect that situation and select the correct types.xtensor
inputs,xaxis_iterator
's view could have fixed dimension of N-1.Someone else would have to look into that if that's desired. However, I think the above paragraph would be more of an optimization, and this fix at least makes the iterators on
xtensor
andxtensor_fixed
functionally correct, in the sense that their views have the correct shape and contain the correct elements.I also made the iterator test cases type parameterized, so the existing test cases check all of
xarray
,xtensor
, andxtensor_fixed
as input types.