12#include "detray/algebra/concepts.hpp"
13#include "detray/algebra/generic/algorithms/matrix/determinant/cofactor.hpp"
14#include "detray/algebra/type_traits.hpp"
15#include "detray/definitions/detail/qualifiers.hpp"
21namespace detray::algebra::generic::matrix {
26template <concepts::square_matrix matrix_t>
34 DETRAY_HOST_DEVICE
constexpr matrix_t
operator()(
const matrix_t &m)
const {
39 template <index_type N>
43 template <index_type N>
49 const matrix_t & )
const {
50 using element_getter_t = detray::traits::element_getter_t<matrix_t>;
51 constexpr element_getter_t elem{};
61 template <index_type N>
63 struct adjoint_getter_helper<N> {
70 DETRAY_HOST_DEVICE
constexpr matrix_t
operator()(
const matrix_t &m)
const {
71 using index_t = detray::traits::index_t<matrix_t>;
72 using element_getter_t = detray::traits::element_getter_t<matrix_t>;
73 constexpr element_getter_t elem{};
81 for (index_t i = 0; i < N; i++) {
82 for (index_t j = 0; j < N; j++) {
84 typename determinant_getter::template determinant_getter_helper<N>()
85 .get_cofactor(m, temp, i, j);
89 sign = ((i + j) % 2 == 0) ? 1 : -1;
95 typename determinant_getter::template determinant_getter_helper<
110template <concepts::square_matrix matrix_t>
113 using scalar_t = detray::traits::value_t<matrix_t>;
115 using index_t = detray::traits::index_t<matrix_t>;
127 DETRAY_HOST_DEVICE
constexpr matrix_t
operator()(
const matrix_t &m)
const {
129 constexpr index_t N{detray::traits::max_rank<matrix_t>};
138 assert(
false &&
"Singular matrix during inversion (cofactor)");
145 for (
index_t i = 0; i < N; i++) {
146 for (
index_t j = 0; j < N; j++) {
147 elem(ret, j, i) = elem(adj, j, i) / det;
determinant::cofactor< matrix_t > determinant_getter
Determinant implementation used to evaluate each minor.
Definition cofactor.hpp:65
constexpr matrix_t operator()(const matrix_t &) const
Return the one-element identity matrix, the adjugate in rank one.
Definition cofactor.hpp:48
constexpr matrix_t operator()(const matrix_t &m) const
Form the adjugate by computing signed minors and transposing them.
Definition cofactor.hpp:70
Helper that computes the adjugate for a fixed matrix rank.
Definition cofactor.hpp:40
"Adjoint getter", assuming a N X N matrix
Definition cofactor.hpp:27
constexpr matrix_t operator()(const matrix_t &m) const
Return the adjugate of a square matrix.
Definition cofactor.hpp:34
detray::traits::index_t< matrix_t > index_type
Index type used to traverse matrix rows and columns.
Definition cofactor.hpp:29
"Determinant getter", assuming a N X N matrix
Definition cofactor.hpp:23
"inverse getter", assuming a N X N matrix
Definition cofactor.hpp:111
detray::traits::index_t< matrix_t > index_t
Index type used to traverse matrix rows and columns.
Definition cofactor.hpp:115
constexpr matrix_t operator()(const matrix_t &m) const
Invert a nonsingular square matrix.
Definition cofactor.hpp:127
detray::traits::value_t< matrix_t > scalar_t
Scalar type of matrix elements.
Definition cofactor.hpp:113
detray::traits::element_getter_t< matrix_t > element_getter_t
Function (object) used for accessing a matrix element.
Definition cofactor.hpp:118
adjoint::cofactor< matrix_t > adjoint_getter
Adjugate implementation used in the inverse formula.
Definition cofactor.hpp:122
determinant::cofactor< matrix_t > determinant_getter
Cofactor-expansion determinant implementation.
Definition cofactor.hpp:120