From patchwork Tue Nov 19 12:19:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 22008 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 B0F1FC32F5 for ; Tue, 19 Nov 2024 12:20:14 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 50D5E65F31; Tue, 19 Nov 2024 13:20:14 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="kP/uo0AF"; 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 AB4D465F26 for ; Tue, 19 Nov 2024 13:20:09 +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 F0847193C for ; Tue, 19 Nov 2024 13:19:51 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1732018792; bh=M/q/1RT8aY2M8BXgSR8MxOcsLqh14yKK7f9h/QkUSdo=; h=From:To:Subject:Date:In-Reply-To:References:From; b=kP/uo0AF+ZSxFBDOxC7qjeskf2CP1R/Z+lEQSGQBjXORYqXIYTMHtXKTuZtYgRK91 56Q6ZoIsZUwnH3FP4zwOMpfkMjZg17ZjCjBegjbaFho1y011Dj4W90RSsu0+s7DvIA ypyMG/te50w4nKfDm5+Di0ql5GucrDyILcN+4FqM= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Subject: [PATCH v4 10/17] ipa: libipa: vector: Add sum() function Date: Tue, 19 Nov 2024 14:19:21 +0200 Message-ID: <20241119121928.30939-11-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241119121928.30939-1-laurent.pinchart@ideasonboard.com> References: <20241119121928.30939-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 a506487c7b43..d6e25e3e722d 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 85b7f6ee68a7..5a2a29b53441 100644 --- a/src/ipa/libipa/vector.h +++ b/src/ipa/libipa/vector.h @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -243,6 +244,12 @@ public: return std::sqrt(length2()); } + template + constexpr R sum() const + { + return std::accumulate(data_.begin(), data_.end(), R{}); + } + private: template static constexpr Vector apply(const Vector &lhs, const Vector &rhs, BinaryOp op)