summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ipa/libipa/vector.cpp11
-rw-r--r--src/ipa/libipa/vector.h17
2 files changed, 28 insertions, 0 deletions
diff --git a/src/ipa/libipa/vector.cpp b/src/ipa/libipa/vector.cpp
index b071b261..bd00b019 100644
--- a/src/ipa/libipa/vector.cpp
+++ b/src/ipa/libipa/vector.cpp
@@ -124,6 +124,17 @@ namespace ipa {
*/
/**
+ * \fn Vector<T, Rows> operator*(const Matrix<T, Rows, Cols> &m, const Vector<T, Cols> &v)
+ * \brief Multiply a matrix by a vector
+ * \tparam T Numerical type of the contents of the matrix and vector
+ * \tparam Rows The number of rows in the matrix
+ * \tparam Cols The number of columns in the matrix (= rows in the vector)
+ * \param m The matrix
+ * \param v The vector
+ * \return Product of matrix \a m and vector \a v
+ */
+
+/**
* \fn bool operator==(const Vector<T, Rows> &lhs, const Vector<T, Rows> &rhs)
* \brief Compare vectors for equality
* \return True if the two vectors are equal, false otherwise
diff --git a/src/ipa/libipa/vector.h b/src/ipa/libipa/vector.h
index 2a290620..556e0967 100644
--- a/src/ipa/libipa/vector.h
+++ b/src/ipa/libipa/vector.h
@@ -16,6 +16,8 @@
#include "libcamera/internal/yaml_parser.h"
+#include "matrix.h"
+
namespace libcamera {
LOG_DECLARE_CATEGORY(Vector)
@@ -140,6 +142,21 @@ private:
std::array<T, Rows> data_;
};
+template<typename T, unsigned int Rows, unsigned int Cols>
+Vector<T, Rows> operator*(const Matrix<T, Rows, Cols> &m, const Vector<T, Cols> &v)
+{
+ Vector<T, Rows> result;
+
+ for (unsigned int i = 0; i < Rows; i++) {
+ T sum = 0;
+ for (unsigned int j = 0; j < Cols; j++)
+ sum += m[i][j] * v[j];
+ result[i] = sum;
+ }
+
+ return result;
+}
+
template<typename T, unsigned int Rows>
bool operator==(const Vector<T, Rows> &lhs, const Vector<T, Rows> &rhs)
{