Line data Source code
1 : #ifndef C21D598C_CF10_4BAC_8857_B0DA4A653638
2 : #define C21D598C_CF10_4BAC_8857_B0DA4A653638
3 :
4 : #include "conversions.h"
5 : #include "math/linalg/diagonal_matrix.hpp" // IWYU pragma: keep
6 : #include "math/linalg/square_matrix.hpp" // IWYU pragma: keep
7 :
8 : namespace tracking
9 : {
10 : namespace math
11 : {
12 : namespace conversions
13 : {
14 :
15 : /// \brief Creates a SquareMatrix from a DiagonalMatrix
16 : ///
17 : /// This function creates a square matrix with the diagonal elements from a diagonal matrix.
18 : /// All off-diagonal elements are set to zero.
19 : ///
20 : /// \tparam ValueType_ The atomic data type of internal elements
21 : /// \tparam Size_ The dimension of the matrixes
22 : /// \tparam IsRowMajor_ The storage layout of the resulting square matrix
23 : /// \param[in] diag The source diagonal matrix
24 : /// \return SquareMatrix with diagonal elements from the input and zeros elsewhere
25 : /// \see DiagonalFromSquare() for the reverse conversion
26 : /// \see SquareFromList() for creating from initializer lists
27 : template <typename ValueType_, sint32 Size_, bool IsRowMajor_>
28 2 : inline auto SquareFromDiagonal(const DiagonalMatrix<ValueType_, Size_>& diag) -> SquareMatrix<ValueType_, Size_, IsRowMajor_>
29 : {
30 2 : SquareMatrix<ValueType_, Size_, IsRowMajor_> result{};
31 8 : for (sint32 i = 0; i < Size_; ++i)
32 : {
33 6 : result.at_unsafe(i, i) = diag.at_unsafe(i);
34 : }
35 2 : return result;
36 : }
37 :
38 : } // namespace conversions
39 : } // namespace math
40 : } // namespace tracking
41 :
42 : #endif // C21D598C_CF10_4BAC_8857_B0DA4A653638
|