[{"id":34097,"web_url":"https://patchwork.libcamera.org/comment/34097/","msgid":"<174617166031.1586992.10958435303373239020@ping.linuxembedded.co.uk>","date":"2025-05-02T07:41:00","subject":"Re: [PATCH v3 02/16] libcamera: matrix: Make most functions\n\tconstexpr","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:07)\n> By zero-initializing the data_ member we can make most functions\n> constexpr which will come in handy in upcoming patches. Note that this\n> is due to C++17. In C++20 we will be able to leave data_ uninitialized\n> for constexpr.  The Matrix(std::array) version of the constructor can\n> not be constexpr because std::copy only became constexpr in C++20.\n> \n> Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n> \n> ---\n> \n> Changes in v2:\n> - Added this patch\n> \n> Changes in v3:\n> - Added comment on data_ initializer\n> ---\n>  include/libcamera/internal/matrix.h | 20 ++++++++++++--------\n>  1 file changed, 12 insertions(+), 8 deletions(-)\n> \n> diff --git a/include/libcamera/internal/matrix.h b/include/libcamera/internal/matrix.h\n> index b9c3d41ef855..512c1162c3bc 100644\n> --- a/include/libcamera/internal/matrix.h\n> +++ b/include/libcamera/internal/matrix.h\n> @@ -25,9 +25,8 @@ class Matrix\n>         static_assert(std::is_arithmetic_v<T>, \"Matrix type must be arithmetic\");\n>  \n>  public:\n> -       Matrix()\n> +       constexpr Matrix()\n>         {\n> -               data_.fill(static_cast<T>(0));\n>         }\n>  \n>         Matrix(const std::array<T, Rows * Cols> &data)\n> @@ -35,7 +34,7 @@ public:\n>                 std::copy(data.begin(), data.end(), data_.begin());\n>         }\n>  \n> -       static Matrix identity()\n> +       static constexpr Matrix identity()\n>         {\n>                 Matrix ret;\n>                 for (size_t i = 0; i < std::min(Rows, Cols); i++)\n> @@ -63,14 +62,14 @@ public:\n>                 return out.str();\n>         }\n>  \n> -       Span<const T, Rows * Cols> data() const { return data_; }\n> +       constexpr Span<const T, Rows * Cols> data() const { return data_; }\n>  \n> -       Span<const T, Cols> operator[](size_t i) const\n> +       constexpr Span<const T, Cols> operator[](size_t i) const\n>         {\n>                 return Span<const T, Cols>{ &data_.data()[i * Cols], Cols };\n>         }\n>  \n> -       Span<T, Cols> operator[](size_t i)\n> +       constexpr Span<T, Cols> operator[](size_t i)\n>         {\n>                 return Span<T, Cols>{ &data_.data()[i * Cols], Cols };\n>         }\n> @@ -88,7 +87,12 @@ public:\n>         }\n>  \n>  private:\n> -       std::array<T, Rows * Cols> data_;\n> +       /*\n> +        * \\todo The initializer is only necessary for the constructor to be\n> +        * constexpr in C++17. Remove the initializer as soon as we are on\n> +        * C++20.\n> +        */\n> +       std::array<T, Rows * Cols> data_ = {};\n>  };\n>  \n>  #ifndef __DOXYGEN__\n> @@ -141,7 +145,7 @@ constexpr Matrix<T, R1, C2> operator*(const Matrix<T, R1, C1> &m1, const Matrix<\n>  }\n>  \n>  template<typename T, unsigned int Rows, unsigned int Cols>\n> -Matrix<T, Rows, Cols> operator+(const Matrix<T, Rows, Cols> &m1, const Matrix<T, Rows, Cols> &m2)\n> +constexpr Matrix<T, Rows, Cols> operator+(const Matrix<T, Rows, Cols> &m1, const Matrix<T, Rows, Cols> &m2)\n>  {\n>         Matrix<T, Rows, Cols> result;\n>  \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 65993BE08B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri,  2 May 2025 07:41:05 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 8417168ACB;\n\tFri,  2 May 2025 09:41:04 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 11BC668ACB\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  2 May 2025 09:41:03 +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 4BC2C353;\n\tFri,  2 May 2025 09:40:55 +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=\"P3S9UTyi\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1746171655;\n\tbh=qpQXMcxsxMMZmPrXm0OQuBF9W50E0Rr24llU6L4bI00=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=P3S9UTyiLEKmlbk9smdKYhS3dNTfNWrPOG/GE9V7i0vg9WuGS7o5sUY5wZG9CEjjJ\n\tckRqPf7xhDIELOjvM7lctM7QtpZRYDZjDx0LQtuRUMEg+L7CTnz0V1K+F2uAoDCpDI\n\tT3pINGNvojZOGbdNfY9aUAVf+PnjZdzufFPsggU4=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20250403154925.382973-3-stefan.klug@ideasonboard.com>","References":"<20250403154925.382973-1-stefan.klug@ideasonboard.com>\n\t<20250403154925.382973-3-stefan.klug@ideasonboard.com>","Subject":"Re: [PATCH v3 02/16] libcamera: matrix: Make most functions\n\tconstexpr","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:41:00 +0100","Message-ID":"<174617166031.1586992.10958435303373239020@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":34139,"web_url":"https://patchwork.libcamera.org/comment/34139/","msgid":"<aBt-sYHRC1jBtFtT@pyrite.rasen.tech>","date":"2025-05-07T15:39:29","subject":"Re: [PATCH v3 02/16] libcamera: matrix: Make most functions\n\tconstexpr","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:07PM +0200, Stefan Klug wrote:\n> By zero-initializing the data_ member we can make most functions\n> constexpr which will come in handy in upcoming patches. Note that this\n> is due to C++17. In C++20 we will be able to leave data_ uninitialized\n> for constexpr.  The Matrix(std::array) version of the constructor can\n> not be constexpr because std::copy only became constexpr in C++20.\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> - Added comment on data_ initializer\n> ---\n>  include/libcamera/internal/matrix.h | 20 ++++++++++++--------\n>  1 file changed, 12 insertions(+), 8 deletions(-)\n> \n> diff --git a/include/libcamera/internal/matrix.h b/include/libcamera/internal/matrix.h\n> index b9c3d41ef855..512c1162c3bc 100644\n> --- a/include/libcamera/internal/matrix.h\n> +++ b/include/libcamera/internal/matrix.h\n> @@ -25,9 +25,8 @@ class Matrix\n>  \tstatic_assert(std::is_arithmetic_v<T>, \"Matrix type must be arithmetic\");\n>  \n>  public:\n> -\tMatrix()\n> +\tconstexpr Matrix()\n>  \t{\n> -\t\tdata_.fill(static_cast<T>(0));\n>  \t}\n>  \n>  \tMatrix(const std::array<T, Rows * Cols> &data)\n> @@ -35,7 +34,7 @@ public:\n>  \t\tstd::copy(data.begin(), data.end(), data_.begin());\n>  \t}\n>  \n> -\tstatic Matrix identity()\n> +\tstatic constexpr Matrix identity()\n>  \t{\n>  \t\tMatrix ret;\n>  \t\tfor (size_t i = 0; i < std::min(Rows, Cols); i++)\n> @@ -63,14 +62,14 @@ public:\n>  \t\treturn out.str();\n>  \t}\n>  \n> -\tSpan<const T, Rows * Cols> data() const { return data_; }\n> +\tconstexpr Span<const T, Rows * Cols> data() const { return data_; }\n>  \n> -\tSpan<const T, Cols> operator[](size_t i) const\n> +\tconstexpr Span<const T, Cols> operator[](size_t i) const\n>  \t{\n>  \t\treturn Span<const T, Cols>{ &data_.data()[i * Cols], Cols };\n>  \t}\n>  \n> -\tSpan<T, Cols> operator[](size_t i)\n> +\tconstexpr Span<T, Cols> operator[](size_t i)\n>  \t{\n>  \t\treturn Span<T, Cols>{ &data_.data()[i * Cols], Cols };\n>  \t}\n> @@ -88,7 +87,12 @@ public:\n>  \t}\n>  \n>  private:\n> -\tstd::array<T, Rows * Cols> data_;\n> +\t/*\n> +\t * \\todo The initializer is only necessary for the constructor to be\n> +\t * constexpr in C++17. Remove the initializer as soon as we are on\n> +\t * C++20.\n> +\t */\n> +\tstd::array<T, Rows * Cols> data_ = {};\n>  };\n>  \n>  #ifndef __DOXYGEN__\n> @@ -141,7 +145,7 @@ constexpr Matrix<T, R1, C2> operator*(const Matrix<T, R1, C1> &m1, const Matrix<\n>  }\n>  \n>  template<typename T, unsigned int Rows, unsigned int Cols>\n> -Matrix<T, Rows, Cols> operator+(const Matrix<T, Rows, Cols> &m1, const Matrix<T, Rows, Cols> &m2)\n> +constexpr Matrix<T, Rows, Cols> operator+(const Matrix<T, Rows, Cols> &m1, const Matrix<T, Rows, Cols> &m2)\n>  {\n>  \tMatrix<T, Rows, Cols> result;\n>  \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 2FD52C3200\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  7 May 2025 15:39:36 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 263B968B32;\n\tWed,  7 May 2025 17:39:35 +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 5CE0C68ADE\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  7 May 2025 17:39:33 +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 B6949C59;\n\tWed,  7 May 2025 17:39:21 +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=\"pVAaxFwV\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1746632361;\n\tbh=Gla1/atWjmWRRlPRUDwb8gy8HeXsOM/4IXPM5V4t7s0=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=pVAaxFwVlg3gtzETR/0onelZr6fYzpNOwGyjYKkLLBETMote1msnlOd3JW0KSR+da\n\t0hpj2WFnx/jK1rATDiDtlpUeKDPbeEvjzuKEAr+u+VaNF0qyGqbg+FbLug0Axeu322\n\t9mQjVPZ39QnJb7dpGLugNRmbvm01y6MhbJ5T/0IE=","Date":"Wed, 7 May 2025 17:39:29 +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 02/16] libcamera: matrix: Make most functions\n\tconstexpr","Message-ID":"<aBt-sYHRC1jBtFtT@pyrite.rasen.tech>","References":"<20250403154925.382973-1-stefan.klug@ideasonboard.com>\n\t<20250403154925.382973-3-stefan.klug@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=us-ascii","Content-Disposition":"inline","In-Reply-To":"<20250403154925.382973-3-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>"}}]