{"id":22008,"url":"https://patchwork.libcamera.org/api/patches/22008/?format=json","web_url":"https://patchwork.libcamera.org/patch/22008/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20241119121928.30939-11-laurent.pinchart@ideasonboard.com>","date":"2024-11-19T12:19:21","name":"[v4,10/17] ipa: libipa: vector: Add sum() function","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"b454db273f3a76b338a95de66a1c43e4e6625bd4","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/?format=json","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/22008/mbox/","series":[{"id":4804,"url":"https://patchwork.libcamera.org/api/series/4804/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=4804","date":"2024-11-19T12:19:11","name":"Improve linear algebra helpers in libipa","version":4,"mbox":"https://patchwork.libcamera.org/series/4804/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/22008/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/22008/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id B0F1FC32F5\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 19 Nov 2024 12:20:14 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 50D5E65F31;\n\tTue, 19 Nov 2024 13:20:14 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id AB4D465F26\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 19 Nov 2024 13:20:09 +0100 (CET)","from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi\n\t[81.175.209.231])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id F0847193C\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 19 Nov 2024 13:19:51 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"kP/uo0AF\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1732018792;\n\tbh=M/q/1RT8aY2M8BXgSR8MxOcsLqh14yKK7f9h/QkUSdo=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=kP/uo0AF+ZSxFBDOxC7qjeskf2CP1R/Z+lEQSGQBjXORYqXIYTMHtXKTuZtYgRK91\n\t56Q6ZoIsZUwnH3FP4zwOMpfkMjZg17ZjCjBegjbaFho1y011Dj4W90RSsu0+s7DvIA\n\typyMG/te50w4nKfDm5+Di0ql5GucrDyILcN+4FqM=","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","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","Content-Transfer-Encoding":"8bit","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Add a function to calculate the sum of a vector. It will be useful for\nalgorithms.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\nReviewed-by: Milan Zamazal <mzamazal@redhat.com>\n---\nChanges since v1:\n\n- Drop Vector::normalize()\n---\n src/ipa/libipa/vector.cpp | 12 ++++++++++++\n src/ipa/libipa/vector.h   |  7 +++++++\n 2 files changed, 19 insertions(+)","diff":"diff --git a/src/ipa/libipa/vector.cpp b/src/ipa/libipa/vector.cpp\nindex a506487c7b43..d6e25e3e722d 100644\n--- a/src/ipa/libipa/vector.cpp\n+++ b/src/ipa/libipa/vector.cpp\n@@ -302,6 +302,18 @@ namespace ipa {\n  * \\return The length of the vector\n  */\n \n+/**\n+ * \\fn Vector::sum() const\n+ * \\brief Calculate the sum of all the vector elements\n+ * \\tparam R The type of the sum\n+ *\n+ * The type R of the sum defaults to the type T of the elements, but can be set\n+ * explicitly to use a different type in case the type T would risk\n+ * overflowing.\n+ *\n+ * \\return The sum of all the vector elements\n+ */\n+\n /**\n  * \\fn Vector<T, Rows> operator*(const Matrix<T, Rows, Cols> &m, const Vector<T, Cols> &v)\n  * \\brief Multiply a matrix by a vector\ndiff --git a/src/ipa/libipa/vector.h b/src/ipa/libipa/vector.h\nindex 85b7f6ee68a7..5a2a29b53441 100644\n--- a/src/ipa/libipa/vector.h\n+++ b/src/ipa/libipa/vector.h\n@@ -10,6 +10,7 @@\n #include <array>\n #include <cmath>\n #include <functional>\n+#include <numeric>\n #include <optional>\n #include <ostream>\n \n@@ -243,6 +244,12 @@ public:\n \t\treturn std::sqrt(length2());\n \t}\n \n+\ttemplate<typename R = T>\n+\tconstexpr R sum() const\n+\t{\n+\t\treturn std::accumulate(data_.begin(), data_.end(), R{});\n+\t}\n+\n private:\n \ttemplate<class BinaryOp>\n \tstatic constexpr Vector apply(const Vector &lhs, const Vector &rhs, BinaryOp op)\n","prefixes":["v4","10/17"]}