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

refactor: Add new concepts for Eigen types #3966

Merged
merged 3 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 6 additions & 6 deletions Core/include/Acts/EventData/TrackStateProxy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "Acts/EventData/TrackStateType.hpp"
#include "Acts/EventData/Types.hpp"
#include "Acts/Surfaces/Surface.hpp"
#include "Acts/Utilities/EigenConcepts.hpp"
#include "Acts/Utilities/HashedString.hpp"
#include "Acts/Utilities/Helpers.hpp"

Expand Down Expand Up @@ -782,12 +783,11 @@ class TrackStateProxy {
template <typename val_t, typename cov_t>
void allocateCalibrated(const Eigen::DenseBase<val_t>& val,
const Eigen::DenseBase<cov_t>& cov)
requires(Eigen::PlainObjectBase<val_t>::RowsAtCompileTime > 0 &&
Eigen::PlainObjectBase<val_t>::RowsAtCompileTime <= eBoundSize &&
Eigen::PlainObjectBase<val_t>::RowsAtCompileTime ==
Eigen::PlainObjectBase<cov_t>::RowsAtCompileTime &&
Eigen::PlainObjectBase<cov_t>::RowsAtCompileTime ==
Eigen::PlainObjectBase<cov_t>::ColsAtCompileTime)
requires(Concepts::eigen_base_is_fixed_size<val_t> &&
Concepts::eigen_bases_have_same_num_rows<val_t, cov_t> &&
Concepts::eigen_base_is_square<cov_t> &&
Eigen::PlainObjectBase<val_t>::RowsAtCompileTime <=
static_cast<std::underlying_type_t<BoundIndices>>(eBoundSize))
paulgessinger marked this conversation as resolved.
Show resolved Hide resolved
{
m_traj->template allocateCalibrated<
Eigen::PlainObjectBase<val_t>::RowsAtCompileTime>(m_istate, val, cov);
Expand Down
13 changes: 6 additions & 7 deletions Core/include/Acts/EventData/VectorMultiTrajectory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "Acts/EventData/Types.hpp"
#include "Acts/EventData/detail/DynamicColumn.hpp"
#include "Acts/EventData/detail/DynamicKeyIterator.hpp"
#include "Acts/Utilities/EigenConcepts.hpp"
#include "Acts/Utilities/HashedString.hpp"
#include "Acts/Utilities/Helpers.hpp"
#include "Acts/Utilities/ThrowAssert.hpp"
Expand Down Expand Up @@ -495,13 +496,11 @@ class VectorMultiTrajectory final
void allocateCalibrated_impl(IndexType istate,
const Eigen::DenseBase<val_t>& val,
const Eigen::DenseBase<cov_t>& cov)

requires(Eigen::PlainObjectBase<val_t>::RowsAtCompileTime > 0 &&
Eigen::PlainObjectBase<val_t>::RowsAtCompileTime <= eBoundSize &&
Eigen::PlainObjectBase<val_t>::RowsAtCompileTime ==
Eigen::PlainObjectBase<cov_t>::RowsAtCompileTime &&
Eigen::PlainObjectBase<cov_t>::RowsAtCompileTime ==
Eigen::PlainObjectBase<cov_t>::ColsAtCompileTime)
requires(Concepts::eigen_base_is_fixed_size<val_t> &&
Concepts::eigen_bases_have_same_num_rows<val_t, cov_t> &&
Concepts::eigen_base_is_square<cov_t> &&
Eigen::PlainObjectBase<val_t>::RowsAtCompileTime <=
static_cast<std::underlying_type_t<BoundIndices>>(eBoundSize))
{
constexpr std::size_t measdim = val_t::RowsAtCompileTime;

Expand Down
56 changes: 56 additions & 0 deletions Core/include/Acts/Utilities/EigenConcepts.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// This file is part of the ACTS project.
//
// Copyright (C) 2016 CERN for the benefit of the ACTS project
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

#pragma once

#include <Eigen/Dense>

namespace Acts::Concepts {
/// @brief Concept that is true iff T is a valid Eigen dense base.
template <typename T>
concept is_eigen_base = requires {
{ T::RowsAtCompileTime };
{ T::ColsAtCompileTime };
};

/// @brief Concept that is true iff T is a valid Eigen dense base with fixed
/// size.
template <typename T>
concept eigen_base_is_fixed_size =
is_eigen_base<T> && Eigen::PlainObjectBase<T>::RowsAtCompileTime > 0 &&
Eigen::PlainObjectBase<T>::ColsAtCompileTime > 0;

/// @brief Concept that is true iff T is a valid Eigen dense base with fixed,
/// square size.
template <typename T>
concept eigen_base_is_square = eigen_base_is_fixed_size<T> &&
Eigen::PlainObjectBase<T>::RowsAtCompileTime ==
Eigen::PlainObjectBase<T>::ColsAtCompileTime;

/// @brief Concept that is true iff T1 and T2 have the same, known at compile
/// time, number of rows.
template <typename T1, typename T2>
concept eigen_bases_have_same_num_rows =
eigen_base_is_fixed_size<T1> && eigen_base_is_fixed_size<T2> &&
static_cast<std::size_t>(Eigen::PlainObjectBase<T1>::RowsAtCompileTime) ==
static_cast<std::size_t>(Eigen::PlainObjectBase<T2>::RowsAtCompileTime);

/// @brief Concept that is true iff T1 and T2 have the same, known at compile
/// time, number of columns.
template <typename T1, typename T2>
concept eigen_bases_have_same_num_cols =
eigen_base_is_fixed_size<T1> && eigen_base_is_fixed_size<T2> &&
static_cast<std::size_t>(Eigen::PlainObjectBase<T1>::ColsAtCompileTime) ==
static_cast<std::size_t>(Eigen::PlainObjectBase<T2>::ColsAtCompileTime);
paulgessinger marked this conversation as resolved.
Show resolved Hide resolved

/// @brief Concept that is true iff T1 and T2 have the same, known at compile
/// time, size.
template <typename T1, typename T2>
concept eigen_bases_have_same_size = eigen_bases_have_same_num_rows<T1, T2> &&
eigen_bases_have_same_num_cols<T1, T2>;
} // namespace Acts::Concepts
Loading