From patchwork Sun Nov 17 22:17:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 21936 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 4424DC32DF for ; Sun, 17 Nov 2024 22:17:45 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7B60C658B7; Sun, 17 Nov 2024 23:17:44 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="Sr+6yPy9"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5898C658AD for ; Sun, 17 Nov 2024 23:17:30 +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 0B3447FE for ; Sun, 17 Nov 2024 23:17:13 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1731881834; bh=9MiINevDfChBdv5qVOrHFrk3D/8r4l9JnlU7vz9WSx8=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Sr+6yPy9IrQICMMnT3hftXw16c9TE1LRPKOKuXij/cS1aTsgPHK/UFTo2mMqymQm5 Js4OVgUQmyLJW2iEBaqVDZHf6lgKUUa8KSkcY5WK20sWrWa0lTWqQtQq9gJa8O8ueq s8b9ucZfszlSZPATVH1v3VgaG50WRvNTjD+NDBwk= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Subject: [RFC PATCH 06/11] ipa: libipa: vector: Add missing binary arithemtic operators Date: Mon, 18 Nov 2024 00:17:07 +0200 Message-ID: <20241117221712.29616-7-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241117221712.29616-1-laurent.pinchart@ideasonboard.com> References: <20241117221712.29616-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" The Vector class defines multiple element-wise arithmetic operators between vectors or between a vector and a scalar. A few variants are missing. Add them. Signed-off-by: Laurent Pinchart --- src/ipa/libipa/vector.cpp | 54 +++++++++++++++++++++++++++++---------- src/ipa/libipa/vector.h | 38 ++++++++++++++++++++------- 2 files changed, 70 insertions(+), 22 deletions(-) diff --git a/src/ipa/libipa/vector.cpp b/src/ipa/libipa/vector.cpp index b2794c200b05..d0e38f402220 100644 --- a/src/ipa/libipa/vector.cpp +++ b/src/ipa/libipa/vector.cpp @@ -71,32 +71,60 @@ namespace ipa { * \return The negated vector */ +/** + * \fn Vector::operator+(Vector const &other) const + * \brief Calculate the sum of this vector and \a other element-wise + * \param[in] other The other vector + * \return The element-wise sum of this vector and \a other + */ + +/** + * \fn Vector::operator+(T scalar) const + * \brief Calculate the sum of this vector and \a scalar element-wise + * \param[in] scalar The scalar + * \return The element-wise sum of this vector and \a other + */ + /** * \fn Vector::operator-(Vector const &other) const - * \brief Subtract one vector from another + * \brief Calculate the difference of this vector and \a other element-wise * \param[in] other The other vector - * \return The difference of \a other from this vector + * \return The element-wise subtraction of \a other from this vector */ /** - * \fn Vector::operator+() - * \brief Add two vectors together + * \fn Vector::operator-(T scalar) const + * \brief Calculate the difference of this vector and \a scalar element-wise + * \param[in] scalar The scalar + * \return The element-wise subtraction of \a scalar from this vector + */ + +/** + * \fn Vector::operator*(const Vector &other) const + * \brief Calculate the product of this vector and \a other element-wise * \param[in] other The other vector - * \return The sum of the two vectors + * \return The element-wise product of this vector and \a other */ /** - * \fn Vector::operator*(T factor) const - * \brief Multiply the vector by a scalar - * \param[in] factor The factor - * \return The vector multiplied by \a factor + * \fn Vector::operator*(T scalar) const + * \brief Calculate the product of this vector and \a scalar element-wise + * \param[in] scalar The scalar + * \return The element-wise product of this vector and \a scalar */ /** - * \fn Vector::operator/() - * \brief Divide the vector by a scalar - * \param[in] factor The factor - * \return The vector divided by \a factor + * \fn Vector::operator/(const Vector &other) const + * \brief Calculate the quotient of this vector and \a other element-wise + * \param[in] other The other vector + * \return The element-wise division of this vector by \a other + */ + +/** + * \fn Vector::operator/(T scalar) const + * \brief Calculate the quotient of this vector and \a scalar element-wise + * \param[in] scalar The scalar + * \return The element-wise division of this vector by \a scalar */ /** diff --git a/src/ipa/libipa/vector.h b/src/ipa/libipa/vector.h index 8c4edfbaf85f..dda49b1f468b 100644 --- a/src/ipa/libipa/vector.h +++ b/src/ipa/libipa/vector.h @@ -74,24 +74,44 @@ public: return ret; } - constexpr Vector operator-(const Vector &other) const - { - return apply(*this, other, [](T a, T b) { return a - b; }); - } - constexpr Vector operator+(const Vector &other) const { return apply(*this, other, [](T a, T b) { return a + b; }); } - constexpr Vector operator*(T factor) const + constexpr Vector operator+(T scalar) const { - return apply(*this, factor, [](T a, T b) { return a * b; }); + return apply(*this, scalar, [](T a, T b) { return a + b; }); } - constexpr Vector operator/(T factor) const + constexpr Vector operator-(const Vector &other) const { - return apply(*this, factor, [](T a, T b) { return a / b; }); + return apply(*this, other, [](T a, T b) { return a - b; }); + } + + constexpr Vector operator-(T scalar) const + { + return apply(*this, scalar, [](T a, T b) { return a - b; }); + } + + constexpr Vector operator*(const Vector &other) const + { + return apply(*this, other, [](T a, T b) { return a * b; }); + } + + constexpr Vector operator*(T scalar) const + { + return apply(*this, scalar, [](T a, T b) { return a * b; }); + } + + constexpr Vector operator/(const Vector &other) const + { + return apply(*this, other, [](T a, T b) { return a / b; }); + } + + constexpr Vector operator/(T scalar) const + { + return apply(*this, scalar, [](T a, T b) { return a / b; }); } constexpr T dot(const Vector &other) const