Closed adriendelsalle closed 4 months ago
I've made a quick pass over the proposed changes and overall this looks great, thanks @adriendelsalle !
The grids and aliases are also interverted to better reflect the design
On one hand I find raster_grid
better than raster_grid_xt
as a name for the default container types (i.e., using xtensor containers) ; it is also consistent with RasterGrid
in the Python bindings (where the container type is fixed). On the other hand I agree the switched class name / alias better reflect the design.
Alternatively, could we get rid of the type aliases and set a default value for all template parameters of each grid class? This way we can still use raster_grid
by default (C++17) or it is fine using raster_grid<>
for C++14.
STL containers are used to store info
Yes that makes sense, and the gain in performance for non-cached neighbors is very welcome (the cache can become a big waste of memory for large grids).
PR is to remove hard dependency to xtensor in cmake files, and make it possible to dowstream project to select what implementation they need.
Agreed that may be useful. We'll likely keep xtensor as the default implementation for quite some time, though.
This refactoring is still not finished on the trimesh for which the only working container types are still the xtensor's ones.
Yes this might require some effort to refactor .set_nodes_areas()
, which currently relies on a lot of advanced vectorized functions available in xtensor. This can be done later.
Alternatively, could we get rid of the type aliases and set a default value for all template parameters of each grid class? This way we can still use
raster_grid
by default (C++17) or it is fine usingraster_grid<>
for C++14.
It also means setting a default raster connect template argument?
It also means setting a default raster connect template argument?
Yes, in 90% of cases we use the queen connectivity.
Merged! Thanks a lot @adriendelsalle
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.