Create a container API for structured grids #155
Draft
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.
Description
This PR aims to refactor the container API of the grids, to next make it easier to refactor the container API of the flow related classes (graph, operators, etc.).
For most operation on the grids, there is no reason to rely on
xtensor
except for trivial broadcasting or selection that could be performed directly on STL containers.It is proposed in this PR to adopt a container API unrelated to the underlying container implementation and interface the implementation using a template specialization:
container_selection
and a type selector (typicallyxt_selector
)fastscapelib
is exposed usingcontainer_impl
xtensor
are renamed to be agnostic:xt_ndims
->container_ndims
,xt_selector
->container_selector
, etc.The grids and aliases are also interverted to better reflect the design:
raster_grid
andprofile_grid
are the templated classesraster_grid_xt
andprofile_grid_xt
are specialization relying onxtensor
with cache logic (andraster_connect::queen
for raster grid)At few places, STL containers are used to store info (
neighbors_offsets_type
was defined asxt::xtensor<xt::xtensor_fixed<std::ptrdiff_t, xt::xshape<2>>, 1>
and proposed to be simplified asstd::vector<std::array<std::ptrdiff_t, 2>>
).The global performance is:
node_neighbors_offsets
to operate overstd::array
s instead ofxt::xtensor
is probably what gives the main impactAlso proposed in this PR is to remove hard dependency to
xtensor
in cmake files, and make it possible to dowstream project to select what implementation they need. This option could probably added later in another PR when the library will be completely independent fromxtensor
(not only the structured grids).This refactoring is still not finished on the
trimesh
for which the only working container types are still thextensor
's ones.