[{"id":32222,"web_url":"https://patchwork.libcamera.org/comment/32222/","msgid":"<87y11ghd5p.fsf@redhat.com>","date":"2024-11-18T13:41:54","subject":"Re: [RFC PATCH v2 08/12] ipa: libipa: vector: Add element-wise\n\tmin() and max() functions","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 functions to calculate the element-wise minimum and maximum of two\n> vectors or of a vector and a scalar. This will be used in algorithm\n> implementations.\n>\n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> ---\n>  src/ipa/libipa/vector.cpp | 28 ++++++++++++++++++++++++++++\n>  src/ipa/libipa/vector.h   | 20 ++++++++++++++++++++\n>  2 files changed, 48 insertions(+)\n>\n> diff --git a/src/ipa/libipa/vector.cpp b/src/ipa/libipa/vector.cpp\n> index a45f08fde493..14816cdb5d09 100644\n> --- a/src/ipa/libipa/vector.cpp\n> +++ b/src/ipa/libipa/vector.cpp\n> @@ -183,6 +183,34 @@ namespace ipa {\n>   * \\return This vector\n>   */\n>  \n> +/**\n> + * \\fn Vector::min(const Vector &other) const\n> + * \\brief Calculate the minimum of this vector and \\a other element-wise\n> + * \\param[in] other The other vector\n> + * \\return The element-wise minimum of this vector and \\a other\n> + */\n> +\n> +/**\n> + * \\fn Vector::min(T scalar) const\n> + * \\brief Calculate the minimum of this vector and \\a scalar element-wise\n> + * \\param[in] scalar The scalar\n> + * \\return The element-wise minimum of this vector and \\a scalar\n> + */\n> +\n> +/**\n> + * \\fn Vector::max(const Vector &other) const\n> + * \\brief Calculate the maximum of this vector and \\a other element-wise\n> + * \\param[in] other The other vector\n> + * \\return The element-wise maximum of this vector and \\a other\n> + */\n> +\n> +/**\n> + * \\fn Vector::max(T scalar) const\n> + * \\brief Calculate the maximum of this vector and \\a scalar element-wise\n> + * \\param[in] scalar The scalar\n> + * \\return The element-wise maximum of this vector and \\a scalar\n> + */\n> +\n>  /**\n>   * \\fn Vector::dot(const Vector<T, Rows> &other) const\n>   * \\brief Compute the dot product\n> diff --git a/src/ipa/libipa/vector.h b/src/ipa/libipa/vector.h\n> index 722ffc57ea45..949dc4650aa4 100644\n> --- a/src/ipa/libipa/vector.h\n> +++ b/src/ipa/libipa/vector.h\n> @@ -154,6 +154,26 @@ public:\n>  \t\treturn apply(scalar, [](T a, T b) { return a / b; });\n>  \t}\n>  \n> +\tconstexpr Vector min(const Vector &other) const\n> +\t{\n> +\t\treturn apply(*this, other, [](T a, T b) { return std::min(a, b); });\n> +\t}\n> +\n> +\tconstexpr Vector min(T scalar) const\n> +\t{\n> +\t\treturn apply(*this, scalar, [](T a, T b) { return std::min(a, b); });\n> +\t}\n> +\n> +\tconstexpr Vector max(const Vector &other) const\n> +\t{\n> +\t\treturn apply(*this, other, [](T a, T b) { return std::max(a, b); });\n> +\t}\n> +\n> +\tconstexpr Vector max(T scalar) const\n> +\t{\n> +\t\treturn apply(*this, scalar, [](T a, T b) -> T { return std::max(a, b); });\n> +\t}\n> +\n\nI wonder whether there could be a way to use std::max and std::min\ndirectly, without wrapping them by lambdas.  I don't know so:\n\nReviewed-by: Milan Zamazal <mzamazal@redhat.com>\n\n>  \tconstexpr T dot(const Vector<T, Rows> &other) const\n>  \t{\n>  \t\tT ret = 0;","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 E7F89C32DD\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 18 Nov 2024 13:42:03 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 08D11658CD;\n\tMon, 18 Nov 2024 14:42:03 +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 B8DF160532\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 18 Nov 2024 14:42:00 +0100 (CET)","from mail-wr1-f71.google.com (mail-wr1-f71.google.com\n\t[209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS\n\t(version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id\n\tus-mta-418-dJsb2IgxOCKubl9zUDn00w-1; Mon, 18 Nov 2024 08:41:58 -0500","by mail-wr1-f71.google.com with SMTP id\n\tffacd0b85a97d-38244684ccaso578683f8f.3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 18 Nov 2024 05:41:58 -0800 (PST)","from nuthatch ([2a00:102a:400a:489a:ffe9:aa41:63cd:fc2b])\n\tby smtp.gmail.com with ESMTPSA id\n\tffacd0b85a97d-3824a8109a7sm1378880f8f.104.2024.11.18.05.41.55\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tMon, 18 Nov 2024 05:41:55 -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=\"YHXL0y9f\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1731937319;\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=y5xDug2ePzYp4bu0QVKW+mCDeOOvwvvDa5nYj7TlHtg=;\n\tb=YHXL0y9fDtW7uGZuQ+/3wlhgqXqeOXP4S9ox14QbvsD8DWb+bnVcXGglzMS3dLt2txMBA6\n\t0Y6QFPp5AhppD48TvHzDY0uLi7CGeuMsV3z3rgPVlXEcwfa8kMufBA6hWoasvnY146gynt\n\t6cd7zJCBJ3Cnbt8lJG2HeKgDEWvsbk8=","X-MC-Unique":"dJsb2IgxOCKubl9zUDn00w-1","X-Mimecast-MFC-AGG-ID":"dJsb2IgxOCKubl9zUDn00w","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1731937317; x=1732542117;\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=y5xDug2ePzYp4bu0QVKW+mCDeOOvwvvDa5nYj7TlHtg=;\n\tb=REFa1RZaW0AIX4qipHrGEPa/jIkMLaK5kLj8A+1X8jZ7hvPxPg2W5W3TSP5fHTQbpB\n\tWR4sINp/q2rbHVx9oiAyts97Zr7MF8eGvhvgz0KDrV6eeW8O6khUADziUajUCltxKwEq\n\tKVSnr8bcj3G1eT2ZSpSOzco3222HNilOWyKrOcnKWt2XsvPoZhTEdig/scb/ROlRJPfx\n\t8ruOZjmOgWGFS+81IucQ16qeXpj7AvkKj9C5+8YKpHD7EqN1EauVUyU4Uuu87YtFM5KR\n\tZMAYbziRW87tcRYEcCI7mM7OfPz6bzoybsd0y2ST+NGUXGj1TKkhdh+oHPhyaiI+AyW4\n\tDMMQ==","X-Gm-Message-State":"AOJu0Yw0j+TgWNAXFC8Idvy+QKlm4aWaG02oJgAYT3NYaVdeOk9hIVg7\n\tkx4dh8gP8RQBgTWHB5HenTr1lVTMqjGZBrjqzfLIEr7xeCvmmhupfU5zvDpy01FVGdR3mBArwzg\n\tGA5W4CxOKZ46cxIvn11MjVM4BGVECry1BY4tc05eSKj7IO0AlyAE4/aIr+qYw+ipF5rtFJiCnpC\n\tVI6jKP9aCxbsc8lpo6b/mn2HtPxwgqy4YMXrKGVrpBxdGxePQvusMgE50=","X-Received":["by 2002:a5d:47a9:0:b0:382:372a:572d with SMTP id\n\tffacd0b85a97d-382372a5a55mr6008898f8f.27.1731937316779; \n\tMon, 18 Nov 2024 05:41:56 -0800 (PST)","by 2002:a5d:47a9:0:b0:382:372a:572d with SMTP id\n\tffacd0b85a97d-382372a5a55mr6008876f8f.27.1731937316389; \n\tMon, 18 Nov 2024 05:41:56 -0800 (PST)"],"X-Google-Smtp-Source":"AGHT+IErwMQTsApsDP/WU0wglcJIozRjNe7KMpBq1ITZeOraigmV4VMyROa3/sFgZtKyq9VprdPtMA==","From":"Milan Zamazal <mzamazal@redhat.com>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Subject":"Re: [RFC PATCH v2 08/12] ipa: libipa: vector: Add element-wise\n\tmin() and max() functions","In-Reply-To":"<20241118000738.18977-9-laurent.pinchart@ideasonboard.com>\n\t(Laurent Pinchart's message of \"Mon, 18 Nov 2024 02:07:34 +0200\")","References":"<20241118000738.18977-1-laurent.pinchart@ideasonboard.com>\n\t<20241118000738.18977-9-laurent.pinchart@ideasonboard.com>","Date":"Mon, 18 Nov 2024 14:41:54 +0100","Message-ID":"<87y11ghd5p.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":"2OPI0Di3G5QhtdKzvEWlynVijPGeJs5hcSV2D0mbjEg_1731937317","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>"}},{"id":32227,"web_url":"https://patchwork.libcamera.org/comment/32227/","msgid":"<20241118135341.GP31681@pendragon.ideasonboard.com>","date":"2024-11-18T13:53:41","subject":"Re: [RFC PATCH v2 08/12] ipa: libipa: vector: Add element-wise min()\n\tand max() functions","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"On Mon, Nov 18, 2024 at 02:41:54PM +0100, Milan Zamazal wrote:\n> Laurent Pinchart <laurent.pinchart@ideasonboard.com> writes:\n> \n> > Add functions to calculate the element-wise minimum and maximum of two\n> > vectors or of a vector and a scalar. This will be used in algorithm\n> > implementations.\n> >\n> > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> > ---\n> >  src/ipa/libipa/vector.cpp | 28 ++++++++++++++++++++++++++++\n> >  src/ipa/libipa/vector.h   | 20 ++++++++++++++++++++\n> >  2 files changed, 48 insertions(+)\n> >\n> > diff --git a/src/ipa/libipa/vector.cpp b/src/ipa/libipa/vector.cpp\n> > index a45f08fde493..14816cdb5d09 100644\n> > --- a/src/ipa/libipa/vector.cpp\n> > +++ b/src/ipa/libipa/vector.cpp\n> > @@ -183,6 +183,34 @@ namespace ipa {\n> >   * \\return This vector\n> >   */\n> >  \n> > +/**\n> > + * \\fn Vector::min(const Vector &other) const\n> > + * \\brief Calculate the minimum of this vector and \\a other element-wise\n> > + * \\param[in] other The other vector\n> > + * \\return The element-wise minimum of this vector and \\a other\n> > + */\n> > +\n> > +/**\n> > + * \\fn Vector::min(T scalar) const\n> > + * \\brief Calculate the minimum of this vector and \\a scalar element-wise\n> > + * \\param[in] scalar The scalar\n> > + * \\return The element-wise minimum of this vector and \\a scalar\n> > + */\n> > +\n> > +/**\n> > + * \\fn Vector::max(const Vector &other) const\n> > + * \\brief Calculate the maximum of this vector and \\a other element-wise\n> > + * \\param[in] other The other vector\n> > + * \\return The element-wise maximum of this vector and \\a other\n> > + */\n> > +\n> > +/**\n> > + * \\fn Vector::max(T scalar) const\n> > + * \\brief Calculate the maximum of this vector and \\a scalar element-wise\n> > + * \\param[in] scalar The scalar\n> > + * \\return The element-wise maximum of this vector and \\a scalar\n> > + */\n> > +\n> >  /**\n> >   * \\fn Vector::dot(const Vector<T, Rows> &other) const\n> >   * \\brief Compute the dot product\n> > diff --git a/src/ipa/libipa/vector.h b/src/ipa/libipa/vector.h\n> > index 722ffc57ea45..949dc4650aa4 100644\n> > --- a/src/ipa/libipa/vector.h\n> > +++ b/src/ipa/libipa/vector.h\n> > @@ -154,6 +154,26 @@ public:\n> >  \t\treturn apply(scalar, [](T a, T b) { return a / b; });\n> >  \t}\n> >  \n> > +\tconstexpr Vector min(const Vector &other) const\n> > +\t{\n> > +\t\treturn apply(*this, other, [](T a, T b) { return std::min(a, b); });\n> > +\t}\n> > +\n> > +\tconstexpr Vector min(T scalar) const\n> > +\t{\n> > +\t\treturn apply(*this, scalar, [](T a, T b) { return std::min(a, b); });\n> > +\t}\n> > +\n> > +\tconstexpr Vector max(const Vector &other) const\n> > +\t{\n> > +\t\treturn apply(*this, other, [](T a, T b) { return std::max(a, b); });\n> > +\t}\n> > +\n> > +\tconstexpr Vector max(T scalar) const\n> > +\t{\n> > +\t\treturn apply(*this, scalar, [](T a, T b) -> T { return std::max(a, b); });\n> > +\t}\n> > +\n> \n> I wonder whether there could be a way to use std::max and std::min\n> directly, without wrapping them by lambdas.  I don't know so:\n\nUnfortunately that doesn't seem to be the case.\n\n> Reviewed-by: Milan Zamazal <mzamazal@redhat.com>\n> \n> >  \tconstexpr T dot(const Vector<T, Rows> &other) const\n> >  \t{\n> >  \t\tT ret = 0;\n>","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 8211BC32DD\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 18 Nov 2024 13:53:51 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 46A82658DC;\n\tMon, 18 Nov 2024 14:53:51 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id B0DBF60532\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 18 Nov 2024 14:53:50 +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 D5368316;\n\tMon, 18 Nov 2024 14:53:33 +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=\"oKWtvJ5f\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1731938014;\n\tbh=rKb+2ICI9zYGT0HNkiTYGj0s5YolUokQkF6rE9plZZw=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=oKWtvJ5fYfo32Sa+sfDcf+Nk1T6RwWJJnJz6a3fw1aXLQJiRXl7HMRpt+HbqPu73M\n\tRRSZoRDDFoXTRuGe7DEaBIPJUwqSeM7eYw8GWQ/GxzlZkc2EPr6wD6NT2nVUDf7iYa\n\tR7nAHLeTacIBPU1QfvLbAogbbgsCXX9aPRzhneo0=","Date":"Mon, 18 Nov 2024 15:53:41 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Milan Zamazal <mzamazal@redhat.com>","Cc":"libcamera-devel@lists.libcamera.org","Subject":"Re: [RFC PATCH v2 08/12] ipa: libipa: vector: Add element-wise min()\n\tand max() functions","Message-ID":"<20241118135341.GP31681@pendragon.ideasonboard.com>","References":"<20241118000738.18977-1-laurent.pinchart@ideasonboard.com>\n\t<20241118000738.18977-9-laurent.pinchart@ideasonboard.com>\n\t<87y11ghd5p.fsf@redhat.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<87y11ghd5p.fsf@redhat.com>","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>"}}]