ACTS
Experiment-independent tracking
Loading...
Searching...
No Matches
eigen_matrix.hpp
1// This file is part of the ACTS project.
2//
3// Copyright (C) 2016 CERN for the benefit of the ACTS project
4//
5// This Source Code Form is subject to the terms of the Mozilla Public
6// License, v. 2.0. If a copy of the MPL was not distributed with this
7// file, You can obtain one at https://mozilla.org/MPL/2.0/.
8
9#pragma once
10
11// Project include(s).
12#include "algebra/impl/eigen_types.hpp"
13#include "detray/algebra/concepts.hpp"
14#include "detray/definitions/detail/qualifiers.hpp"
15
16// Eigen include(s).
17#ifdef _MSC_VER
18#pragma warning(push, 0)
19#endif // MSVC
20#ifdef __NVCC_DIAG_PRAGMA_SUPPORT__
21#pragma nv_diagnostic push
22#pragma nv_diag_suppress 20012
23#endif // __NVCC_DIAG_PRAGMA_SUPPORT__
24#include <Eigen/Cholesky>
25#include <Eigen/Core>
26#ifdef _MSC_VER
27#pragma warning(pop)
28#endif // MSVC
29#ifdef __NVCC_DIAG_PRAGMA_SUPPORT__
30#pragma nv_diagnostic pop
31#endif // __NVCC_DIAG_PRAGMA_SUPPORT__
32
33namespace detray::algebra::eigen::math {
34
36template <concepts::matrix matrix_t>
37DETRAY_HOST_DEVICE constexpr matrix_t zero() {
38 return matrix_t::Zero();
39}
40
42template <concepts::matrix matrix_t>
43DETRAY_HOST_DEVICE constexpr matrix_t identity() {
44 return matrix_t::Identity();
45}
46
48template <typename derived_type>
49DETRAY_HOST_DEVICE constexpr void set_zero(Eigen::MatrixBase<derived_type> &m) {
50 m.setZero();
51}
52
54template <typename derived_type>
55DETRAY_HOST_DEVICE constexpr void set_identity(
56 Eigen::MatrixBase<derived_type> &m) {
57 m.setIdentity();
58}
59
61template <typename derived_type>
62DETRAY_HOST_DEVICE constexpr matrix_type<
63 typename Eigen::MatrixBase<derived_type>::value_type,
64 Eigen::MatrixBase<derived_type>::ColsAtCompileTime,
65 Eigen::MatrixBase<derived_type>::RowsAtCompileTime>
66transpose(const Eigen::MatrixBase<derived_type> &m) {
67 return m.transpose();
68}
69
71template <typename derived_type_1, typename derived_type_2>
72 requires(Eigen::MatrixBase<derived_type_2>::RowsAtCompileTime == 3)
73DETRAY_HOST_DEVICE constexpr matrix_type<
74 typename Eigen::MatrixBase<derived_type_1>::value_type,
75 Eigen::MatrixBase<derived_type_1>::RowsAtCompileTime,
76 Eigen::MatrixBase<derived_type_1>::ColsAtCompileTime>
77column_wise_cross(const Eigen::MatrixBase<derived_type_1> &m,
78 const Eigen::MatrixBase<derived_type_2> &v) {
79 return m.colwise().cross(v);
80}
81
83template <typename derived_type_1, typename derived_type_2>
84 requires(Eigen::MatrixBase<derived_type_1>::RowsAtCompileTime ==
85 Eigen::MatrixBase<derived_type_2>::RowsAtCompileTime)
86DETRAY_HOST_DEVICE constexpr matrix_type<
87 typename Eigen::MatrixBase<derived_type_1>::value_type,
88 Eigen::MatrixBase<derived_type_1>::RowsAtCompileTime,
89 Eigen::MatrixBase<derived_type_1>::ColsAtCompileTime>
90column_wise_multiply(const Eigen::MatrixBase<derived_type_1> &m,
91 const Eigen::MatrixBase<derived_type_2> &v) {
92 return m.array().colwise() * v.array();
93}
94
96template <typename derived_type_1, typename derived_type_2>
97 requires(Eigen::MatrixBase<derived_type_1>::RowsAtCompileTime ==
98 Eigen::MatrixBase<derived_type_2>::RowsAtCompileTime)
99DETRAY_HOST_DEVICE constexpr matrix_type<
100 typename Eigen::MatrixBase<derived_type_1>::value_type,
101 Eigen::MatrixBase<derived_type_1>::RowsAtCompileTime,
102 Eigen::MatrixBase<derived_type_1>::RowsAtCompileTime>
103outer_product(const Eigen::MatrixBase<derived_type_1> &a,
104 const Eigen::MatrixBase<derived_type_2> &b) {
105 return a * b.transpose();
106}
107
109template <typename derived_type>
110DETRAY_HOST_DEVICE constexpr
111 typename Eigen::MatrixBase<derived_type>::value_type
112 determinant(const Eigen::MatrixBase<derived_type> &m) {
113 return m.determinant();
114}
115
117template <typename derived_type>
118DETRAY_HOST_DEVICE constexpr matrix_type<
119 typename Eigen::MatrixBase<derived_type>::value_type,
120 Eigen::MatrixBase<derived_type>::RowsAtCompileTime,
121 Eigen::MatrixBase<derived_type>::ColsAtCompileTime>
122inverse(const Eigen::MatrixBase<derived_type> &m) {
123 return m.inverse();
124}
125
127template <typename derived_type>
128DETRAY_HOST_DEVICE constexpr matrix_type<
129 typename Eigen::MatrixBase<derived_type>::value_type,
130 Eigen::MatrixBase<derived_type>::RowsAtCompileTime,
131 Eigen::MatrixBase<derived_type>::ColsAtCompileTime>
132cholesky_decomposition(const Eigen::MatrixBase<derived_type> &m) {
133 Eigen::LLT<derived_type> LL_T(m);
134 return LL_T.matrixL();
135}
136
137} // namespace detray::algebra::eigen::math
constexpr double m
Meter.
Definition Units.hpp:97