Skip to content

Shared memory arrays

Pre-release
Pre-release
Compare
Choose a tag to compare
@g5t g5t released this 06 Nov 09:21
· 52 commits to master since this release

The data storage class ArrayVector<T> has been replaced Array2<T> which shares ownership of its held pointer to allocated heap memory. This allows both internal use of views to avoid copying-out small sections of an array to perform, e.g., a vector operation; using externally owned pointers; and providing its pointer for use by external applications.
To allow this interaction with Python pybind11::buffer_info is utilized to get and return the pointer and relevant array information. Internally the
new class holds an arbitrary shared pointer which serves the dual purpose of reference counting for owned pointers and holding a reference
to an owning object for external pointers.

This refactor is a rather-major change within the C++ code but should not present any great differences through the Python API.
Some concerns to be aware of when using the brille Python module:

  • Methods which take lists of Q points, e.g., brille.BZTrellisQdc.moveinto, should now always be provided a numpy.ndarray (or other Python buffer object) which has shape [N, 3]. Previously arrays with an arbitrary number of dimensions were allowed as long as the last dimension had three elements. These methods should work with any memory layout for the provided arrays, but best performance might be achieved when the 3-vectors are each in contiguous memory.
  • Methods which take and store data to interpolate, e.g., brille.BZTrellisQdc.fill, continue to accept arrays with arbitrary shape, and the shape should be consistent with what is to be interpolated. If the provide array has row-ordered contiguous memory layout it will be used directly -- care should be taken to ensure other references to the same array do not modify the underlying data unintentionally as this could produce unexpected interpolation results -- for any other memory layout the array is copied.