Line data Source code
1 : #ifndef B83EA5A9_DE89_46DE_A570_E875E0EEFC5C
2 : #define B83EA5A9_DE89_46DE_A570_E875E0EEFC5C
3 :
4 : #include "conversions.h"
5 : #include "math/linalg/matrix_column_view.hpp" // IWYU pragma: keep
6 : #include "math/linalg/vector.hpp" // IWYU pragma: keep
7 :
8 : namespace tracking
9 : {
10 : namespace math
11 : {
12 : namespace conversions
13 : {
14 :
15 : /// \brief Creates a single-column Matrix from a Vector
16 : ///
17 : /// This function converts a Vector into a Matrix with one column, effectively
18 : /// representing the vector as a column matrix. The resulting matrix uses row-major storage.
19 : ///
20 : /// \tparam ValueType_ The atomic data type of internal elements
21 : /// \tparam Size_ The size of the vector and number of rows in the matrix
22 : /// \param[in] vec The source vector to convert
23 : /// \return Matrix with Size_ rows and 1 column containing the vector elements
24 : /// \see VectorFromMatrixColumnView() for the reverse conversion
25 : /// \see MatrixFromList() for creating matrixes from initializer lists
26 : template <typename ValueType_, sint32 Size_>
27 1 : inline auto MatrixFromVector(const Vector<ValueType_, Size_>& vec) -> Matrix<ValueType_, Size_, 1, true>
28 : {
29 1 : Matrix<ValueType_, Size_, 1, true> result{};
30 4 : for (sint32 i = 0; i < Size_; ++i)
31 : {
32 3 : result.at_unsafe(i, 0) = vec.at_unsafe(i);
33 : }
34 1 : return result;
35 : }
36 :
37 :
38 : } // namespace conversions
39 : } // namespace math
40 : } // namespace tracking
41 :
42 : #endif // B83EA5A9_DE89_46DE_A570_E875E0EEFC5C
|