diff options
author | Paul Elder <paul.elder@ideasonboard.com> | 2024-06-14 21:02:11 +0900 |
---|---|---|
committer | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2024-06-17 12:19:01 +0300 |
commit | 01a33fedf6cdbb99c2b0316462a5578bb1b4b434 (patch) | |
tree | 628dc667ff92648f401966b0c2b01db0382d6736 /src/ipa/libipa/vector.h | |
parent | cbfdfa42cacc0c9b83abb604e19febaf505cf24f (diff) |
ipa: libipa: vector: Add matrix-vector multiplication
Add an operation for multiplying a matrix with a vector.
Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Diffstat (limited to 'src/ipa/libipa/vector.h')
-rw-r--r-- | src/ipa/libipa/vector.h | 17 |
1 files changed, 17 insertions, 0 deletions
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) { |