From patchwork Mon Feb 17 10:01:43 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Klug X-Patchwork-Id: 22788 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 EEEE6C327D for ; Mon, 17 Feb 2025 10:02:19 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7D3736866D; Mon, 17 Feb 2025 11:02:19 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="P0SYrnt/"; 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 9A84668665 for ; Mon, 17 Feb 2025 11:02:13 +0100 (CET) Received: from ideasonboard.com (unknown [IPv6:2a00:6020:448c:6c00:b47f:e20a:c4c7:ece1]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 3DD24E29; Mon, 17 Feb 2025 11:00:52 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1739786452; bh=918sfwA7Mb+3uVAMU/CSzykUjmZSib/6jaJgceZLH1c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=P0SYrnt/sAQ+eoMPsIDcf5VFZFKJPJdfieToHktL+peZ72ZM7mdUc+IG7J4rw90Tc UwXOQUDVTt7m2IbuKfCkNmdImua00ja4jrMwx/1oxvPDfYcqcXRWXaHl9LqeBNEjK6 Zor6f7m0heF77ifL0ANUEStW9pSgetPhQKMtxfk4= From: Stefan Klug To: libcamera-devel@lists.libcamera.org Cc: Stefan Klug Subject: [PATCH 02/10] libcamera: vector: Add cast function Date: Mon, 17 Feb 2025 11:01:43 +0100 Message-ID: <20250217100203.297894-3-stefan.klug@ideasonboard.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250217100203.297894-1-stefan.klug@ideasonboard.com> References: <20250217100203.297894-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" The libcamera code base uses matrices and vectors of type float and double. Add a cast function to easily convert between different underlying types. Signed-off-by: Stefan Klug --- include/libcamera/internal/vector.h | 9 +++++++++ src/libcamera/vector.cpp | 10 ++++++++++ 2 files changed, 19 insertions(+) diff --git a/include/libcamera/internal/vector.h b/include/libcamera/internal/vector.h index a67a09474204..c8f9a8c412f2 100644 --- a/include/libcamera/internal/vector.h +++ b/include/libcamera/internal/vector.h @@ -243,6 +243,15 @@ public: return std::accumulate(data_.begin(), data_.end(), R{}); } + template + Vector cast() const + { + Vector ret; + for (unsigned int i = 0; i < Rows; i++) + ret[i] = static_cast(data_[i]); + return ret; + } + private: template static constexpr Vector apply(const Vector &lhs, const Vector &rhs, BinaryOp op) diff --git a/src/libcamera/vector.cpp b/src/libcamera/vector.cpp index 85ca2208245a..57dcef8bf3d8 100644 --- a/src/libcamera/vector.cpp +++ b/src/libcamera/vector.cpp @@ -202,6 +202,16 @@ LOG_DEFINE_CATEGORY(Vector) * \return The element-wise maximum of this vector and \a scalar */ +/** + * \fn template Vector Vector::cast() const + * \brief Cast the vector to a different type + * + * This function returns a new vector with the same size and values but a + * different type. + * + * \return The new vector + */ + /** * \fn Vector::dot(const Vector &other) const * \brief Compute the dot product