From patchwork Mon Nov 18 22:16:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 21968 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 7341BC32F0 for ; Mon, 18 Nov 2024 22:16:50 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 815A465ED9; Mon, 18 Nov 2024 23:16:49 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="aI4wdJlB"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 361EF65902 for ; Mon, 18 Nov 2024 23:16:39 +0100 (CET) Received: from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi [81.175.209.231]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 2DC0F6DE for ; Mon, 18 Nov 2024 23:16:22 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1731968182; bh=WZPXj2Nuz3Z3KOJiIMd6JFdDT9rTF9Sb3WJ1nfRI+jI=; h=From:To:Subject:Date:In-Reply-To:References:From; b=aI4wdJlBRpjWh+nF04xxyKCQ9IXrHH+2gPQlqYrx+cWLZfg8QL1pXWjcRUq14NgnW Y+WrzAbYPck6baUIsFSi5y5R6XoEWI6OgpgsfEP3+Rf4JQRT3jK85BMzqX0BnvpWHu R9gFCEPNbqxD6GAq8pop/Hd+9ZHMMWKUJlnUK3sE= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Subject: [PATCH v3 08/17] ipa: libipa: vector: Add compound assignment operators Date: Tue, 19 Nov 2024 00:16:09 +0200 Message-ID: <20241118221618.13953-9-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241118221618.13953-1-laurent.pinchart@ideasonboard.com> References: <20241118221618.13953-1-laurent.pinchart@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" Extend the Vector class with compound assignment operators that match the binary arithmetic operators. Signed-off-by: Laurent Pinchart Reviewed-by: Milan Zamazal --- Changes since v2: - Use std::plus, std::minus, std::multiplies and std::divides --- src/ipa/libipa/vector.cpp | 56 ++++++++++++++++++++++++++++++++++++++ src/ipa/libipa/vector.h | 57 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 113 insertions(+) diff --git a/src/ipa/libipa/vector.cpp b/src/ipa/libipa/vector.cpp index d8f7ce951d60..64ffcf5036a4 100644 --- a/src/ipa/libipa/vector.cpp +++ b/src/ipa/libipa/vector.cpp @@ -133,6 +133,62 @@ namespace ipa { * \return The element-wise division of this vector by \a scalar */ +/** + * \fn Vector::operator+=(Vector const &other) + * \brief Add \a other element-wise to this vector + * \param[in] other The other vector + * \return This vector + */ + +/** + * \fn Vector::operator+=(T scalar) + * \brief Add \a scalar element-wise to this vector + * \param[in] scalar The scalar + * \return This vector + */ + +/** + * \fn Vector::operator-=(Vector const &other) + * \brief Subtract \a other element-wise from this vector + * \param[in] other The other vector + * \return This vector + */ + +/** + * \fn Vector::operator-=(T scalar) + * \brief Subtract \a scalar element-wise from this vector + * \param[in] scalar The scalar + * \return This vector + */ + +/** + * \fn Vector::operator*=(const Vector &other) + * \brief Multiply this vector by \a other element-wise + * \param[in] other The other vector + * \return This vector + */ + +/** + * \fn Vector::operator*=(T scalar) + * \brief Multiply this vector by \a scalar element-wise + * \param[in] scalar The scalar + * \return This vector + */ + +/** + * \fn Vector::operator/=(const Vector &other) + * \brief Divide this vector by \a other element-wise + * \param[in] other The other vector + * \return This vector + */ + +/** + * \fn Vector::operator/=(T scalar) + * \brief Divide this vector by \a scalar element-wise + * \param[in] scalar The scalar + * \return This vector + */ + /** * \fn Vector::dot(const Vector &other) const * \brief Compute the dot product diff --git a/src/ipa/libipa/vector.h b/src/ipa/libipa/vector.h index 88f2a03fe579..15f511653b60 100644 --- a/src/ipa/libipa/vector.h +++ b/src/ipa/libipa/vector.h @@ -120,6 +120,46 @@ public: return apply(*this, scalar, std::divides<>{}); } + Vector &operator+=(const Vector &other) + { + return apply(other, [](T a, T b) { return a + b; }); + } + + Vector &operator+=(T scalar) + { + return apply(scalar, [](T a, T b) { return a + b; }); + } + + Vector &operator-=(const Vector &other) + { + return apply(other, [](T a, T b) { return a - b; }); + } + + Vector &operator-=(T scalar) + { + return apply(scalar, [](T a, T b) { return a - b; }); + } + + Vector &operator*=(const Vector &other) + { + return apply(other, [](T a, T b) { return a * b; }); + } + + Vector &operator*=(T scalar) + { + return apply(scalar, [](T a, T b) { return a * b; }); + } + + Vector &operator/=(const Vector &other) + { + return apply(other, [](T a, T b) { return a / b; }); + } + + Vector &operator/=(T scalar) + { + return apply(scalar, [](T a, T b) { return a / b; }); + } + constexpr T dot(const Vector &other) const { T ret = 0; @@ -212,6 +252,23 @@ private: return result; } + Vector &apply(const Vector &other, std::function func) + { + auto itOther = other.data_.begin(); + std::for_each(data_.begin(), data_.end(), + [&func, &itOther](T &v) { v = func(v, *itOther++); }); + + return *this; + } + + Vector &apply(T scalar, std::function func) + { + std::for_each(data_.begin(), data_.end(), + [&func, scalar](T &v) { v = func(v, scalar); }); + + return *this; + } + std::array data_; };