ACTS
Experiment-independent tracking
Loading...
Searching...
No Matches
partial_pivot_lud.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 "detray/algebra/concepts.hpp"
13#include "detray/algebra/generic/algorithms/matrix/decomposition/partial_pivot_lud.hpp"
14#include "detray/algebra/type_traits.hpp"
15#include "detray/definitions/detail/qualifiers.hpp"
16
17namespace detray::algebra::generic::matrix::determinant {
18
20template <concepts::square_matrix matrix_t>
23 using scalar_t = detray::traits::value_t<matrix_t>;
25 using index_t = detray::traits::index_t<matrix_t>;
26
28 using element_getter_t = detray::traits::element_getter_t<matrix_t>;
29
33 matrix_t>;
34
38 DETRAY_HOST_DEVICE constexpr scalar_t operator()(const matrix_t& m) const {
39 constexpr element_getter_t elem{};
40 constexpr index_t N{detray::traits::max_rank<matrix_t>};
41
42 const typename decomposition_t::template lud<
43 detray::traits::max_rank<matrix_t>>
44 decomp_res = decomposition_t()(m);
45
46 // Get the LU decomposition matrix equal to (L - I) + U
47 const auto& lu = decomp_res.lu;
48 const auto n_pivot = static_cast<index_t>(decomp_res.n_pivot);
49
50 scalar_t det = elem(lu, 0, 0);
51
52 for (index_t i = 1; i < N; i++) {
53 det *= elem(lu, i, i);
54 }
55
56 return (n_pivot - N) % 2 == 0 ? det : -det;
57 }
58};
59
60} // namespace detray::algebra::generic::matrix::determinant
"Partial Pivot LU Decomposition", assuming a N X N matrix
Definition partial_pivot_lud.hpp:23
Compute a determinant from an LU decomposition with partial pivoting.
Definition partial_pivot_lud.hpp:21
detray::traits::element_getter_t< matrix_t > element_getter_t
Function (object) used for accessing a matrix element.
Definition partial_pivot_lud.hpp:28
constexpr scalar_t operator()(const matrix_t &m) const
Compute the determinant as the signed product of LU diagonal entries.
Definition partial_pivot_lud.hpp:38
typename algebra::generic::matrix::decomposition::partial_pivot_lud< matrix_t > decomposition_t
LU decomposition implementation used to factor the matrix.
Definition partial_pivot_lud.hpp:31
detray::traits::index_t< matrix_t > index_t
Matrix index type.
Definition partial_pivot_lud.hpp:25
detray::traits::value_t< matrix_t > scalar_t
Matrix element type.
Definition partial_pivot_lud.hpp:23