-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Add new concepts for Eigen types (#3966)
This commit adds several new concepts for dealing with Eigen base types. The motivation for this is superficially to simplify some of the requirements in the track state proxy and the multi-trajectory, but it also allows me to more easily deal with some clang compiler warnings seen in #3949, as clang won't let me compare `A::ColsAtCompileTime` and `B::ColsAtCompileTime` if `A` and `B` are different types; this allows me to hide the conversion to integers inside a concept. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Introduced new concepts for Eigen matrix types to enhance type safety and clarity in the `TrackStateProxy` and `VectorMultiTrajectory` classes. - Updated method signatures in both classes to utilize these concepts for improved parameter validation. - **Bug Fixes** - Enhanced error handling logic in the `allocateCalibrated_impl` method to ensure consistent exception messaging. - **Documentation** - Added a new header file defining several concepts related to Eigen dense matrix types, improving code expressiveness and type-checking capabilities. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
- Loading branch information
1 parent
87439ad
commit 26273bc
Showing
3 changed files
with
68 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
/// @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 |