Line data Source code
1 : #ifndef ACBE61FE_A7AF_40EC_A62C_B94049A80274
2 : #define ACBE61FE_A7AF_40EC_A62C_B94049A80274
3 :
4 : #include "base/first_include.h" // IWYU pragma: keep
5 : #include "math/linalg/matrix.h" // IWYU pragma: keep
6 : #include "math/linalg/vector.h" // IWYU pragma: keep
7 :
8 : namespace tracking
9 : {
10 : namespace math
11 : {
12 :
13 : /// \brief Non-owning single-column view providing arithmetic operations on Matrix objects
14 : ///
15 : /// MatrixColumnView provides a lightweight, zero-copy interface to access and manipulate
16 : /// a single column of a Matrix. It supports dot product operations and element access
17 : /// without copying data.
18 : ///
19 : /// \tparam ValueType_ The atomic data type of internal elements
20 : /// \tparam Rows_ The number of rows in the source matrix
21 : /// \tparam Cols_ The number of columns in the source matrix
22 : /// \tparam IsRowMajor_ The storage layout of the source matrix (default: true)
23 : ///
24 : /// \note This is a non-owning view - the lifetime of the MatrixColumnView must not exceed
25 : /// the lifetime of the underlying Matrix object.
26 : /// \note All operations are performed in-place on the viewed column.
27 : /// \note Performance: Zero-copy operations, minimal overhead compared to direct matrix access.
28 : ///
29 : /// \see Matrix for the underlying matrix implementation
30 : /// \see MatrixView for rectangular submatrix views
31 : /// \see MatrixRowView for single-row views
32 : template <typename ValueType_, sint32 Rows_, sint32 Cols_, bool IsRowMajor_ = true>
33 : class MatrixColumnView TEST_REMOVE_FINAL
34 : {
35 : public:
36 : /// \brief Construct a single-column view on an existing Matrix
37 : ///
38 : /// Creates a non-owning view of a single column of the given matrix.
39 : /// The view covers rows from rowBegin to rowEnd-1 of the specified column.
40 : ///
41 : /// \param[in] matrix The matrix to view (must outlive the view)
42 : /// \param[in] col Column index to view (0-based)
43 : /// \param[in] rowBegin Starting row index (0-based, default: 0)
44 : /// \param[in] rowEnd Ending row index (0-based, default: Rows_-1)
45 : ///
46 : /// \note The view does not own the data - ensure the matrix lifetime exceeds the view's
47 : /// \note Bounds are not checked at runtime - invalid indices may cause undefined behavior
48 : /// \note For full column views, use rowBegin=0, rowEnd=Rows_-1
49 : explicit MatrixColumnView(const Matrix<ValueType_, Rows_, Cols_, IsRowMajor_>& matrix,
50 : const sint32 col,
51 : const sint32 rowBegin = 0,
52 : const sint32 rowEnd = Rows_ - 1);
53 :
54 : /// \brief Access element at specified row index within the column view
55 : ///
56 : /// \param[in] idx Row index relative to the view (0 to getRowCount()-1)
57 : /// \return The element value
58 : ///
59 : /// \note No bounds checking - invalid indices cause undefined behavior
60 : [[nodiscard]] auto at_unsafe(const sint32 idx) const -> ValueType_;
61 :
62 : /// \brief Compute dot product with a vector
63 : ///
64 : /// Performs dot product: column_view • vector
65 : /// Requires that the view and vector dimensions are compatible.
66 : ///
67 : /// \tparam Rows2_ Size of the vector
68 : /// \param[in] other Vector to multiply with
69 : /// \return Scalar result of the dot product
70 : template <sint32 Rows2_>
71 : [[nodiscard]] auto operator*(const Vector<ValueType_, Rows2_>& other) const -> ValueType_;
72 :
73 : /// \brief Compute dot product with another column view
74 : ///
75 : /// Performs dot product: column_view1 • column_view2
76 : /// Requires that the view dimensions are compatible.
77 : ///
78 : /// \tparam Rows2_ Rows of the other column view
79 : /// \tparam Cols2_ Cols of the other column view
80 : /// \tparam IsRowMajor2_ Storage layout of the other column view
81 : /// \param[in] other Column view to multiply with
82 : /// \return Scalar result of the dot product
83 : template <sint32 Rows2_, sint32 Cols2_, bool IsRowMajor2_>
84 : [[nodiscard]] auto operator*(const MatrixColumnView<ValueType_, Rows2_, Cols2_, IsRowMajor2_>& other) const -> ValueType_;
85 :
86 : // TODO(matthias): add columnView * rowView resulting in a new Matrix
87 :
88 : /// \brief Get the number of rows in this column view
89 : /// \return Number of rows
90 5684 : [[nodiscard]] auto getRowCount() const -> sint32 { return _rowCount; }
91 :
92 :
93 : private:
94 : const Matrix<ValueType_, Rows_, Cols_, IsRowMajor_>& _matrix;
95 : const sint32 _col;
96 : const sint32 _rowBegin;
97 : const sint32 _rowCount;
98 : };
99 :
100 : /// \brief Multiply a matrix by a column view
101 : ///
102 : /// Performs matrix multiplication: mat * colView
103 : /// The result is a vector where each element is the dot product of the corresponding
104 : /// matrix row with the column view.
105 : ///
106 : /// \tparam ValueType_ The atomic data type of internal elements
107 : /// \tparam Rows_ Rows of the matrix
108 : /// \tparam Cols_ Cols of the matrix
109 : /// \tparam IsRowMajor_ Storage layout of the matrix
110 : /// \tparam Rows2_ Rows of the column view
111 : /// \tparam Cols2_ Cols of the column view
112 : /// \tparam IsRowMajor2_ Storage layout of the column view
113 : /// \param[in] mat Matrix to multiply
114 : /// \param[in] colView Column view to multiply with
115 : /// \return Vector result of size Rows_
116 : template <typename ValueType_, sint32 Rows_, sint32 Cols_, bool IsRowMajor_, sint32 Rows2_, sint32 Cols2_, bool IsRowMajor2_>
117 : [[nodiscard]] auto operator*(const Matrix<ValueType_, Rows_, Cols_, IsRowMajor_>& mat,
118 : const MatrixColumnView<ValueType_, Rows2_, Cols2_, IsRowMajor2_>& colView)
119 : -> Vector<ValueType_, Rows_>;
120 :
121 : } // namespace math
122 : } // namespace tracking
123 :
124 : #endif // ACBE61FE_A7AF_40EC_A62C_B94049A80274
|