From patchwork Fri Jun 14 12:02:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 20323 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 634A3C3237 for ; Fri, 14 Jun 2024 12:02:27 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9FE6165489; Fri, 14 Jun 2024 14:02:26 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="g25CNozd"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id AC0CF61A2A for ; Fri, 14 Jun 2024 14:02:24 +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 5DD5B2DCE; Fri, 14 Jun 2024 14:02:08 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1718366529; bh=Oo3SY/kBHrwJ+K2H6Szk6oYGSHTyCzT6uJ1Xypilliw=; h=From:To:Cc:Subject:Date:From; b=g25CNozdhPxv+aj9ojeVJQBSIKLfiRrCuEvQYFK1Opjji9TGttanTsX58LfppSHlL jCQOwcmP9qbQCWl6XrYb8UObpxE4OQT2gyCX/JKUTGrEiVjY42mBISCHBI5S2ibMGT MbATpMa6FhouHEqUaZ6SyNKiR90CoMWCM8VUiolQ= From: Paul Elder To: libcamera-devel@lists.libcamera.org Cc: Paul Elder , Kieran Bingham Subject: [PATCH v3] ipa: libipa: vector: Add matrix-vector multiplication Date: Fri, 14 Jun 2024 21:02:11 +0900 Message-Id: <20240614120211.184588-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 Reviewed-by: Laurent Pinchart --- Changes in v3: - make SFINAE more concise Changes in v2: - s/D/Rows/ in Vector class Depends on v9 of "ipa: libipa: Add Matrix class" --- src/ipa/libipa/vector.cpp | 11 +++++++++++ src/ipa/libipa/vector.h | 19 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/ipa/libipa/vector.cpp b/src/ipa/libipa/vector.cpp index b071b261b9c4..bd00b01961d5 100644 --- a/src/ipa/libipa/vector.cpp +++ b/src/ipa/libipa/vector.cpp @@ -123,6 +123,17 @@ 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 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 &lhs, const Vector &rhs) * \brief Compare vectors for equality diff --git a/src/ipa/libipa/vector.h b/src/ipa/libipa/vector.h index 2a2906202ce4..bc7acc9d0a27 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,23 @@ private: std::array data_; }; +#ifndef __DOXYGEN__ +template +#endif /* __DOXYGEN__ */ +Vector operator*(const Matrix &m, const Vector &v) +{ + Vector 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 bool operator==(const Vector &lhs, const Vector &rhs) {