From patchwork Wed Mar 19 16:11:07 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Klug X-Patchwork-Id: 22980 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 9DC3EC32FE for ; Wed, 19 Mar 2025 16:12:04 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 5DF3A68956; Wed, 19 Mar 2025 17:12:04 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="OQxsZKpU"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id F11C768945 for ; Wed, 19 Mar 2025 17:12:02 +0100 (CET) Received: from ideasonboard.com (unknown [IPv6:2a00:6020:448c:6c00:760:e5ca:4814:99c7]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 14DB58FA; Wed, 19 Mar 2025 17:10:20 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1742400620; bh=GX+nwPV4aQPLp2kqpsBwud/hZduuE8qLSo/rMFQK/ZY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OQxsZKpUf2yAoodyn6lmrnezgcjoi8Aqv3Sp38SGUHUHH4upsddVryasTDhXrCLHM CFihc3UbWGb9I3Id5A1Tw47daG5R1SL2vDFQNckGhScHMU3wqOoZy8Elsg23uDhsA8 VyPtjJML42rtDT9WU+D24W3VTio5+Y134o4oOQeg= From: Stefan Klug To: libcamera-devel@lists.libcamera.org Cc: Stefan Klug Subject: [PATCH v2 02/17] libcamera: matrix: Make most functions constexpr Date: Wed, 19 Mar 2025 17:11:07 +0100 Message-ID: <20250319161152.63625-3-stefan.klug@ideasonboard.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250319161152.63625-1-stefan.klug@ideasonboard.com> References: <20250319161152.63625-1-stefan.klug@ideasonboard.com> MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" By zero-initializing the data_ member we can make most functions constexpr which will come in handy in upcoming patches. Note that this is due to C++17. In C++20 we will be able to leave data_ unintialized for constexpr. The Matrix(std::array) version of the constructor can not be constexpr because std::copy only became constexpr in C++20. Signed-off-by: Stefan Klug --- Changes in v2: - Added this patch --- include/libcamera/internal/matrix.h | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/include/libcamera/internal/matrix.h b/include/libcamera/internal/matrix.h index 8399be583f28..2e7929e9060c 100644 --- a/include/libcamera/internal/matrix.h +++ b/include/libcamera/internal/matrix.h @@ -25,9 +25,8 @@ class Matrix static_assert(std::is_arithmetic_v, "Matrix type must be arithmetic"); public: - Matrix() + constexpr Matrix() { - data_.fill(static_cast(0)); } Matrix(const std::array &data) @@ -35,7 +34,7 @@ public: std::copy(data.begin(), data.end(), data_.begin()); } - static Matrix identity() + static constexpr Matrix identity() { Matrix ret; for (size_t i = 0; i < std::min(Rows, Cols); i++) @@ -63,14 +62,14 @@ public: return out.str(); } - Span data() const { return data_; } + constexpr Span data() const { return data_; } - Span operator[](size_t i) const + constexpr Span operator[](size_t i) const { return Span{ &data_.data()[i * Cols], Cols }; } - Span operator[](size_t i) + constexpr Span operator[](size_t i) { return Span{ &data_.data()[i * Cols], Cols }; } @@ -85,7 +84,7 @@ public: } private: - std::array data_; + std::array data_{}; }; template @@ -130,7 +129,7 @@ constexpr Matrix operator*(const Matrix &m1, const Matrix< } template -Matrix operator+(const Matrix &m1, const Matrix &m2) +constexpr Matrix operator+(const Matrix &m1, const Matrix &m2) { Matrix result;