[{"id":36251,"web_url":"https://patchwork.libcamera.org/comment/36251/","msgid":"<0b2655ab-c996-4f6a-917e-a0b4d78cfba8@ideasonboard.com>","date":"2025-10-14T15:03:27","subject":"Re: [PATCH v1 3/4] ipa: libipa: pwl: Add construction from\n\tinitializer_list","submitter":{"id":216,"url":"https://patchwork.libcamera.org/api/people/216/","name":"Barnabás Pőcze","email":"barnabas.pocze@ideasonboard.com"},"content":"Hi\n\n2025. 10. 14. 16:24 keltezéssel, Stefan Klug írta:\n> In the tuning files it is possible to construct the PWL from a linear\n> list of numbers. Add a initializer_list based constructor to replicate\n> similar style in C++ code. An initializer_list is preferred to a Span\n> based constructor because the Span makes the static construction\n> cumbersome ( {{{ 1.0, 2.0 }}} vs { 1.0, 2.0 } ) and initialization is\n> the only use case at the moment.\n> \n> Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n> ---\n>   src/ipa/libipa/pwl.cpp | 19 +++++++++++++++++++\n>   src/ipa/libipa/pwl.h   |  1 +\n>   2 files changed, 20 insertions(+)\n> \n> diff --git a/src/ipa/libipa/pwl.cpp b/src/ipa/libipa/pwl.cpp\n> index 1858ab37b101..501ac79ea8b5 100644\n> --- a/src/ipa/libipa/pwl.cpp\n> +++ b/src/ipa/libipa/pwl.cpp\n> @@ -122,6 +122,25 @@ Pwl::Pwl(std::vector<Point> &&points)\n>   {\n>   }\n>   \n> +/**\n> + * \\brief Construct a piecewise linear function from a initializer list\n> + * \\param[in] data initializer list of doubles\n> + *\n> + * This constructor takes a even number of doubles and treats them as\n> + * x0,y0,x1,y1,...,xn,yn coordinates for the PWL.\n> + */\n> +Pwl::Pwl(std::initializer_list<double> data)\n> +{\n> +\tASSERT((data.size() % 2) == 0);\n\n   std::initializer_list<Point>\n\n?\n\nI am not a fan of the runtime %2==0 assertion when the same requirement could be\nexpressed in the type system easily. Admittedly that will need more braces, but\nI still think it's better.\n\nIn any case, I would really prefer if the runtime assert could be avoided.\nAnd I think you could already be able to do this initialization without a new\nconstructor. `Pwl{{ {{0.0, 0.5}}, ... }}` because of `Pwl::Pwl(std::vector<Point>&&)`\nIt's indeed a bit inconvenient because `Vector` has no n-argument constructors.\n\n\nRegards,\nBarnabás Pőcze\n\n> +\n> +\tauto iter = data.begin();\n> +\twhile (iter != data.end()) {\n> +\t\tdouble x = *iter++;\n> +\t\tdouble y = *iter++;\n> +\t\tappend(x, y);\n> +\t}\n> +}\n> +\n>   /**\n>    * \\brief Append a point to the end of the piecewise linear function\n>    * \\param[in] x x-coordinate of the point to add to the piecewise linear function\n> diff --git a/src/ipa/libipa/pwl.h b/src/ipa/libipa/pwl.h\n> index add20b5867af..b82b17317a5e 100644\n> --- a/src/ipa/libipa/pwl.h\n> +++ b/src/ipa/libipa/pwl.h\n> @@ -45,6 +45,7 @@ public:\n>   \tPwl();\n>   \tPwl(const std::vector<Point> &points);\n>   \tPwl(std::vector<Point> &&points);\n> +\tPwl(std::initializer_list<double> data);\n>   \n>   \tvoid append(double x, double y, double eps = 1e-6);\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 7D30BBE080\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 14 Oct 2025 15:03:33 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id B85D4605FF;\n\tTue, 14 Oct 2025 17:03:32 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 8C114605F3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 14 Oct 2025 17:03:31 +0200 (CEST)","from [192.168.33.20] (185.182.214.105.nat.pool.zt.hu\n\t[185.182.214.105])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id DA4CB741;\n\tTue, 14 Oct 2025 17:01:52 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"ELHDkppk\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1760454113;\n\tbh=qJUtJ7PlU3nR0oikZ9nuoamAASAxw3grZh4QqgibPPc=;\n\th=Date:Subject:To:References:From:In-Reply-To:From;\n\tb=ELHDkppk/8OQ0JMg8Jb52nkCUtopu0/S4nSvz79cIDv7dOxXm2sSN2K6zGpPQuLT4\n\tsdrP6VE8pMZ2AJ/T9+MCowlYXO9B3C1euA5d94463i2ctZT6ZFiI2tWJBPBbca2vyn\n\tGItVYQjba6O3H6esu/trFd50cQZuNRdo9sMH0n7c=","Message-ID":"<0b2655ab-c996-4f6a-917e-a0b4d78cfba8@ideasonboard.com>","Date":"Tue, 14 Oct 2025 17:03:27 +0200","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH v1 3/4] ipa: libipa: pwl: Add construction from\n\tinitializer_list","To":"Stefan Klug <stefan.klug@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","References":"<20251014142427.3107490-1-stefan.klug@ideasonboard.com>\n\t<20251014142427.3107490-4-stefan.klug@ideasonboard.com>","From":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>","Content-Language":"en-US, hu-HU","In-Reply-To":"<20251014142427.3107490-4-stefan.klug@ideasonboard.com>","Content-Type":"text/plain; charset=UTF-8; format=flowed","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>"}},{"id":36584,"web_url":"https://patchwork.libcamera.org/comment/36584/","msgid":"<1089602c-f9a6-48c1-a3f3-5163d702cd14@ideasonboard.com>","date":"2025-10-31T16:10:44","subject":"Re: [PATCH v1 3/4] ipa: libipa: pwl: Add construction from\n\tinitializer_list","submitter":{"id":156,"url":"https://patchwork.libcamera.org/api/people/156/","name":"Dan Scally","email":"dan.scally@ideasonboard.com"},"content":"On 14/10/2025 15:24, Stefan Klug wrote:\n> In the tuning files it is possible to construct the PWL from a linear\n> list of numbers. Add a initializer_list based constructor to replicate\n> similar style in C++ code. An initializer_list is preferred to a Span\n> based constructor because the Span makes the static construction\n> cumbersome ( {{{ 1.0, 2.0 }}} vs { 1.0, 2.0 } ) and initialization is\n> the only use case at the moment.\n> \n> Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n> ---\n>   src/ipa/libipa/pwl.cpp | 19 +++++++++++++++++++\n>   src/ipa/libipa/pwl.h   |  1 +\n>   2 files changed, 20 insertions(+)\n> \n> diff --git a/src/ipa/libipa/pwl.cpp b/src/ipa/libipa/pwl.cpp\n> index 1858ab37b101..501ac79ea8b5 100644\n> --- a/src/ipa/libipa/pwl.cpp\n> +++ b/src/ipa/libipa/pwl.cpp\n> @@ -122,6 +122,25 @@ Pwl::Pwl(std::vector<Point> &&points)\n>   {\n>   }\n>   \n> +/**\n> + * \\brief Construct a piecewise linear function from a initializer list\n> + * \\param[in] data initializer list of doubles\n> + *\n> + * This constructor takes a even number of doubles and treats them as\n> + * x0,y0,x1,y1,...,xn,yn coordinates for the PWL.\n> + */\n> +Pwl::Pwl(std::initializer_list<double> data)\n> +{\n> +\tASSERT((data.size() % 2) == 0);\n> +\n> +\tauto iter = data.begin();\n> +\twhile (iter != data.end()) {\n> +\t\tdouble x = *iter++;\n> +\t\tdouble y = *iter++;\n> +\t\tappend(x, y);\n> +\t}\n> +}\n\nFor me \"{ 0.0, 0.5 }\" is much nicer than \"Pwl{{ {{0.0, 0.5}} }}\"; my concern would be more that it's \nnot super clear what the call-site is actually constructing, but that could also be solved with a \ncomment:\n\nReviewed-by: Daniel Scally <dan.scally@ideasonboard.com>\n\n> +\n>   /**\n>    * \\brief Append a point to the end of the piecewise linear function\n>    * \\param[in] x x-coordinate of the point to add to the piecewise linear function\n> diff --git a/src/ipa/libipa/pwl.h b/src/ipa/libipa/pwl.h\n> index add20b5867af..b82b17317a5e 100644\n> --- a/src/ipa/libipa/pwl.h\n> +++ b/src/ipa/libipa/pwl.h\n> @@ -45,6 +45,7 @@ public:\n>   \tPwl();\n>   \tPwl(const std::vector<Point> &points);\n>   \tPwl(std::vector<Point> &&points);\n> +\tPwl(std::initializer_list<double> data);\n>   \n>   \tvoid append(double x, double y, double eps = 1e-6);\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 B29FEC3259\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 31 Oct 2025 16:10:50 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id CB8FD60A79;\n\tFri, 31 Oct 2025 17:10:49 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id DEEA360947\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 31 Oct 2025 17:10:47 +0100 (CET)","from [192.168.0.43]\n\t(cpc141996-chfd3-2-0-cust928.12-3.cable.virginm.net [86.13.91.161])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 5FE65153F;\n\tFri, 31 Oct 2025 17:08:56 +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=\"fpPild2I\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1761926936;\n\tbh=nF4DzLYLc+sOyLpDTuJEj8Aunr4j+HqxnVLk1xzmo0M=;\n\th=Date:Subject:To:References:From:In-Reply-To:From;\n\tb=fpPild2I/GGjs5jZKtEX5S/BoomP1IhaDePFS5+tv+k5J6DI4Lp7qlivxnBBXydzU\n\tsaFJvQKAZ3uIetM2hh0DARUJ8cyOEfcz/EB4L2pQ6ui3E/KFwCIVWnNafIAAzGnHBg\n\ttAYe+Kl6jsYgW2j5ZtUUWa0u7m6TXY0DL5id++tg=","Message-ID":"<1089602c-f9a6-48c1-a3f3-5163d702cd14@ideasonboard.com>","Date":"Fri, 31 Oct 2025 16:10:44 +0000","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH v1 3/4] ipa: libipa: pwl: Add construction from\n\tinitializer_list","To":"Stefan Klug <stefan.klug@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","References":"<20251014142427.3107490-1-stefan.klug@ideasonboard.com>\n\t<20251014142427.3107490-4-stefan.klug@ideasonboard.com>","Content-Language":"en-US","From":"Dan Scally <dan.scally@ideasonboard.com>","In-Reply-To":"<20251014142427.3107490-4-stefan.klug@ideasonboard.com>","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"7bit","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>"}}]