Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add traccc tuple and pair types #814

Merged
merged 1 commit into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions core/include/traccc/edm/details/container_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@
// Project include(s).
#include "traccc/definitions/qualifiers.hpp"
#include "traccc/edm/details/container_element.hpp"
#include "traccc/utils/pair.hpp"

// VecMem include(s).
#include <vecmem/memory/memory_resource.hpp>

// Thrust include(s).
#include <thrust/pair.h>

// System include(s).
#include <cassert>
#include <stdexcept>
Expand All @@ -38,7 +36,7 @@ namespace traccc {
template <typename header_t, typename item_t,
template <typename> class vector_t,
template <typename> class jagged_vector_t,
template <typename, typename> class pair_t = thrust::pair>
template <typename, typename> class pair_t = traccc::pair>
class container_base {
public:
/// @name Type definitions
Expand Down
6 changes: 2 additions & 4 deletions core/include/traccc/finding/candidate_link.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@

// Project include(s).
#include "traccc/edm/measurement.hpp"

// Thrust include(s).
#include <thrust/pair.h>
#include "traccc/utils/pair.hpp"

namespace traccc {

Expand All @@ -20,7 +18,7 @@ namespace traccc {
struct candidate_link {

// Type of index
using link_index_type = thrust::pair<unsigned int, unsigned int>;
using link_index_type = traccc::pair<unsigned int, unsigned int>;

// Index of link from the previous step
link_index_type previous;
Expand Down
20 changes: 20 additions & 0 deletions core/include/traccc/utils/pair.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/** TRACCC library, part of the ACTS project (R&D line)
*
* (c) 2025 CERN for the benefit of the ACTS project
*
* Mozilla Public License Version 2.0
*/

#pragma once

namespace traccc {
template <typename T1, typename T2>
struct pair {
public:
using first_type = T1;
using second_type = T2;

T1 first;
T2 second;
};
} // namespace traccc
88 changes: 88 additions & 0 deletions core/include/traccc/utils/tuple.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/** TRACCC library, part of the ACTS project (R&D line)
*
* (c) 2025 CERN for the benefit of the ACTS project
*
* Mozilla Public License Version 2.0
*/

#pragma once

#include <type_traits>
#include <utility>

#include "traccc/definitions/qualifiers.hpp"

namespace traccc {

template <typename... Ts>
struct tuple {};

template <typename T, typename... Ts>
struct tuple<T, Ts...> {

TRACCC_HOST_DEVICE constexpr tuple(){};

constexpr tuple(const tuple &o) requires(
std::is_copy_constructible_v<T> &&
(std::is_copy_constructible_v<Ts> && ...)) = default;

template <typename U, typename... Us>
requires std::is_constructible_v<T, U &&>
&&std::is_constructible_v<tuple<Ts...>, Us &&...>
TRACCC_HOST_DEVICE explicit constexpr tuple(
const tuple<U, Us...> &o)
: v(o.v), r(o.r) {}

constexpr tuple(tuple &&o) noexcept
requires(std::is_move_constructible_v<T> &&
(std::is_move_constructible_v<Ts> && ...)) = default;

template <typename U, typename... Us>
requires std::is_constructible_v<T, U &&>
&&std::is_constructible_v<tuple<Ts...>, Us &&...>
TRACCC_HOST_DEVICE explicit constexpr tuple(tuple<U, Us...> &&o)
: v(std::move(o.v)), r(std::move(o.r)) {}

template <typename U, typename... Us>
requires std::is_constructible_v<T, U &&>
&&std::is_constructible_v<tuple<Ts...>, Us &&...> &&
(!(std::is_same_v<tuple, U> ||
(std::is_same_v<tuple, Us> || ...))) TRACCC_HOST_DEVICE
explicit constexpr tuple(U &&_v, Us &&... _r)
: v(std::forward<U>(_v)),
r(std::forward<Us>(_r)...) {}

constexpr ~tuple() noexcept = default;

constexpr tuple &operator=(const tuple &other) requires(
std::is_copy_assignable_v<T> &&
(std::is_copy_assignable_v<Ts> && ...)) = default;

template <typename U, typename... Us>
TRACCC_HOST_DEVICE constexpr tuple &
operator=(const tuple<U, Us...> &other) requires(
std::is_assignable_v<T &, const U &> &&
(std::is_assignable_v<Ts &, const Us &> && ...)) {
v = other.v;
r = other.r;
return *this;
}

constexpr tuple &operator=(tuple &&other) noexcept
requires(std::is_move_assignable_v<T> &&
(std::is_move_assignable_v<Ts> && ...)) = default;

template <typename U, typename... Us>
TRACCC_HOST_DEVICE constexpr tuple &operator=(
tuple<U, Us...> &&other) requires(std::is_assignable_v<T &, U> &&
(std::is_assignable_v<Ts &, Us> &&
...)) {
v = std::move(other.v);
r = std::move(other.r);
return *this;
}

T v;
tuple<Ts...> r;
};
} // namespace traccc
Loading