-
Notifications
You must be signed in to change notification settings - Fork 432
added a mapper that maps the indexes of a view to the indices of a container #2880
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
added a mapper that maps the indexes of a view to the indices of a container #2880
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR introduces a new index_mapper class that enables conversion of indices from a view's coordinate system to the underlying container's coordinate system. This is particularly useful when working with views that contain fixed dimensions (integral slices), which reduce the dimensionality compared to the original container.
Key Changes:
- Implements
index_mappertemplate class with support forxviewtypes - Provides
map()andmap_at()methods for index conversion with and without bounds checking - Adds comprehensive test coverage for 2D and 3D views with various slicing patterns
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 22 comments.
| File | Description |
|---|---|
include/xtensor/views/index_mapper.hpp |
New header file implementing the index_mapper class with template metaprogramming to handle view-to-container index mapping |
test/test_xview.cpp |
Adds test cases for index_mapper functionality covering simple 2D views and 3D views with various slice configurations |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| * @throws Assertion failure if `i != 0` for integral slices. | ||
| * @throws Assertion failure if `i >= slice.size()` for non-integral slices. |
Copilot
AI
Dec 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The assertion message is misleading in the documentation. The assertion checks that the index is within bounds (i < slice.size()), but the documentation states it "throws Assertion failure if i >= slice.size()". While technically correct, assertions don't throw exceptions in the traditional sense - they abort the program in debug builds. Consider updating the documentation to clarify this behavior or use proper exception handling if runtime bounds checking is desired.
| * @throws Assertion failure if `i != 0` for integral slices. | |
| * @throws Assertion failure if `i >= slice.size()` for non-integral slices. | |
| * @note This function uses assertions to enforce preconditions: | |
| * - Aborts with assertion failure if `i != 0` for integral slices. | |
| * - Aborts with assertion failure if `i >= slice.size()` for non-integral slices. | |
| * These are not exceptions and will terminate the program in debug builds if triggered. |
| value_type map_at(const UnderlyingContainer& container, const view_type& view, const Indices... indices) const | ||
| requires(sizeof...(Indices) == n_free); | ||
|
|
||
| constexpr size_t dimension() const { return n_free; } |
Copilot
AI
Dec 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The dimension() method returns the number of free (non-integral) dimensions, but the method name is ambiguous. It's unclear whether this returns the view's dimension or the container's dimension. Consider renaming to free_dimensions() or view_dimension() to make the purpose clearer.
| constexpr size_t dimension() const { return n_free; } | |
| constexpr size_t free_dimensions() const { return n_free; } |
Checklist
Description
The
index_mapperclass provides functionality to convert indices from a view's coordinate systemto the corresponding indices in the underlying container. This is particularly useful for views
that contain integral slices (fixed indices), as these slices reduce the dimensionality of the view.
Example: