-
Notifications
You must be signed in to change notification settings - Fork 56
Allow negative value for the ghost index in the first dimension of SimpleArray #21
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
Conversation
1. Add a constructor of small_vector taking initiali value. 2. Add a pointer m_body to the start of the body data in SimpleArray. 3. Improve the index validation with the ghost index support. 1. Add multi-dimensional index validation. 2. When ghost is non-trivial, the flat indexing only works with 1-dimensional arrays. 3. Add Python unit tests.
Remove the clang-tidy error of "readability-else-after-return".
| self.assertEqual((1, 24), sarr.reshape((1, 24)).shape) | ||
| self.assertEqual((12, 2), sarr.reshape((12, 2)).shape) | ||
|
|
||
| def test_SimpleArray_ghost_1d(self): |
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.
Test for ghost index for 1D arrays.
| ): | ||
| sarr[14] = 1 | ||
|
|
||
| def test_SimpleArray_ghost_md(self): |
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.
Test the ghost index for the multi-dimensional arrays.
| r"SimpleArray::validate_range\(\): cannot handle 3-dimensional " | ||
| r"\(more than 1\) array with non-zero nghost: 1" | ||
| ): | ||
| sarr[-1] |
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.
For multi-dimensional arrays, the single-index ghost index should not work at all.
| } | ||
| } | ||
| ) | ||
| .def("__getitem__", [](wrapped_type const & self, ssize_t key) { return self.at(key); }) |
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.
Make getitem and setitem cleaner.
|
|
||
| template < typename ... Args > | ||
| value_type const & operator()(Args ... args) const { return data(buffer_offset(m_stride, args...)); } | ||
| value_type const & operator()(Args ... args) const { return m_body[buffer_offset(m_stride, args...)]; } |
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.
Use the body pointer to replace the original data pointer. This implements the ghost index access.
|
@y3jo6 Perhaps you may be interested in the code here. |
|
The code works fine and I am going to check in. |
The ghost index works like the negative index in the POD array. In SimpleArray, it is only enabled in the first (leading dimension).
ref #20