16 #ifndef OPENKALMAN_DETERMINANT_HPP 17 #define OPENKALMAN_DETERMINANT_HPP 24 template<
typename Arg>
25 inline void error_if_argument_to_determinant_is_not_square(
const Arg& arg)
28 throw std::domain_error {
"Argument to 'determinant' is not a square matrix"};
38 template<square_shaped<Applicability::permitted> Arg> requires (max_tensor_order_v<Arg> <= 2)
41 template<
typename Arg, std::enable_if_t<square_shaped<Arg, Applicability::permitted> and (max_tensor_order_v<Arg> <= 2),
int> = 0>
44 determinant(Arg&& arg)
46 using Scalar = scalar_type_of_t<Arg>;
47 constexpr auto ix = []{ if constexpr (dynamic_dimension<Arg, 0>) return 1; else return 0; }();
49 if constexpr (
identity_matrix<Arg> or empty_
object<Arg>)
51 detail::error_if_argument_to_determinant_is_not_square(arg);
52 return values::Fixed<Scalar, 1>{};
54 else if constexpr (dimension_size_of_index_is<Arg, 0, 1> or dimension_size_of_index_is<Arg, 1, 1>)
57 detail::error_if_argument_to_determinant_is_not_square(arg);
58 return
internal::get_singular_component(std::forward<Arg>(arg));
60 else if constexpr (constant_matrix<Arg> and not dynamic_dimension<Arg, ix> and index_dimension_of_v<Arg, ix> >= 2)
62 detail::error_if_argument_to_determinant_is_not_square(arg);
65 else if constexpr (constant_diagonal_matrix<Arg>)
67 detail::error_if_argument_to_determinant_is_not_square(arg);
70 else if constexpr (triangular_matrix<Arg>)
72 detail::error_if_argument_to_determinant_is_not_square(arg);
75 else if constexpr (constant_matrix<Arg>)
78 if (not d)
throw std::invalid_argument{
"Argument of 'determinant' is not a square matrix."};
79 else if (get_dimension(*d) >= 2)
return static_cast<Scalar
>(0);
80 else if (get_dimension(*d) == 1)
return static_cast<Scalar>(internal::get_singular_component(std::forward<Arg>(arg)));
81 else return static_cast<Scalar
>(1);
91 #endif //OPENKALMAN_DETERMINANT_HPP typename scalar_type_of< T >::type scalar_type_of_t
helper template for scalar_type_of.
Definition: scalar_type_of.hpp:54
constexpr auto is_square_shaped(const T &t)
Determine whether an object is square_shaped at runtime.
Definition: is_square_shaped.hpp:63
Definition: tuple_reverse.hpp:103
decltype(auto) constexpr reduce(BinaryFunction &&b, Arg &&arg)
Perform a partial reduction based on an associative binary function, across one or more indices...
Definition: reduce.hpp:143
The root namespace for OpenKalman.
Definition: basics.hpp:34
An interface to various routines from the linear algebra library associated with indexible object T...
Definition: library_interface.hpp:37
The constant associated with T, assuming T is a constant_diagonal_matrix.
Definition: constant_diagonal_coefficient.hpp:32
constexpr auto determinant(Arg &&arg)
Take the determinant of a matrix.
Definition: determinant.hpp:44
decltype(auto) constexpr diagonal_of(Arg &&arg)
Extract a column vector (or column slice for rank>2 tensors) comprising the diagonal elements...
Definition: diagonal_of.hpp:33