[{"id":33792,"web_url":"https://patchwork.libcamera.org/comment/33792/","msgid":"<174344072846.3394313.17838678133152093866@ping.linuxembedded.co.uk>","date":"2025-03-31T17:05:28","subject":"Re: [PATCH v2 04/17] libcamera: vector: Add a Span based constructor","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Stefan Klug (2025-03-19 16:11:09)\n> Now that Matrix has a Span based constructor, add the same for Vector.\n\nWell, with that logic, someone else has a yacht - so I deserve one ...\n:-)\n\nI assume Vectors deserve span based constructors because it benefits\nthem directly?\n\n\n> \n> Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n> \n> ---\n> \n> Changes in v2:\n> - Added this patch\n> ---\n>  include/libcamera/internal/vector.h | 12 ++++++++----\n>  src/libcamera/vector.cpp            |  8 ++++++++\n>  2 files changed, 16 insertions(+), 4 deletions(-)\n> \n> diff --git a/include/libcamera/internal/vector.h b/include/libcamera/internal/vector.h\n> index a67a09474204..66cc5ac988c2 100644\n> --- a/include/libcamera/internal/vector.h\n> +++ b/include/libcamera/internal/vector.h\n> @@ -40,10 +40,14 @@ public:\n>                 data_.fill(scalar);\n>         }\n>  \n> -       constexpr Vector(const std::array<T, Rows> &data)\n> +       Vector(const std::array<T, Rows> &data)\n>         {\n> -               for (unsigned int i = 0; i < Rows; i++)\n> -                       data_[i] = data[i];\n> +               std::copy(data.begin(), data.end(), data_.begin());\n> +       }\n\nThis loses a constexpr ... what's the downside here? At least that\nshould be highlighted/discussed in the commit message.\n\n\n> +\n> +       Vector(const Span<const T, Rows> &data)\n> +       {\n> +               std::copy(data.begin(), data.end(), data_.begin());\n>         }\n>  \n>         const T &operator[](size_t i) const\n> @@ -285,7 +289,7 @@ private:\n>                 return *this;\n>         }\n>  \n> -       std::array<T, Rows> data_;\n> +       std::array<T, Rows> data_{};\n\nIs this just for initialisation ?\n\n>  };\n>  \n>  template<typename T>\n> diff --git a/src/libcamera/vector.cpp b/src/libcamera/vector.cpp\n> index 85ca2208245a..435f2fc62f8b 100644\n> --- a/src/libcamera/vector.cpp\n> +++ b/src/libcamera/vector.cpp\n> @@ -44,6 +44,14 @@ LOG_DEFINE_CATEGORY(Vector)\n>   * The size of \\a data must be equal to the dimension size Rows of the vector.\n>   */\n>  \n> +/**\n> + * \\fn Vector::Vector(const Span<const T, Rows> &data)\n> + * \\brief Construct vector from supplied data\n> + * \\param data Data from which to construct a vector\n> + *\n> + * The size of \\a data must be equal to the dimension size Rows of the vector.\n> + */\n> +\n>  /**\n>   * \\fn T Vector::operator[](size_t i) const\n>   * \\brief Index to an element in the vector\n> -- \n> 2.43.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 A532AC3213\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 31 Mar 2025 17:05:33 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id C85BF68985;\n\tMon, 31 Mar 2025 19:05:32 +0200 (CEST)","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 3CA516897A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 31 Mar 2025 19:05:31 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 90BF5703;\n\tMon, 31 Mar 2025 19:03:39 +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=\"OWEYBoyq\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1743440619;\n\tbh=cAfasPvOuoTmfoPERbb6/RS1vPp5+B5F/4Lr/AmZOSw=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=OWEYBoyqipZgsMZOBD9ALboWwmAU6NEu7SB3CGVGLfG81of4rLTlwCbsWfYaGCOmz\n\ti9Xu9zWTvWEprDW9O1Vwz4Tvw0jQR+hJ8PkWNde9q+FYgLoQAi2+0V8qv20m5HpL0x\n\tiI51emCBYfPFd2rCjM2awugizbU/y73wDdLmW8Ag=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20250319161152.63625-5-stefan.klug@ideasonboard.com>","References":"<20250319161152.63625-1-stefan.klug@ideasonboard.com>\n\t<20250319161152.63625-5-stefan.klug@ideasonboard.com>","Subject":"Re: [PATCH v2 04/17] libcamera: vector: Add a Span based constructor","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"Stefan Klug <stefan.klug@ideasonboard.com>","To":"Stefan Klug <stefan.klug@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Mon, 31 Mar 2025 18:05:28 +0100","Message-ID":"<174344072846.3394313.17838678133152093866@ping.linuxembedded.co.uk>","User-Agent":"alot/0.10","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":33826,"web_url":"https://patchwork.libcamera.org/comment/33826/","msgid":"<20250401010416.GR14432@pendragon.ideasonboard.com>","date":"2025-04-01T01:04:16","subject":"Re: [PATCH v2 04/17] libcamera: vector: Add a Span based constructor","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"On Mon, Mar 31, 2025 at 06:05:28PM +0100, Kieran Bingham wrote:\n> Quoting Stefan Klug (2025-03-19 16:11:09)\n> > Now that Matrix has a Span based constructor, add the same for Vector.\n> \n> Well, with that logic, someone else has a yacht - so I deserve one ...\n> :-)\n> \n> I assume Vectors deserve span based constructors because it benefits\n> them directly?\n\nA similar commit message to 03/17 would be better indeed.\n\nAll my comments on 03/17 apply here too.\n\n> > Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n> > \n> > ---\n> > \n> > Changes in v2:\n> > - Added this patch\n> > ---\n> >  include/libcamera/internal/vector.h | 12 ++++++++----\n> >  src/libcamera/vector.cpp            |  8 ++++++++\n> >  2 files changed, 16 insertions(+), 4 deletions(-)\n> > \n> > diff --git a/include/libcamera/internal/vector.h b/include/libcamera/internal/vector.h\n> > index a67a09474204..66cc5ac988c2 100644\n> > --- a/include/libcamera/internal/vector.h\n> > +++ b/include/libcamera/internal/vector.h\n> > @@ -40,10 +40,14 @@ public:\n> >                 data_.fill(scalar);\n> >         }\n> >  \n> > -       constexpr Vector(const std::array<T, Rows> &data)\n> > +       Vector(const std::array<T, Rows> &data)\n> >         {\n> > -               for (unsigned int i = 0; i < Rows; i++)\n> > -                       data_[i] = data[i];\n> > +               std::copy(data.begin(), data.end(), data_.begin());\n> > +       }\n> \n> This loses a constexpr ... what's the downside here? At least that\n> should be highlighted/discussed in the commit message.\n> \n> > +\n> > +       Vector(const Span<const T, Rows> &data)\n> > +       {\n> > +               std::copy(data.begin(), data.end(), data_.begin());\n> >         }\n> >  \n> >         const T &operator[](size_t i) const\n> > @@ -285,7 +289,7 @@ private:\n> >                 return *this;\n> >         }\n> >  \n> > -       std::array<T, Rows> data_;\n> > +       std::array<T, Rows> data_{};\n> \n> Is this just for initialisation ?\n>\n> >  };\n> >  \n> >  template<typename T>\n> > diff --git a/src/libcamera/vector.cpp b/src/libcamera/vector.cpp\n> > index 85ca2208245a..435f2fc62f8b 100644\n> > --- a/src/libcamera/vector.cpp\n> > +++ b/src/libcamera/vector.cpp\n> > @@ -44,6 +44,14 @@ LOG_DEFINE_CATEGORY(Vector)\n> >   * The size of \\a data must be equal to the dimension size Rows of the vector.\n> >   */\n> >  \n> > +/**\n> > + * \\fn Vector::Vector(const Span<const T, Rows> &data)\n> > + * \\brief Construct vector from supplied data\n> > + * \\param data Data from which to construct a vector\n> > + *\n> > + * The size of \\a data must be equal to the dimension size Rows of the vector.\n> > + */\n> > +\n> >  /**\n> >   * \\fn T Vector::operator[](size_t i) const\n> >   * \\brief Index to an element in the vector","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 43DDEC3213\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue,  1 Apr 2025 01:04:44 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 5347668985;\n\tTue,  1 Apr 2025 03:04:43 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id E7B1562C66\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  1 Apr 2025 03:04:41 +0200 (CEST)","from pendragon.ideasonboard.com (85-76-147-224-nat.elisa-mobile.fi\n\t[85.76.147.224])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id B35406A6;\n\tTue,  1 Apr 2025 03:02:49 +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=\"QnoKFPmf\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1743469370;\n\tbh=TrMc7If3zenedkV6eDuHBOEF7WNkQIT2Wdo74PC7074=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=QnoKFPmfZktkBGTfBru8AIQYaPlVAnJ/6i7/hh+uEu7GbsGEucbuVghMbJzLrZI+Z\n\tJCxK7709nSSwfIqnbD5ZxKn2Fn43R+6rxATbLgNxcO+lxERGAhzitaOv+15BU4QbFG\n\tNZgnDaOpSnHgZ1cPPZ5TbWB8uVZQFypvicMI6pc0=","Date":"Tue, 1 Apr 2025 04:04:16 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"Stefan Klug <stefan.klug@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Subject":"Re: [PATCH v2 04/17] libcamera: vector: Add a Span based constructor","Message-ID":"<20250401010416.GR14432@pendragon.ideasonboard.com>","References":"<20250319161152.63625-1-stefan.klug@ideasonboard.com>\n\t<20250319161152.63625-5-stefan.klug@ideasonboard.com>\n\t<174344072846.3394313.17838678133152093866@ping.linuxembedded.co.uk>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<174344072846.3394313.17838678133152093866@ping.linuxembedded.co.uk>","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":33855,"web_url":"https://patchwork.libcamera.org/comment/33855/","msgid":"<g5noveqt5hwaemmrqrmei4xrxotu2yr67uh56rdmymgkqfkeit@utdogt323cgs>","date":"2025-04-01T14:20:15","subject":"Re: [PATCH v2 04/17] libcamera: vector: Add a Span based constructor","submitter":{"id":184,"url":"https://patchwork.libcamera.org/api/people/184/","name":"Stefan Klug","email":"stefan.klug@ideasonboard.com"},"content":"On Mon, Mar 31, 2025 at 06:05:28PM +0100, Kieran Bingham wrote:\n> Quoting Stefan Klug (2025-03-19 16:11:09)\n> > Now that Matrix has a Span based constructor, add the same for Vector.\n> \n> Well, with that logic, someone else has a yacht - so I deserve one ...\n> :-)\n\nNice indeed. I'd like to have a plane :-)\n\n> \n> I assume Vectors deserve span based constructors because it benefits\n> them directly?\n\nFixed the commit message.\n\n> \n> \n> > \n> > Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n> > \n> > ---\n> > \n> > Changes in v2:\n> > - Added this patch\n> > ---\n> >  include/libcamera/internal/vector.h | 12 ++++++++----\n> >  src/libcamera/vector.cpp            |  8 ++++++++\n> >  2 files changed, 16 insertions(+), 4 deletions(-)\n> > \n> > diff --git a/include/libcamera/internal/vector.h b/include/libcamera/internal/vector.h\n> > index a67a09474204..66cc5ac988c2 100644\n> > --- a/include/libcamera/internal/vector.h\n> > +++ b/include/libcamera/internal/vector.h\n> > @@ -40,10 +40,14 @@ public:\n> >                 data_.fill(scalar);\n> >         }\n> >  \n> > -       constexpr Vector(const std::array<T, Rows> &data)\n> > +       Vector(const std::array<T, Rows> &data)\n> >         {\n> > -               for (unsigned int i = 0; i < Rows; i++)\n> > -                       data_[i] = data[i];\n> > +               std::copy(data.begin(), data.end(), data_.begin());\n> > +       }\n> \n> This loses a constexpr ... what's the downside here? At least that\n> should be highlighted/discussed in the commit message.\n\nActually this is a bit of a mess. I changed to std::copy to align with\nthe Matrix implementation. But std::copy is not constexpr until C++20.\nBut as no one uses the constexpr version, the compiler doesn't tell.\n\nThen I realized that a lot of the operators are declared constexpr even\nthough they are not constexpr. (Because the inner transform is constexpr\nsince C++20).\n\nRemoving all those constexpr without being able to test them is not\nreally sensible. So my current strategy on this is:\n\nThe constexpr declaration is merely an \"intent\" as we can't test it. We\nmight need to fix things when we need it, or not if we switch to C++20\nfirst. Taking that direction I should leave the constexpr in place in\nthis case although I know it is not working. Oh that doesn't feel right\neither...\n\nOpinions?\n\n> \n> \n> > +\n> > +       Vector(const Span<const T, Rows> &data)\n> > +       {\n> > +               std::copy(data.begin(), data.end(), data_.begin());\n> >         }\n> >  \n> >         const T &operator[](size_t i) const\n> > @@ -285,7 +289,7 @@ private:\n> >                 return *this;\n> >         }\n> >  \n> > -       std::array<T, Rows> data_;\n> > +       std::array<T, Rows> data_{};\n> \n> Is this just for initialisation ?\n\nYes, I added a comment in v3.\n\nBest regards,\nStefan\n\n> \n> >  };\n> >  \n> >  template<typename T>\n> > diff --git a/src/libcamera/vector.cpp b/src/libcamera/vector.cpp\n> > index 85ca2208245a..435f2fc62f8b 100644\n> > --- a/src/libcamera/vector.cpp\n> > +++ b/src/libcamera/vector.cpp\n> > @@ -44,6 +44,14 @@ LOG_DEFINE_CATEGORY(Vector)\n> >   * The size of \\a data must be equal to the dimension size Rows of the vector.\n> >   */\n> >  \n> > +/**\n> > + * \\fn Vector::Vector(const Span<const T, Rows> &data)\n> > + * \\brief Construct vector from supplied data\n> > + * \\param data Data from which to construct a vector\n> > + *\n> > + * The size of \\a data must be equal to the dimension size Rows of the vector.\n> > + */\n> > +\n> >  /**\n> >   * \\fn T Vector::operator[](size_t i) const\n> >   * \\brief Index to an element in the vector\n> > -- \n> > 2.43.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 CCBFDC323E\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue,  1 Apr 2025 14:20:20 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 84EEB68962;\n\tTue,  1 Apr 2025 16:20:20 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 7014768947\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  1 Apr 2025 16:20:18 +0200 (CEST)","from ideasonboard.com (unknown\n\t[IPv6:2a00:6020:448c:6c00:14c7:4fcc:495b:719f])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 326266F9;\n\tTue,  1 Apr 2025 16:18:26 +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=\"NGSx+7Yx\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1743517106;\n\tbh=IfSolc9UXGIddZ0YrFa+bTN5/1UEIW2W3SnFGLtA7SU=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=NGSx+7YxqQwI/vTWz0wtUG/qxQLEunQqwSxVPe/dCyUXxDwBnyupBTsvuHVCk16AI\n\tSwkLBcPWU71/Ntf7Jc8+zVaF7+vtDJPDFP4fFdzFmJvO4wPBgK6Oi9xovN7drgKG4Y\n\t1h3C2x9Bjum1d/opmqXqKRYeDSW6CTlwFFo0uLcA=","Date":"Tue, 1 Apr 2025 16:20:15 +0200","From":"Stefan Klug <stefan.klug@ideasonboard.com>","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Subject":"Re: [PATCH v2 04/17] libcamera: vector: Add a Span based constructor","Message-ID":"<g5noveqt5hwaemmrqrmei4xrxotu2yr67uh56rdmymgkqfkeit@utdogt323cgs>","References":"<20250319161152.63625-1-stefan.klug@ideasonboard.com>\n\t<20250319161152.63625-5-stefan.klug@ideasonboard.com>\n\t<174344072846.3394313.17838678133152093866@ping.linuxembedded.co.uk>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<174344072846.3394313.17838678133152093866@ping.linuxembedded.co.uk>","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":33859,"web_url":"https://patchwork.libcamera.org/comment/33859/","msgid":"<20250401182338.GB3494@pendragon.ideasonboard.com>","date":"2025-04-01T18:23:38","subject":"Re: [PATCH v2 04/17] libcamera: vector: Add a Span based constructor","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"On Tue, Apr 01, 2025 at 04:20:15PM +0200, Stefan Klug wrote:\n> On Mon, Mar 31, 2025 at 06:05:28PM +0100, Kieran Bingham wrote:\n> > Quoting Stefan Klug (2025-03-19 16:11:09)\n> > > Now that Matrix has a Span based constructor, add the same for Vector.\n> > \n> > Well, with that logic, someone else has a yacht - so I deserve one ...\n> > :-)\n> \n> Nice indeed. I'd like to have a plane :-)\n> \n> > \n> > I assume Vectors deserve span based constructors because it benefits\n> > them directly?\n> \n> Fixed the commit message.\n> \n> > > Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n> > > \n> > > ---\n> > > \n> > > Changes in v2:\n> > > - Added this patch\n> > > ---\n> > >  include/libcamera/internal/vector.h | 12 ++++++++----\n> > >  src/libcamera/vector.cpp            |  8 ++++++++\n> > >  2 files changed, 16 insertions(+), 4 deletions(-)\n> > > \n> > > diff --git a/include/libcamera/internal/vector.h b/include/libcamera/internal/vector.h\n> > > index a67a09474204..66cc5ac988c2 100644\n> > > --- a/include/libcamera/internal/vector.h\n> > > +++ b/include/libcamera/internal/vector.h\n> > > @@ -40,10 +40,14 @@ public:\n> > >                 data_.fill(scalar);\n> > >         }\n> > >  \n> > > -       constexpr Vector(const std::array<T, Rows> &data)\n> > > +       Vector(const std::array<T, Rows> &data)\n> > >         {\n> > > -               for (unsigned int i = 0; i < Rows; i++)\n> > > -                       data_[i] = data[i];\n> > > +               std::copy(data.begin(), data.end(), data_.begin());\n> > > +       }\n> > \n> > This loses a constexpr ... what's the downside here? At least that\n> > should be highlighted/discussed in the commit message.\n> \n> Actually this is a bit of a mess. I changed to std::copy to align with\n> the Matrix implementation. But std::copy is not constexpr until C++20.\n> But as no one uses the constexpr version, the compiler doesn't tell.\n> \n> Then I realized that a lot of the operators are declared constexpr even\n> though they are not constexpr. (Because the inner transform is constexpr\n> since C++20).\n> \n> Removing all those constexpr without being able to test them is not\n> really sensible. So my current strategy on this is:\n> \n> The constexpr declaration is merely an \"intent\" as we can't test it. We\n> might need to fix things when we need it, or not if we switch to C++20\n> first. Taking that direction I should leave the constexpr in place in\n> this case although I know it is not working. Oh that doesn't feel right\n> either...\n> \n> Opinions?\n\nI'm fine with this. You're not making things worse, and we're not\ncornering ourselves in a bad way, so we can wait to see if we'll switch\nto C++20 first or will replace std::copy.\n\n> > > +\n> > > +       Vector(const Span<const T, Rows> &data)\n> > > +       {\n> > > +               std::copy(data.begin(), data.end(), data_.begin());\n> > >         }\n> > >  \n> > >         const T &operator[](size_t i) const\n> > > @@ -285,7 +289,7 @@ private:\n> > >                 return *this;\n> > >         }\n> > >  \n> > > -       std::array<T, Rows> data_;\n> > > +       std::array<T, Rows> data_{};\n> > \n> > Is this just for initialisation ?\n> \n> Yes, I added a comment in v3.\n> \n> Best regards,\n> Stefan\n> \n> > >  };\n> > >  \n> > >  template<typename T>\n> > > diff --git a/src/libcamera/vector.cpp b/src/libcamera/vector.cpp\n> > > index 85ca2208245a..435f2fc62f8b 100644\n> > > --- a/src/libcamera/vector.cpp\n> > > +++ b/src/libcamera/vector.cpp\n> > > @@ -44,6 +44,14 @@ LOG_DEFINE_CATEGORY(Vector)\n> > >   * The size of \\a data must be equal to the dimension size Rows of the vector.\n> > >   */\n> > >  \n> > > +/**\n> > > + * \\fn Vector::Vector(const Span<const T, Rows> &data)\n> > > + * \\brief Construct vector from supplied data\n> > > + * \\param data Data from which to construct a vector\n> > > + *\n> > > + * The size of \\a data must be equal to the dimension size Rows of the vector.\n> > > + */\n> > > +\n> > >  /**\n> > >   * \\fn T Vector::operator[](size_t i) const\n> > >   * \\brief Index to an element in the vector","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 A4F4EC3213\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue,  1 Apr 2025 18:24:05 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 1908A68985;\n\tTue,  1 Apr 2025 20:24:05 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 33BE968947\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  1 Apr 2025 20:24:04 +0200 (CEST)","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 8F3196F9;\n\tTue,  1 Apr 2025 20:22:11 +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=\"euPU25HA\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1743531731;\n\tbh=ucygZykYPHKKP6yq6fydy9otZoSeD8b0oiT/+a3CG00=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=euPU25HA58dQ2CfOuh2D5IKvL6ePoIGNpo6G1YGXM7ULtpnrLPBgfw09GYAGP4N6N\n\tL98SuN/s1EBlXmSJje6rcFk62xX5uWlbp4ht/69iYMz9Xki4Uhh3d/sbS3BhFvZfuv\n\tB21VBKBKsyKpUErEWa8Ay5VoNT843U0bnGbPYRJk=","Date":"Tue, 1 Apr 2025 21:23:38 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Stefan Klug <stefan.klug@ideasonboard.com>","Cc":"Kieran Bingham <kieran.bingham@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Subject":"Re: [PATCH v2 04/17] libcamera: vector: Add a Span based constructor","Message-ID":"<20250401182338.GB3494@pendragon.ideasonboard.com>","References":"<20250319161152.63625-1-stefan.klug@ideasonboard.com>\n\t<20250319161152.63625-5-stefan.klug@ideasonboard.com>\n\t<174344072846.3394313.17838678133152093866@ping.linuxembedded.co.uk>\n\t<g5noveqt5hwaemmrqrmei4xrxotu2yr67uh56rdmymgkqfkeit@utdogt323cgs>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<g5noveqt5hwaemmrqrmei4xrxotu2yr67uh56rdmymgkqfkeit@utdogt323cgs>","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>"}}]