Skip to content

Commit

Permalink
ref: remove old template types on containers (#908)
Browse files Browse the repository at this point in the history
Remove container template types that are not really used and rename std::array to darray everywhere in the core library. Also removes some leftover cmath includes
  • Loading branch information
niermann999 authored Dec 20, 2024
1 parent 2e41d90 commit 7816acc
Show file tree
Hide file tree
Showing 91 changed files with 335 additions and 435 deletions.
2 changes: 1 addition & 1 deletion core/include/detray/builders/bin_fillers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ struct bin_associator {
// Fill the surfaces into the grid by matching their contour onto the
// grid bins
bin_association(ctx, surfaces, transforms, masks, grid,
std::array<scalar_t, 2>{0.1f, 0.1f}, false);
darray<scalar_t, 2>{0.1f, 0.1f}, false);
}
};

Expand Down
3 changes: 1 addition & 2 deletions core/include/detray/builders/detail/bin_association.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include "detray/utils/ranges.hpp"

// System include(s)
#include <array>
#include <vector>

namespace detray::detail {
Expand All @@ -44,7 +43,7 @@ static inline void bin_association(const context_t & /*context*/,
const transform_container_t &transforms,
const mask_container_t &surface_masks,
grid_t &grid,
const std::array<scalar_t, 2> &bin_tolerance,
const darray<scalar_t, 2> &bin_tolerance,
bool absolute_tolerance = true) {

using algebra_t = typename grid_t::local_frame_type::algebra_type;
Expand Down
42 changes: 16 additions & 26 deletions core/include/detray/builders/detail/volume_connector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ namespace detray {
/// @param volume_grid [in] the indexed volume grid
///
template <typename detector_t,
template <typename, std::size_t> class array_type = darray,
template <typename...> class tuple_type = dtuple,
template <typename...> class vector_type = dvector>
void connect_cylindrical_volumes(
detector_t &d, const typename detector_t::volume_finder &volume_grid) {
Expand All @@ -35,7 +33,7 @@ void connect_cylindrical_volumes(

// The grid is populated, now create portal surfaces
// Start from left bottom corner (0,0)
vector_type<array_type<dindex, 2>> seeds = {{0, 0}};
vector_type<darray<dindex, 2>> seeds = {{0, 0}};
dmap<dindex, dindex> seed_map;

// The axes are used quite a bit
Expand All @@ -51,7 +49,7 @@ void connect_cylindrical_volumes(
*
* @note seeds are only set in bottom left corners of blocks
**/
auto add_new_seed = [&](const array_type<dindex, 2> &seed,
auto add_new_seed = [&](const darray<dindex, 2> &seed,
dindex volume_index) -> void {
if (volume_index == dindex_invalid) {
return;
Expand All @@ -78,14 +76,10 @@ void connect_cylindrical_volumes(
auto &volume = d.volume(ref);

// Collect portals per seed
vector_type<tuple_type<array_type<scalar_t, 2>, dindex>>
left_portals_info;
vector_type<tuple_type<array_type<scalar_t, 2>, dindex>>
upper_portals_info;
vector_type<tuple_type<array_type<scalar_t, 2>, dindex>>
right_portals_info;
vector_type<tuple_type<array_type<scalar_t, 2>, dindex>>
lower_portals_info;
vector_type<dtuple<darray<scalar_t, 2>, dindex>> left_portals_info;
vector_type<dtuple<darray<scalar_t, 2>, dindex>> upper_portals_info;
vector_type<dtuple<darray<scalar_t, 2>, dindex>> right_portals_info;
vector_type<dtuple<darray<scalar_t, 2>, dindex>> lower_portals_info;

/// Helper method for walking up along the bins
///
Expand All @@ -96,12 +90,11 @@ void connect_cylindrical_volumes(
///
/// @return the end position of the the walk (inside position)
auto walk_up =
[&](array_type<dindex, 2> start_bin,
vector_type<tuple_type<array_type<scalar_t, 2>, dindex>>
&portals_info,
int peek, bool add_seed = false) -> array_type<dindex, 2> {
[&](darray<dindex, 2> start_bin,
vector_type<dtuple<darray<scalar_t, 2>, dindex>> &portals_info,
int peek, bool add_seed = false) -> darray<dindex, 2> {
auto running_bin = start_bin;
array_type<dindex, 2> last_added = {dindex_invalid, dindex_invalid};
darray<dindex, 2> last_added = {dindex_invalid, dindex_invalid};
// Test entry
auto test = volume_grid.bin(running_bin[0], running_bin[1]);
// Low/high
Expand Down Expand Up @@ -161,13 +154,12 @@ void connect_cylindrical_volumes(
///
/// @return the end position of the the walk (inside position)
auto walk_right =
[&](const array_type<dindex, 2> &start_bin,
vector_type<tuple_type<array_type<scalar_t, 2>, dindex>>
&portals_info,
[&](const darray<dindex, 2> &start_bin,
vector_type<dtuple<darray<scalar_t, 2>, dindex>> &portals_info,
int peek, bool add_seed = false,
bool walk_only = false) -> array_type<dindex, 2> {
bool walk_only = false) -> darray<dindex, 2> {
auto running_bin = start_bin;
array_type<dindex, 2> last_added = {dindex_invalid, dindex_invalid};
darray<dindex, 2> last_added = {dindex_invalid, dindex_invalid};

// Test, low and high at seed position
auto test = volume_grid.bin(running_bin[0], running_bin[1]);
Expand Down Expand Up @@ -245,8 +237,7 @@ void connect_cylindrical_volumes(
*
**/
auto add_disc_portals =
[&](vector_type<tuple_type<array_type<scalar_t, 2>, dindex>>
&portals_info,
[&](vector_type<dtuple<darray<scalar_t, 2>, dindex>> &portals_info,
dindex bound_index) -> void {
using portal_t = typename detector_t::surface_type;
using volume_link_t = typename portal_t::volume_link_type;
Expand Down Expand Up @@ -296,8 +287,7 @@ void connect_cylindrical_volumes(
* @param bound_index
**/
auto add_cylinder_portal =
[&](vector_type<tuple_type<array_type<scalar_t, 2>, dindex>>
&portals_info,
[&](vector_type<dtuple<darray<scalar_t, 2>, dindex>> &portals_info,
dindex bound_index) -> void {
using portal_t = typename detector_t::surface_type;
using volume_link_t = typename portal_t::volume_link_type;
Expand Down
4 changes: 2 additions & 2 deletions core/include/detray/builders/detector_builder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ class detector_builder {
0u, 0.f, -constant<scalar_type>::pi,
-2000.f, 180.f, constant<scalar_type>::pi,
2000.f};
std::array<std::size_t, 3> n_vgrid_bins{1u, 1u, 1u};
darray<std::size_t, 3> n_vgrid_bins{1u, 1u, 1u};

std::array<std::vector<scalar_type>, 3UL> bin_edges{
darray<std::vector<scalar_type>, 3UL> bin_edges{
std::vector<scalar_type>{0.f, 180.f},
std::vector<scalar_type>{-constant<scalar_type>::pi,
constant<scalar_type>::pi},
Expand Down
7 changes: 3 additions & 4 deletions core/include/detray/builders/grid_builder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include "detray/utils/grid/detail/concepts.hpp"

// System include(s)
#include <array>
#include <cassert>
#include <memory>
#include <vector>
Expand Down Expand Up @@ -80,11 +79,11 @@ class grid_builder : public volume_decorator<detector_t> {
template <typename grid_shape_t>
DETRAY_HOST void init_grid(
const mask<grid_shape_t, algebra_type> &m,
const std::array<std::size_t, grid_t::dim> &n_bins,
const darray<std::size_t, grid_t::dim> &n_bins,
const std::vector<std::pair<typename grid_t::loc_bin_index, dindex>>
&bin_capacities = {},
const std::array<std::vector<scalar_type>, grid_t::dim> &ax_bin_edges =
std::array<std::vector<scalar_type>, grid_t::dim>()) {
const darray<std::vector<scalar_type>, grid_t::dim> &ax_bin_edges =
darray<std::vector<scalar_type>, grid_t::dim>()) {

static_assert(
std::is_same_v<typename grid_shape_t::template local_frame_type<
Expand Down
90 changes: 45 additions & 45 deletions core/include/detray/builders/grid_factory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ class grid_factory {
typename phi_binning = axis::regular<scalar_type, host_container_types>>
requires std::is_enum_v<decltype(r_bounds::label)> auto new_grid(
const mask<annulus2D, algebra_type> &grid_bounds,
const std::array<std::size_t, 2UL> n_bins,
const darray<std::size_t, 2UL> n_bins,
const std::vector<std::pair<loc_bin_index<annulus2D>, dindex>>
&bin_capacities = {},
const std::array<std::vector<scalar_type>, 2UL> &bin_edges =
std::array<std::vector<scalar_type>, 2UL>(),
const std::array<std::vector<scalar_type>, 2UL> &axis_spans =
std::array<std::vector<scalar_type>, 2UL>()) const {
const darray<std::vector<scalar_type>, 2UL> &bin_edges =
darray<std::vector<scalar_type>, 2UL>(),
const darray<std::vector<scalar_type>, 2UL> &axis_spans =
darray<std::vector<scalar_type>, 2UL>()) const {

static_assert(
std::is_same_v<phi_bounds, axis::circular<>>,
Expand Down Expand Up @@ -137,13 +137,13 @@ class grid_factory {
typename z_binning = axis::regular<scalar_type, host_container_types>>
requires std::is_enum_v<decltype(x_bounds::label)> auto new_grid(
const mask<cuboid3D, algebra_type> &grid_bounds,
const std::array<std::size_t, 3UL> n_bins,
const darray<std::size_t, 3UL> n_bins,
const std::vector<std::pair<loc_bin_index<cuboid3D>, dindex>>
&bin_capacities = {},
const std::array<std::vector<scalar_type>, 3UL> &bin_edges =
std::array<std::vector<scalar_type>, 3UL>(),
const std::array<std::vector<scalar_type>, 3UL> &axis_spans =
std::array<std::vector<scalar_type>, 3UL>()) const {
const darray<std::vector<scalar_type>, 3UL> &bin_edges =
darray<std::vector<scalar_type>, 3UL>(),
const darray<std::vector<scalar_type>, 3UL> &axis_spans =
darray<std::vector<scalar_type>, 3UL>()) const {
// Axes boundaries and local indices
using boundary = cuboid3D::boundaries;
using axes_t = axes<cuboid3D>::template type<algebra_t>;
Expand Down Expand Up @@ -193,13 +193,13 @@ class grid_factory {
typename z_binning = axis::regular<scalar_type, host_container_types>>
requires std::is_enum_v<decltype(rphi_bounds::label)> auto new_grid(
const mask<cylinder2D, algebra_type> &grid_bounds,
const std::array<std::size_t, 2UL> n_bins,
const darray<std::size_t, 2UL> n_bins,
const std::vector<std::pair<loc_bin_index<cylinder2D>, dindex>>
&bin_capacities = {},
const std::array<std::vector<scalar_type>, 2UL> &bin_edges =
std::array<std::vector<scalar_type>, 2UL>(),
const std::array<std::vector<scalar_type>, 2UL> &axis_spans =
std::array<std::vector<scalar_type>, 2UL>()) const {
const darray<std::vector<scalar_type>, 2UL> &bin_edges =
darray<std::vector<scalar_type>, 2UL>(),
const darray<std::vector<scalar_type>, 2UL> &axis_spans =
darray<std::vector<scalar_type>, 2UL>()) const {

static_assert(
std::is_same_v<rphi_bounds, axis::circular<axis::label::e_rphi>>,
Expand Down Expand Up @@ -239,13 +239,13 @@ class grid_factory {
typename z_binning = axis::regular<scalar_type, host_container_types>>
requires std::is_enum_v<decltype(rphi_bounds::label)> auto new_grid(
const mask<concentric_cylinder2D, algebra_type> &grid_bounds,
const std::array<std::size_t, 2UL> n_bins,
const darray<std::size_t, 2UL> n_bins,
const std::vector<std::pair<loc_bin_index<concentric_cylinder2D>,
dindex>> &bin_capacities = {},
const std::array<std::vector<scalar_type>, 2UL> &bin_edges =
std::array<std::vector<scalar_type>, 2UL>(),
const std::array<std::vector<scalar_type>, 2UL> &axis_spans =
std::array<std::vector<scalar_type>, 2UL>()) const {
const darray<std::vector<scalar_type>, 2UL> &bin_edges =
darray<std::vector<scalar_type>, 2UL>(),
const darray<std::vector<scalar_type>, 2UL> &axis_spans =
darray<std::vector<scalar_type>, 2UL>()) const {

static_assert(
std::is_same_v<rphi_bounds, axis::circular<axis::label::e_rphi>>,
Expand Down Expand Up @@ -287,13 +287,13 @@ class grid_factory {
typename z_binning = axis::regular<scalar_type, host_container_types>>
requires std::is_enum_v<decltype(r_bounds::label)> auto new_grid(
const mask<cylinder3D, algebra_type> &grid_bounds,
const std::array<std::size_t, 3UL> n_bins,
const darray<std::size_t, 3UL> n_bins,
const std::vector<std::pair<loc_bin_index<cylinder3D>, dindex>>
&bin_capacities = {},
const std::array<std::vector<scalar_type>, 3UL> &bin_edges =
std::array<std::vector<scalar_type>, 3UL>(),
const std::array<std::vector<scalar_type>, 3UL> &axis_spans =
std::array<std::vector<scalar_type>, 3UL>()) const {
const darray<std::vector<scalar_type>, 3UL> &bin_edges =
darray<std::vector<scalar_type>, 3UL>(),
const darray<std::vector<scalar_type>, 3UL> &axis_spans =
darray<std::vector<scalar_type>, 3UL>()) const {

static_assert(
std::is_same_v<phi_bounds, axis::circular<>>,
Expand Down Expand Up @@ -350,13 +350,13 @@ class grid_factory {
typename phi_binning = axis::regular<scalar_type, host_container_types>>
requires std::is_enum_v<decltype(r_bounds::label)> auto new_grid(
const mask<ring2D, algebra_type> &grid_bounds,
const std::array<std::size_t, 2UL> n_bins,
const darray<std::size_t, 2UL> n_bins,
const std::vector<std::pair<loc_bin_index<ring2D>, dindex>>
&bin_capacities = {},
const std::array<std::vector<scalar_type>, 2UL> &bin_edges =
std::array<std::vector<scalar_type>, 2UL>(),
const std::array<std::vector<scalar_type>, 2UL> &axis_spans =
std::array<std::vector<scalar_type>, 2UL>()) const {
const darray<std::vector<scalar_type>, 2UL> &bin_edges =
darray<std::vector<scalar_type>, 2UL>(),
const darray<std::vector<scalar_type>, 2UL> &axis_spans =
darray<std::vector<scalar_type>, 2UL>()) const {

static_assert(std::is_same_v<phi_bounds, axis::circular<>>,
"Phi axis bounds need to be circular for ring shape");
Expand Down Expand Up @@ -396,13 +396,13 @@ class grid_factory {
typename y_binning = axis::regular<scalar_type, host_container_types>>
requires std::is_enum_v<decltype(x_bounds::label)> auto new_grid(
const mask<rectangle2D, algebra_type> &grid_bounds,
const std::array<std::size_t, 2UL> n_bins,
const darray<std::size_t, 2UL> n_bins,
const std::vector<std::pair<loc_bin_index<rectangle2D>, dindex>>
&bin_capacities = {},
const std::array<std::vector<scalar_type>, 2UL> &bin_edges =
std::array<std::vector<scalar_type>, 2UL>(),
const std::array<std::vector<scalar_type>, 2UL> &axis_spans =
std::array<std::vector<scalar_type>, 2UL>()) const {
const darray<std::vector<scalar_type>, 2UL> &bin_edges =
darray<std::vector<scalar_type>, 2UL>(),
const darray<std::vector<scalar_type>, 2UL> &axis_spans =
darray<std::vector<scalar_type>, 2UL>()) const {
// Axes boundaries and local indices
using boundary = rectangle2D::boundaries;
using axes_t = axes<rectangle2D>::template type<algebra_t>;
Expand Down Expand Up @@ -441,13 +441,13 @@ class grid_factory {
typename y_binning = axis::regular<scalar_type, host_container_types>>
requires std::is_enum_v<decltype(x_bounds::label)> auto new_grid(
const mask<trapezoid2D, algebra_type> &grid_bounds,
const std::array<std::size_t, 2UL> n_bins,
const darray<std::size_t, 2UL> n_bins,
const std::vector<std::pair<loc_bin_index<trapezoid2D>, dindex>>
&bin_capacities = {},
const std::array<std::vector<scalar_type>, 2UL> &bin_edges =
std::array<std::vector<scalar_type>, 2UL>(),
const std::array<std::vector<scalar_type>, 2UL> &axis_spans =
std::array<std::vector<scalar_type>, 2UL>()) const {
const darray<std::vector<scalar_type>, 2UL> &bin_edges =
darray<std::vector<scalar_type>, 2UL>(),
const darray<std::vector<scalar_type>, 2UL> &axis_spans =
darray<std::vector<scalar_type>, 2UL>()) const {
// Axes boundaries and local indices
using boundary = trapezoid2D::boundaries;
using axes_t = axes<trapezoid2D>::template type<algebra_t>;
Expand Down Expand Up @@ -538,11 +538,11 @@ class grid_factory {
template <concepts::grid grid_t, typename grid_shape_t>
auto new_grid(
const mask<grid_shape_t, algebra_type> &m,
const std::array<std::size_t, grid_t::dim> &n_bins,
const darray<std::size_t, grid_t::dim> &n_bins,
const std::vector<std::pair<typename grid_t::loc_bin_index, dindex>>
&bin_capacities = {},
const std::array<std::vector<scalar_type>, grid_t::dim> &ax_bin_edges =
{}) const {
const darray<std::vector<scalar_type>, grid_t::dim> &ax_bin_edges = {})
const {

return new_grid(m, n_bins, bin_capacities, ax_bin_edges,
typename grid_t::axes_type::bounds{},
Expand All @@ -558,11 +558,11 @@ class grid_factory {
std::enable_if_t<std::is_enum_v<typename grid_shape_t::boundaries>,
bool> = true>
auto new_grid(const mask<grid_shape_t, algebra_type> &m,
const std::array<std::size_t, grid_shape_t::dim> &n_bins,
const darray<std::size_t, grid_shape_t::dim> &n_bins,
const std::vector<
std::pair<axis::multi_bin<sizeof...(bound_ts)>, dindex>>
&bin_capacities = {},
const std::array<std::vector<scalar_type>, grid_shape_t::dim>
const darray<std::vector<scalar_type>, grid_shape_t::dim>
&ax_bin_edges = {},
const types::list<bound_ts...> & = {},
const types::list<binning_ts...> & = {}) const {
Expand Down
12 changes: 5 additions & 7 deletions core/include/detray/builders/material_map_builder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include "detray/materials/material_map.hpp"

// System include(s)
#include <array>
#include <cassert>
#include <map>
#include <memory>
Expand Down Expand Up @@ -118,7 +117,7 @@ class material_map_builder final : public volume_decorator<detector_t> {
}

// Construct and append the material map for a given surface shape
std::array<std::vector<scalar_type>, DIM> axis_spans{};
darray<std::vector<scalar_type>, DIM> axis_spans{};
auto axis_spans_itr = m_axis_spans.find(sf_idx);
if (axis_spans_itr != m_axis_spans.end()) {
axis_spans = axis_spans_itr->second;
Expand Down Expand Up @@ -195,9 +194,9 @@ class material_map_builder final : public volume_decorator<detector_t> {
/// The surface this material map belongs to (index is volume local)
std::map<dindex, std::vector<bin_data_type>> m_bin_data;
/// Number of bins for the material grid axes
std::map<dindex, std::array<std::size_t, DIM>> m_n_bins{};
std::map<dindex, darray<std::size_t, DIM>> m_n_bins{};
/// The Axis spans for the material grid axes
std::map<dindex, std::array<std::vector<scalar_type>, DIM>> m_axis_spans{};
std::map<dindex, darray<std::vector<scalar_type>, DIM>> m_axis_spans{};
/// Helper to generate empty grids
mat_map_factory_t m_factory{};
};
Expand Down Expand Up @@ -227,9 +226,8 @@ struct add_sf_material_map {
[[maybe_unused]] const index_t& index,
[[maybe_unused]] const mat_factory_t& mat_factory,
[[maybe_unused]] std::vector<bin_data_t>& bin_data,
[[maybe_unused]] const std::array<std::size_t, DIM>& n_bins,
[[maybe_unused]] const std::array<std::vector<scalar_t>, DIM>&
axis_spans,
[[maybe_unused]] const darray<std::size_t, DIM>& n_bins,
[[maybe_unused]] const darray<std::vector<scalar_t>, DIM>& axis_spans,
[[maybe_unused]] material_store_t& mat_store) const {

using mask_shape_t = typename coll_t::value_type::shape;
Expand Down
Loading

0 comments on commit 7816acc

Please sign in to comment.