[{"id":32231,"web_url":"https://patchwork.libcamera.org/comment/32231/","msgid":"<87ed38hcd2.fsf@redhat.com>","date":"2024-11-18T13:59:05","subject":"Re: [RFC PATCH v2 07/12] ipa: libipa: vector: Add compound\n\tassignment operators","submitter":{"id":177,"url":"https://patchwork.libcamera.org/api/people/177/","name":"Milan Zamazal","email":"mzamazal@redhat.com"},"content":"Laurent Pinchart <laurent.pinchart@ideasonboard.com> writes:\n\n> Extend the Vector class with compound assignment operators that match\n> the binary arithmetic operators.\n>\n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nReviewed-by: Milan Zamazal <mzamazal@redhat.com>\n\n> ---\n>  src/ipa/libipa/vector.cpp | 56 ++++++++++++++++++++++++++++++++++++++\n>  src/ipa/libipa/vector.h   | 57 +++++++++++++++++++++++++++++++++++++++\n>  2 files changed, 113 insertions(+)\n>\n> diff --git a/src/ipa/libipa/vector.cpp b/src/ipa/libipa/vector.cpp\n> index d0e38f402220..a45f08fde493 100644\n> --- a/src/ipa/libipa/vector.cpp\n> +++ b/src/ipa/libipa/vector.cpp\n> @@ -127,6 +127,62 @@ namespace ipa {\n>   * \\return The element-wise division of this vector by \\a scalar\n>   */\n>  \n> +/**\n> + * \\fn Vector::operator+=(Vector const &other)\n> + * \\brief Add \\a other element-wise to this vector\n> + * \\param[in] other The other vector\n> + * \\return This vector\n> + */\n> +\n> +/**\n> + * \\fn Vector::operator+=(T scalar)\n> + * \\brief Add \\a scalar element-wise to this vector\n> + * \\param[in] scalar The scalar\n> + * \\return This vector\n> + */\n> +\n> +/**\n> + * \\fn Vector::operator-=(Vector const &other)\n> + * \\brief Subtract \\a other element-wise from this vector\n> + * \\param[in] other The other vector\n> + * \\return This vector\n> + */\n> +\n> +/**\n> + * \\fn Vector::operator-=(T scalar)\n> + * \\brief Subtract \\a scalar element-wise from this vector\n> + * \\param[in] scalar The scalar\n> + * \\return This vector\n> + */\n> +\n> +/**\n> + * \\fn Vector::operator*=(const Vector &other)\n> + * \\brief Multiply this vector by \\a other element-wise\n> + * \\param[in] other The other vector\n> + * \\return This vector\n> + */\n> +\n> +/**\n> + * \\fn Vector::operator*=(T scalar)\n> + * \\brief Multiply this vector by \\a scalar element-wise\n> + * \\param[in] scalar The scalar\n> + * \\return This vector\n> + */\n> +\n> +/**\n> + * \\fn Vector::operator/=(const Vector &other)\n> + * \\brief Divide this vector by \\a other element-wise\n> + * \\param[in] other The other vector\n> + * \\return This vector\n> + */\n> +\n> +/**\n> + * \\fn Vector::operator/=(T scalar)\n> + * \\brief Divide this vector by \\a scalar element-wise\n> + * \\param[in] scalar The scalar\n> + * \\return This vector\n> + */\n> +\n>  /**\n>   * \\fn Vector::dot(const Vector<T, Rows> &other) const\n>   * \\brief Compute the dot product\n> diff --git a/src/ipa/libipa/vector.h b/src/ipa/libipa/vector.h\n> index dda49b1f468b..722ffc57ea45 100644\n> --- a/src/ipa/libipa/vector.h\n> +++ b/src/ipa/libipa/vector.h\n> @@ -114,6 +114,46 @@ public:\n>  \t\treturn apply(*this, scalar, [](T a, T b) { return a / b; });\n>  \t}\n>  \n> +\tVector &operator+=(const Vector &other)\n> +\t{\n> +\t\treturn apply(other, [](T a, T b) { return a + b; });\n> +\t}\n> +\n> +\tVector &operator+=(T scalar)\n> +\t{\n> +\t\treturn apply(scalar, [](T a, T b) { return a + b; });\n> +\t}\n> +\n> +\tVector &operator-=(const Vector &other)\n> +\t{\n> +\t\treturn apply(other, [](T a, T b) { return a - b; });\n> +\t}\n> +\n> +\tVector &operator-=(T scalar)\n> +\t{\n> +\t\treturn apply(scalar, [](T a, T b) { return a - b; });\n> +\t}\n> +\n> +\tVector &operator*=(const Vector &other)\n> +\t{\n> +\t\treturn apply(other, [](T a, T b) { return a * b; });\n> +\t}\n> +\n> +\tVector &operator*=(T scalar)\n> +\t{\n> +\t\treturn apply(scalar, [](T a, T b) { return a * b; });\n> +\t}\n> +\n> +\tVector &operator/=(const Vector &other)\n> +\t{\n> +\t\treturn apply(other, [](T a, T b) { return a / b; });\n> +\t}\n> +\n> +\tVector &operator/=(T scalar)\n> +\t{\n> +\t\treturn apply(scalar, [](T a, T b) { return a / b; });\n> +\t}\n> +\n>  \tconstexpr T dot(const Vector<T, Rows> &other) const\n>  \t{\n>  \t\tT ret = 0;\n> @@ -206,6 +246,23 @@ private:\n>  \t\treturn result;\n>  \t}\n>  \n> +\tVector &apply(const Vector &other, std::function<T(T, T)> func)\n> +\t{\n> +\t\tauto itOther = other.data_.begin();\n> +\t\tstd::for_each(data_.begin(), data_.end(),\n> +\t\t\t      [&func, &itOther](T &v) { v = func(v, *itOther++); });\n> +\n> +\t\treturn *this;\n> +\t}\n> +\n> +\tVector &apply(T scalar, std::function<T(T, T)> func)\n> +\t{\n> +\t\tstd::for_each(data_.begin(), data_.end(),\n> +\t\t\t      [&func, scalar](T &v) { v = func(v, scalar); });\n> +\n> +\t\treturn *this;\n> +\t}\n> +\n>  \tstd::array<T, Rows> data_;\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 9BE8AC32EA\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 18 Nov 2024 13:59:14 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 3B5E0658D9;\n\tMon, 18 Nov 2024 14:59:14 +0100 (CET)","from us-smtp-delivery-124.mimecast.com\n\t(us-smtp-delivery-124.mimecast.com [170.10.133.124])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id CA33E60532\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 18 Nov 2024 14:59:12 +0100 (CET)","from mail-wr1-f72.google.com (mail-wr1-f72.google.com\n\t[209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS\n\t(version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id\n\tus-mta-362-bojBiA_oOw-B-mUfIrx7wQ-1; Mon, 18 Nov 2024 08:59:10 -0500","by mail-wr1-f72.google.com with SMTP id\n\tffacd0b85a97d-38240d9ed31so818334f8f.3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 18 Nov 2024 05:59:10 -0800 (PST)","from nuthatch ([2a00:102a:400a:489a:ffe9:aa41:63cd:fc2b])\n\tby smtp.gmail.com with ESMTPSA id\n\tffacd0b85a97d-3824770f3dasm3203473f8f.54.2024.11.18.05.59.07\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tMon, 18 Nov 2024 05:59:08 -0800 (PST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=redhat.com header.i=@redhat.com\n\theader.b=\"eoa9sxmA\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1731938351;\n\th=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n\tto:to:cc:cc:mime-version:mime-version:content-type:content-type:\n\tin-reply-to:in-reply-to:references:references;\n\tbh=dCQrQ2cX+Ip4dDE2NfWMS2u8fmfPwKVc3Af/NBipBYs=;\n\tb=eoa9sxmA3BeRNykO964SiDQEGbE1kD7WZE5DDg1AATQkqpDgKPiqm9cJjHgh7ygkjfJNBo\n\tiQ/GfLOHS0C0C60qaTQDCxhOpZ4JBkv9R4LKGe2d0dWfYP0pr2AZY5cCTWNmuJNPQYMeLK\n\tL3EvFE77M1z04s3HkNCSHktZXlmStJM=","X-MC-Unique":"bojBiA_oOw-B-mUfIrx7wQ-1","X-Mimecast-MFC-AGG-ID":"bojBiA_oOw-B-mUfIrx7wQ","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1731938349; x=1732543149;\n\th=mime-version:user-agent:message-id:date:references:in-reply-to\n\t:subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date\n\t:message-id:reply-to;\n\tbh=dCQrQ2cX+Ip4dDE2NfWMS2u8fmfPwKVc3Af/NBipBYs=;\n\tb=YqwBOiCD+0sk/Mgjoa0ldFeygzcbWUjWTh393uavmngOT8Bc70/wv20aUs5uYaVdx9\n\t7dx9Kq7DGWwCTTdzzCz5+rIRN3pbmq++RG3sBWjKc48TCKEdj80ucr3UKDzSlXZwHcVK\n\t9EtHPwiqwFDF9jvUh1MMXRgu+r737eU7NeOnvpwJbSMvP1/wsFX90k+DhfX3d2DkfjlK\n\tFt3NfVrHMyXSpmvXOEL4iJtU31OWn+q2TU6/NU/VawDOWX90NAgT/LM9NKFGSWLvoriC\n\tjarzatAXdglK2bRQDo3dznMorCtBQPSw65L3xLhRf45JZz2m6cy9jwqKfoD4QObHAXaA\n\tR8Jw==","X-Gm-Message-State":"AOJu0YzX/d6zNRrcG1RVXWRIpStIbNJ2AdIYFQlmXQZhHIcuIQsklwZO\n\tdjL5Qke/m75OtBjQqiehKM6a2BDHsCnyMn8XEt7RZM5sJAeb4tzEhXvY5iZsCjlOxdzCZAKaVe4\n\tXtS9ARHVISJyJPbzFLr0RvILWWqYKSUEqAZMewbzLl4GKjNlk2UEXIhQtbIrYJkfvvAqN1euHtn\n\tJqKm9G3w+luLNJY4uHA+j7kWyg0u1r2rpmgobVZKX6cKwAMOCGIgf9Mvk=","X-Received":["by 2002:a05:6000:18af:b0:382:22c6:7bcb with SMTP id\n\tffacd0b85a97d-382258f0d92mr10546939f8f.3.1731938349123; \n\tMon, 18 Nov 2024 05:59:09 -0800 (PST)","by 2002:a05:6000:18af:b0:382:22c6:7bcb with SMTP id\n\tffacd0b85a97d-382258f0d92mr10546916f8f.3.1731938348705; \n\tMon, 18 Nov 2024 05:59:08 -0800 (PST)"],"X-Google-Smtp-Source":"AGHT+IHVUXb+QfdOSW63zUh3AUJULffiVa7w5AuyQLMc2M7G0iWGo/0rSyJzdanuQxFzU2iSd0qpiQ==","From":"Milan Zamazal <mzamazal@redhat.com>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Subject":"Re: [RFC PATCH v2 07/12] ipa: libipa: vector: Add compound\n\tassignment operators","In-Reply-To":"<20241118000738.18977-8-laurent.pinchart@ideasonboard.com>\n\t(Laurent Pinchart's message of \"Mon, 18 Nov 2024 02:07:33 +0200\")","References":"<20241118000738.18977-1-laurent.pinchart@ideasonboard.com>\n\t<20241118000738.18977-8-laurent.pinchart@ideasonboard.com>","Date":"Mon, 18 Nov 2024 14:59:05 +0100","Message-ID":"<87ed38hcd2.fsf@redhat.com>","User-Agent":"Gnus/5.13 (Gnus v5.13)","MIME-Version":"1.0","X-Mimecast-Spam-Score":"0","X-Mimecast-MFC-PROC-ID":"qdbbhYVkFvHd0RtQUo4XF74shJvEKxtNo1s90OgfOmQ_1731938349","X-Mimecast-Originator":"redhat.com","Content-Type":"text/plain","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>"}}]