1#ifndef PBAT_MATH_LINALG_MINI_DETERMINANT_H
2#define PBAT_MATH_LINALG_MINI_DETERMINANT_H
5#include "pbat/HostDevice.h"
14template <
class TMatrix>
15PBAT_HOST_DEVICE
auto Determinant(TMatrix&& A)
17 using MatrixType = std::remove_cvref_t<TMatrix>;
18 PBAT_MINI_CHECK_CMATRIX(MatrixType);
20 MatrixType::kRows == MatrixType::kCols,
21 "Cannot compute determinant of non-square matrix");
22 static_assert(MatrixType::kRows < 4,
"Determinant of matrix of dimensions >= 4 too costly");
23 if constexpr (MatrixType::kRows == 1)
27 else if constexpr (MatrixType::kRows == 2)
29 return A(0, 0) * A(1, 1) - A(0, 1) * A(1, 0);
31 else if constexpr (MatrixType::kRows == 3)
33 return A(0, 0) * (A(1, 1) * A(2, 2) - A(2, 1) * A(1, 2)) -
34 A(0, 1) * (A(1, 0) * A(2, 2) - A(2, 0) * A(1, 2)) +
35 A(0, 2) * (A(1, 0) * A(2, 1) - A(2, 0) * A(1, 1));
39 using ScalarType =
typename MatrixType::ScalarType;
40 return ScalarType{0.};
Mini linear algebra related functionality.
Definition Assign.h:12
Linear Algebra related functionality.
Definition FilterEigenvalues.h:7
Math related functionality.
Definition Concepts.h:19
The main namespace of the library.
Definition Aliases.h:15