Skip to content

Conversation

@yungyuc
Copy link
Member

@yungyuc yungyuc commented Nov 14, 2021

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

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".
@yungyuc yungyuc added the enhancement New feature or request label Nov 14, 2021
@yungyuc yungyuc self-assigned this Nov 14, 2021
self.assertEqual((1, 24), sarr.reshape((1, 24)).shape)
self.assertEqual((12, 2), sarr.reshape((12, 2)).shape)

def test_SimpleArray_ghost_1d(self):
Copy link
Member Author

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):
Copy link
Member Author

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]
Copy link
Member Author

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); })
Copy link
Member Author

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...)]; }
Copy link
Member Author

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.

@yungyuc
Copy link
Member Author

yungyuc commented Nov 14, 2021

@y3jo6 Perhaps you may be interested in the code here.

@yungyuc
Copy link
Member Author

yungyuc commented Nov 20, 2021

The code works fine and I am going to check in.

@yungyuc yungyuc merged commit 93e7406 into solvcon:master Nov 20, 2021
@yungyuc yungyuc deleted the feature/ghost-array branch November 20, 2021 12:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant