[{"id":34098,"web_url":"https://patchwork.libcamera.org/comment/34098/","msgid":"<174617179947.1586992.5684017660646469812@ping.linuxembedded.co.uk>","date":"2025-05-02T07:43:19","subject":"Re: [PATCH v3 04/16] 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-04-03 16:49:09)\n> When one wants to create a Vector from existing data, currently the only\n> way is via std::array. Add a Span based constructor to allow creation\n> from std::vectors and alike.\n> \n> While at it, replace the manual loop with std::copy.\n> \n> Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> \n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n> ---\n> \n> Changes in v2:\n> - Added this patch\n> \n> Changes in v3:\n> - Improved commit message\n> - Added constexpr to the contructor\n> - Pass Span by value\n> - Removed initializer of data_ member which was only needed for the\n>   default constructor to be actually constexpr. But Vector is not used\n> as constexpr anywhere, so we can leave that as is (This will fix itself\n> with C++20).\n> ---\n>  include/libcamera/internal/vector.h | 8 ++++++--\n>  src/libcamera/vector.cpp            | 8 ++++++++\n>  2 files changed, 14 insertions(+), 2 deletions(-)\n> \n> diff --git a/include/libcamera/internal/vector.h b/include/libcamera/internal/vector.h\n> index a67a09474204..4e9ef1ee6853 100644\n> --- a/include/libcamera/internal/vector.h\n> +++ b/include/libcamera/internal/vector.h\n> @@ -42,8 +42,12 @@ public:\n>  \n>         constexpr 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> +       constexpr 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> diff --git a/src/libcamera/vector.cpp b/src/libcamera/vector.cpp\n> index 85ca2208245a..5567d5b8defb 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 1FFA8BE08B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri,  2 May 2025 07:43:24 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 8B08868B24;\n\tFri,  2 May 2025 09:43:23 +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 A9FAD68ACB\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  2 May 2025 09:43:22 +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 E7A08353;\n\tFri,  2 May 2025 09:43:14 +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=\"VF79Ok/y\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1746171795;\n\tbh=IRyLw21FC2PUg5HUG8gE91D9O70Vc1tGB7QADDyJeUM=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=VF79Ok/y6p7qU7GCtmEgwW2o81+raRTc6wfYJfLO6WGFMecPBdatHPEuhX4xdxDnz\n\tKYyIK/Tt9xHajkoNRPiLuGE8tRvY/22W9SOowUQztPVm5IPho8gUK/YmP7mDd5mbyQ\n\t7NibQ8O7DkFm1y1Gx8egvY9QxzDsxhiPBp2/X2sA=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20250403154925.382973-5-stefan.klug@ideasonboard.com>","References":"<20250403154925.382973-1-stefan.klug@ideasonboard.com>\n\t<20250403154925.382973-5-stefan.klug@ideasonboard.com>","Subject":"Re: [PATCH v3 04/16] libcamera: vector: Add a Span based constructor","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"Stefan Klug <stefan.klug@ideasonboard.com>,\n\tLaurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Stefan Klug <stefan.klug@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Fri, 02 May 2025 08:43:19 +0100","Message-ID":"<174617179947.1586992.5684017660646469812@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":34141,"web_url":"https://patchwork.libcamera.org/comment/34141/","msgid":"<aBt_CFJGKMga7jvg@pyrite.rasen.tech>","date":"2025-05-07T15:40:56","subject":"Re: [PATCH v3 04/16] libcamera: vector: Add a Span based constructor","submitter":{"id":17,"url":"https://patchwork.libcamera.org/api/people/17/","name":"Paul Elder","email":"paul.elder@ideasonboard.com"},"content":"On Thu, Apr 03, 2025 at 05:49:09PM +0200, Stefan Klug wrote:\n> When one wants to create a Vector from existing data, currently the only\n> way is via std::array. Add a Span based constructor to allow creation\n> from std::vectors and alike.\n> \n> While at it, replace the manual loop with std::copy.\n> \n> Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nReviewed-by: Paul Elder <paul.elder@ideasonboard.com>\n\n> \n> ---\n> \n> Changes in v2:\n> - Added this patch\n> \n> Changes in v3:\n> - Improved commit message\n> - Added constexpr to the contructor\n> - Pass Span by value\n> - Removed initializer of data_ member which was only needed for the\n>   default constructor to be actually constexpr. But Vector is not used\n> as constexpr anywhere, so we can leave that as is (This will fix itself\n> with C++20).\n> ---\n>  include/libcamera/internal/vector.h | 8 ++++++--\n>  src/libcamera/vector.cpp            | 8 ++++++++\n>  2 files changed, 14 insertions(+), 2 deletions(-)\n> \n> diff --git a/include/libcamera/internal/vector.h b/include/libcamera/internal/vector.h\n> index a67a09474204..4e9ef1ee6853 100644\n> --- a/include/libcamera/internal/vector.h\n> +++ b/include/libcamera/internal/vector.h\n> @@ -42,8 +42,12 @@ public:\n>  \n>  \tconstexpr Vector(const std::array<T, Rows> &data)\n>  \t{\n> -\t\tfor (unsigned int i = 0; i < Rows; i++)\n> -\t\t\tdata_[i] = data[i];\n> +\t\tstd::copy(data.begin(), data.end(), data_.begin());\n> +\t}\n> +\n> +\tconstexpr Vector(const Span<const T, Rows> data)\n> +\t{\n> +\t\tstd::copy(data.begin(), data.end(), data_.begin());\n>  \t}\n>  \n>  \tconst T &operator[](size_t i) const\n> diff --git a/src/libcamera/vector.cpp b/src/libcamera/vector.cpp\n> index 85ca2208245a..5567d5b8defb 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 3F67AC3200\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  7 May 2025 15:41:02 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id F302468B35;\n\tWed,  7 May 2025 17:41:01 +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 A720A68ADE\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  7 May 2025 17:41:00 +0200 (CEST)","from pyrite.rasen.tech (unknown\n\t[IPv6:2001:861:3a80:3300:4f2f:8c2c:b3ef:17d4])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 4781DC59;\n\tWed,  7 May 2025 17:40: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=\"MSeig9o2\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1746632449;\n\tbh=ApHiDGUllajExB0g36dzbnb0Zi8zAAy/p0d+dVMADDU=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=MSeig9o2HdqN2i5F2Nt4mAPMGSsv9NjBJrdFtpzQsURMj+ZdUSaILjajX3JfzFArV\n\tmEosVu96wPnKu+/BLcvRdFdHn7XTe85JkQRaigMKytnqAuiYLwYR2c/EvCm8j8x8bb\n\tbaMl8/mVs4AyZN0rCr3cEi7M+ZErlgoyAsLbTOcQ=","Date":"Wed, 7 May 2025 17:40:56 +0200","From":"Paul Elder <paul.elder@ideasonboard.com>","To":"Stefan Klug <stefan.klug@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org,\n\tLaurent Pinchart <laurent.pinchart@ideasonboard.com>","Subject":"Re: [PATCH v3 04/16] libcamera: vector: Add a Span based constructor","Message-ID":"<aBt_CFJGKMga7jvg@pyrite.rasen.tech>","References":"<20250403154925.382973-1-stefan.klug@ideasonboard.com>\n\t<20250403154925.382973-5-stefan.klug@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=us-ascii","Content-Disposition":"inline","In-Reply-To":"<20250403154925.382973-5-stefan.klug@ideasonboard.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>"}}]