[{"id":32228,"web_url":"https://patchwork.libcamera.org/comment/32228/","msgid":"<87ikskhcje.fsf@redhat.com>","date":"2024-11-18T13:55:17","subject":"Re: [RFC PATCH v2 09/12] ipa: libipa: vector: Add sum() function","submitter":{"id":177,"url":"https://patchwork.libcamera.org/api/people/177/","name":"Milan Zamazal","email":"mzamazal@redhat.com"},"content":"Laurent Pinchart <laurent.pinchart@ideasonboard.com> writes:\n\n> Add a function to calculate the sum of a vector. It will be useful for\n> algorithms.\n>\n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nReviewed-by: Milan Zamazal <mzamazal@redhat.com>\n\n> ---\n> Changes 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(+)\n>\n> diff --git a/src/ipa/libipa/vector.cpp b/src/ipa/libipa/vector.cpp\n> index 14816cdb5d09..19e7537f8a5a 100644\n> --- a/src/ipa/libipa/vector.cpp\n> +++ b/src/ipa/libipa/vector.cpp\n> @@ -296,6 +296,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\n> diff --git a/src/ipa/libipa/vector.h b/src/ipa/libipa/vector.h\n> index 949dc4650aa4..f55da6476103 100644\n> --- a/src/ipa/libipa/vector.h\n> +++ b/src/ipa/libipa/vector.h\n> @@ -9,6 +9,7 @@\n>  #include <algorithm>\n>  #include <array>\n>  #include <cmath>\n> +#include <numeric>\n>  #include <optional>\n>  #include <ostream>\n>  \n> @@ -245,6 +246,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>  \tstatic constexpr Vector apply(const Vector &lhs, const Vector &rhs, std::function<T(T, T)> func)\n>  \t{","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 165ECC32DD\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 18 Nov 2024 13:55:31 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 9AB61658DC;\n\tMon, 18 Nov 2024 14:55:30 +0100 (CET)","from us-smtp-delivery-124.mimecast.com\n\t(us-smtp-delivery-124.mimecast.com [170.10.133.124])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 463B660532\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 18 Nov 2024 14:55:29 +0100 (CET)","from mail-wm1-f70.google.com (mail-wm1-f70.google.com\n\t[209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS\n\t(version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id\n\tus-mta-160--3iMm_wUMDWsw6DvjYkv1g-1; Mon, 18 Nov 2024 08:55:26 -0500","by mail-wm1-f70.google.com with SMTP id\n\t5b1f17b1804b1-432d04b3d40so26798935e9.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 18 Nov 2024 05:55:26 -0800 (PST)","from nuthatch ([2a00:102a:400a:489a:ffe9:aa41:63cd:fc2b])\n\tby smtp.gmail.com with ESMTPSA id\n\t5b1f17b1804b1-432da298a41sm162306715e9.38.2024.11.18.05.55.18\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tMon, 18 Nov 2024 05:55:18 -0800 (PST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=redhat.com header.i=@redhat.com\n\theader.b=\"MMOTG9F2\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1731938128;\n\th=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n\tto:to:cc:cc:mime-version:mime-version:content-type:content-type:\n\tin-reply-to:in-reply-to:references:references;\n\tbh=ZPQcm0sZuCH2ujtMsoAb3RqH+KGJ+5hrMRCagnu7vLA=;\n\tb=MMOTG9F2b54SFPbCQOwMv+9XxqBxEFpY8LvfKWFGmimSQurBkJnV7ScJfRKWhatAoYh0MP\n\tccLVU57FLcdTf9Aj9AHFNxHNoHNz7jiWjWl+vWNiuecrWde5eT+JxnihxsEoPi9xWcb/yz\n\tQsUZuD0aZM/umQhBr0Rj15g3Xon1A9s=","X-MC-Unique":"-3iMm_wUMDWsw6DvjYkv1g-1","X-Mimecast-MFC-AGG-ID":"-3iMm_wUMDWsw6DvjYkv1g","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1731938125; x=1732542925;\n\th=mime-version:user-agent:message-id:date:references:in-reply-to\n\t:subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date\n\t:message-id:reply-to;\n\tbh=ZPQcm0sZuCH2ujtMsoAb3RqH+KGJ+5hrMRCagnu7vLA=;\n\tb=w0Fm/7LXR8TFnm2wlQquxMpxYQu37zKrjVuSplWSnO9YfgAUmZ5kw/ZbdfFQy8yoae\n\tH1sUS6Wf+d3WaI76Ucw2NUPXePUMeJsN/Im39Ic3sf9G4sdg4AKQyp4Svf8yQgX/HGh5\n\tK1Iy/gCq4Nv4xJ6AxJmSvzOKnzs2VYIcVpfN3o5h00gG8fswvR9aBoWm3DzQY/1sA4XM\n\tvZEZoTbUWUnjfERZbkQeEPKZv7ukXB3wc/wLfGWGoSCWyR9GXZce6W2rY4ejSrlK8w0b\n\t29b0N3T+4ikrSJ80/Y4BObfvFg0XYC7aR2sAGWJ1fGAa142XsslKFve5GE6BqW0UR9CM\n\t6QlQ==","X-Gm-Message-State":"AOJu0YxyOOpWtLcq+GVGvsclwI+Jzd8OVPbSwRUVT1Cm59e1J40Zz0g9\n\ttY5AmxsTAjOBWiIHlzgcxGbG35dpgZ/DbezB+aKFOLVp3KZW5DWW3MBFPBTCclH+mIVu3qgkkpj\n\tLy5p7CJ+lxR9e3ntgeemeFhXu85IIDlnnk1/W3vcSbUT/XLBxNiS4xiP7zYEKy6G6hGy205Bk/L\n\t5Rs5S9KVF8mIqqZyEaiTm3RPz91nY5D4exMOw1HUY9StANq6gsR1CS+g0=","X-Received":["by 2002:a05:600c:3d16:b0:431:58cd:b260 with SMTP id\n\t5b1f17b1804b1-432df791f45mr104010955e9.25.1731938125319; \n\tMon, 18 Nov 2024 05:55:25 -0800 (PST)","by 2002:a05:600c:3d16:b0:431:58cd:b260 with SMTP id\n\t5b1f17b1804b1-432df791f45mr104008395e9.25.1731938119396; \n\tMon, 18 Nov 2024 05:55:19 -0800 (PST)"],"X-Google-Smtp-Source":"AGHT+IG1UhVK4gpVXdnsStD5yUVW7FtSYh/t+Q1BrbMNVFcuMUPZjq4oXoxXBFXDxMBaPXZyL8G1JQ==","From":"Milan Zamazal <mzamazal@redhat.com>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Subject":"Re: [RFC PATCH v2 09/12] ipa: libipa: vector: Add sum() function","In-Reply-To":"<20241118000738.18977-10-laurent.pinchart@ideasonboard.com>\n\t(Laurent Pinchart's message of \"Mon, 18 Nov 2024 02:07:35 +0200\")","References":"<20241118000738.18977-1-laurent.pinchart@ideasonboard.com>\n\t<20241118000738.18977-10-laurent.pinchart@ideasonboard.com>","Date":"Mon, 18 Nov 2024 14:55:17 +0100","Message-ID":"<87ikskhcje.fsf@redhat.com>","User-Agent":"Gnus/5.13 (Gnus v5.13)","MIME-Version":"1.0","X-Mimecast-Spam-Score":"0","X-Mimecast-MFC-PROC-ID":"nRBse_zY5X3Vms0LCz3sgxfjSc7VdbtNIivq47AXCkA_1731938126","X-Mimecast-Originator":"redhat.com","Content-Type":"text/plain","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>"}}]