From patchwork Mon Nov 18 22:16:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 21970 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 288C3C32F0 for ; Mon, 18 Nov 2024 22:16:53 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9ACFD65ED9; Mon, 18 Nov 2024 23:16:52 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="XjZcu67r"; 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 DC130658FE for ; Mon, 18 Nov 2024 23:16:41 +0100 (CET) Received: from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi [81.175.209.231]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id D0D056DE for ; Mon, 18 Nov 2024 23:16:24 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1731968185; bh=CfQrts0FGzibO3+YYYZdwluX8ReZ/57VWl/f+nCSqpM=; h=From:To:Subject:Date:In-Reply-To:References:From; b=XjZcu67rNEoqSddSHkX2BUvHfMQKRs8wwesJPNoMLljbsSIRMW9B31rvoBKjGgc8P cW3BbQNtbL4HCdATCvM1jVB5RTMnL89NAYopJTHjki+SeORg9GEp79STtSC00ZhU9G ct8KHTtwJmG+LRYgdZZI5VeniulvslWdY2DdmJKQ= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Subject: [PATCH v3 10/17] ipa: libipa: vector: Add sum() function Date: Tue, 19 Nov 2024 00:16:11 +0200 Message-ID: <20241118221618.13953-11-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241118221618.13953-1-laurent.pinchart@ideasonboard.com> References: <20241118221618.13953-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" Add a function to calculate the sum of a vector. It will be useful for algorithms. Signed-off-by: Laurent Pinchart Reviewed-by: Milan Zamazal --- Changes since v1: - Drop Vector::normalize() --- src/ipa/libipa/vector.cpp | 12 ++++++++++++ src/ipa/libipa/vector.h | 7 +++++++ 2 files changed, 19 insertions(+) diff --git a/src/ipa/libipa/vector.cpp b/src/ipa/libipa/vector.cpp index 56c494a7e4da..a1ad47cd046b 100644 --- a/src/ipa/libipa/vector.cpp +++ b/src/ipa/libipa/vector.cpp @@ -302,6 +302,18 @@ namespace ipa { * \return The length of the vector */ +/** + * \fn Vector::sum() const + * \brief Calculate the sum of all the vector elements + * \tparam R The type of the sum + * + * The type R of the sum defaults to the type T of the elements, but can be set + * explicitly to use a different type in case the type T would risk + * overflowing. + * + * \return The sum of all the vector elements + */ + /** * \fn Vector operator*(const Matrix &m, const Vector &v) * \brief Multiply a matrix by a vector diff --git a/src/ipa/libipa/vector.h b/src/ipa/libipa/vector.h index 3fed9570bf62..564292743829 100644 --- a/src/ipa/libipa/vector.h +++ b/src/ipa/libipa/vector.h @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -251,6 +252,12 @@ public: return std::sqrt(length2()); } + template + constexpr R sum() const + { + return std::accumulate(data_.begin(), data_.end(), R{}); + } + private: static constexpr Vector apply(const Vector &lhs, const Vector &rhs, std::function func) {