From patchwork Sun Jun 16 17:45:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 20345 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 66DE9C32D0 for ; Sun, 16 Jun 2024 17:46:15 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id BDC8F65493; Sun, 16 Jun 2024 19:46:14 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="LT53VQdh"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4157F65489 for ; Sun, 16 Jun 2024 19:46:09 +0200 (CEST) Received: from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi [81.175.209.231]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id BF4652D5; Sun, 16 Jun 2024 19:45:52 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1718559952; bh=NdUij6PJHSPgcDitQ/3pZgzqjn82tJfGLWD7hV0NMHM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LT53VQdhlzQR5PdvAnH9KorP0g6u0dkaBLV+xP7cVFe3r+p0HkPgvI++VaHqu6xQO G7/6aEiofEmtT/BQ4aD/HvUrXn/+MS4T0riHIt2SMAs7lqzq0Ixs2xOTvgYmbH6qaX cg0eWw5EOhdCcAMGrZzQMA1buKsop71HjW+BDvYc= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Cc: Paul Elder Subject: [PATCH v10 4/4] ipa: libipa: vector: Add matrix-vector multiplication Date: Sun, 16 Jun 2024 20:45:41 +0300 Message-ID: <20240616174541.10708-5-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240616174541.10708-1-laurent.pinchart@ideasonboard.com> References: <20240616174541.10708-1-laurent.pinchart@ideasonboard.com> 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" From: Paul Elder Add an operation for multiplying a matrix with a vector. Signed-off-by: Paul Elder Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart Signed-off-by: Laurent Pinchart --- Changes since v3: - Drop unneeded __DOXYGEN__ guard Changes in v3: - make SFINAE more concise Changes in v2: - s/D/Rows/ in Vector class --- src/ipa/libipa/vector.cpp | 11 +++++++++++ src/ipa/libipa/vector.h | 17 +++++++++++++++++ 2 files changed, 28 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..556e0967c869 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 data_; }; +template +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) {