From patchwork Fri Jun 7 08:20:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 20237 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 2AA4AC31E9 for ; Fri, 7 Jun 2024 08:20:57 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id CF3596545E; Fri, 7 Jun 2024 10:20:55 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="MmAt+OQZ"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6BEA365457 for ; Fri, 7 Jun 2024 10:20:54 +0200 (CEST) Received: from neptunite.hamster-moth.ts.net (h175-177-049-156.catv02.itscom.jp [175.177.49.156]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id B674029F; Fri, 7 Jun 2024 10:20:43 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1717748444; bh=JTlitEFtVtIy9IiWSvD7xcGZkoadTjGxPdtsT43+Uts=; h=From:To:Cc:Subject:Date:From; b=MmAt+OQZyJPGRveiVqrvanLBgyfwhdpa1YAGiKA11xwzv+/u4+EVR8F19WH9rzGdT RgFPifcIWvTFXXvW3/gbkQFSqMUcHWmUeMUoJPcjHzN+WI7ccdt+kUEiC1qi81dxz9 S93OK9uAan6Pn4Hlh9+WAxyOmFOun3gAFmtWzCwI= From: Paul Elder To: libcamera-devel@lists.libcamera.org Cc: Paul Elder Subject: [PATCH] ipa: libipa: vector: Add matrix-vector multiplication Date: Fri, 7 Jun 2024 17:20:45 +0900 Message-Id: <20240607082045.2718555-1-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add an operation for multiplying a matrix with a vector. Signed-off-by: Paul Elder Reviewed-by: Kieran Bingham --- Depends on v6 of "ipa: libipa: Add Matrix class" and v5 of "ipa: libipa: Add Vector class" --- src/ipa/libipa/vector.cpp | 12 ++++++++++++ src/ipa/libipa/vector.h | 22 ++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/src/ipa/libipa/vector.cpp b/src/ipa/libipa/vector.cpp index bdc3c447c..e18426fe5 100644 --- a/src/ipa/libipa/vector.cpp +++ b/src/ipa/libipa/vector.cpp @@ -145,6 +145,18 @@ namespace ipa { * \return The length of the vector */ +/** + * \fn Vector operator*(const Matrix &m, const Vector &v) + * \brief Multiply a matrix by a vector + * \tparam T Numerical type of the contents of the matrix and vector + * \tparam R1 The number of rows in the matrix + * \tparam C1 The number of colums in the matrix + * \tparam R2 The number of elements 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 &lhs, const Vector &rhs) * \brief Compare vectors for equality diff --git a/src/ipa/libipa/vector.h b/src/ipa/libipa/vector.h index 87aad28b5..934b44494 100644 --- a/src/ipa/libipa/vector.h +++ b/src/ipa/libipa/vector.h @@ -17,6 +17,8 @@ #include "libcamera/internal/yaml_parser.h" +#include "matrix.h" + namespace libcamera { LOG_DECLARE_CATEGORY(Vector) @@ -166,6 +168,26 @@ private: std::array data_; }; +#ifndef __DOXYGEN__ +template && C1 == R2> * = nullptr> +#endif /* __DOXYGEN__ */ +Vector operator*(const Matrix &m, const Vector &v) +{ + Vector result; + + for (unsigned int i = 0; i < R1; i++) { + T sum = 0; + for (unsigned int j = 0; j < C1; j++) + sum += m[i][j] * v[j]; + result[i] = sum; + } + + return result; +} + #ifndef __DOXYGEN__ template> * = nullptr>