Patch Detail
Show a patch.
GET /api/1.1/patches/22004/?format=api
{ "id": 22004, "url": "https://patchwork.libcamera.org/api/1.1/patches/22004/?format=api", "web_url": "https://patchwork.libcamera.org/patch/22004/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20241119121928.30939-7-laurent.pinchart@ideasonboard.com>", "date": "2024-11-19T12:19:17", "name": "[v4,06/17] ipa: libipa: vector: Generalize arithmetic operators", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": false, "hash": "dac597a11596178ef0e753c1f5e751bc91012d19", "submitter": { "id": 2, "url": "https://patchwork.libcamera.org/api/1.1/people/2/?format=api", "name": "Laurent Pinchart", "email": "laurent.pinchart@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/22004/mbox/", "series": [ { "id": 4804, "url": "https://patchwork.libcamera.org/api/1.1/series/4804/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4804", "date": "2024-11-19T12:19:11", "name": "Improve linear algebra helpers in libipa", "version": 4, "mbox": "https://patchwork.libcamera.org/series/4804/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/22004/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/22004/checks/", "tags": {}, "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 8AB4DC32F1\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 19 Nov 2024 12:20:01 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id EEB8965F1E;\n\tTue, 19 Nov 2024 13:20:00 +0100 (CET)", "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id E393E65F1C\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 19 Nov 2024 13:19:57 +0100 (CET)", "from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi\n\t[81.175.209.231])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 4B2C91211\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 19 Nov 2024 13:19:40 +0100 (CET)" ], "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"Gji7WaNR\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1732018780;\n\tbh=fp0lTBlk5VDfOf4pZxT+cewG2ES+5ye9ffGTAWYZbKY=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=Gji7WaNR0v03+s308Z2pC9Ysk3Kp8PVxznO9iHOBmzoGvqkzU2fSxPaCq46wPZZnv\n\tTMrLvaq1OjmdbnNXuzEKVDWNKG9xXobCHh5obDJgbffIKZ0Z3WL1WLIuWI0n03DiS1\n\tZzN5n360Ub5pdJucrV7FB/JMAZQhQeg8dzUjsGIg=", "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Subject": "[PATCH v4 06/17] ipa: libipa: vector: Generalize arithmetic\n\toperators", "Date": "Tue, 19 Nov 2024 14:19:17 +0200", "Message-ID": "<20241119121928.30939-7-laurent.pinchart@ideasonboard.com>", "X-Mailer": "git-send-email 2.45.2", "In-Reply-To": "<20241119121928.30939-1-laurent.pinchart@ideasonboard.com>", "References": "<20241119121928.30939-1-laurent.pinchart@ideasonboard.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "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>" }, "content": "Instead of hand-coding all arithmetic operators, implement them based on\na generic apply() function that takes an operator-specific binary\noperators. This will simplify adding missing arithmetic operators.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\nReviewed-by: Milan Zamazal <mzamazal@redhat.com>\n---\nChanges since v3:\n\n- Replace std::function with a templated argument\n\nChanges since v2:\n\n- Include <algorithm>\n- Use std::plus, std::minus, std::multiplies and std::divides\n---\n src/ipa/libipa/vector.h | 52 +++++++++++++++++++++++++----------------\n 1 file changed, 32 insertions(+), 20 deletions(-)", "diff": "diff --git a/src/ipa/libipa/vector.h b/src/ipa/libipa/vector.h\nindex b4eb19707063..10e16d41aa8b 100644\n--- a/src/ipa/libipa/vector.h\n+++ b/src/ipa/libipa/vector.h\n@@ -6,8 +6,10 @@\n */\n #pragma once\n \n+#include <algorithm>\n #include <array>\n #include <cmath>\n+#include <functional>\n #include <optional>\n #include <ostream>\n \n@@ -70,36 +72,24 @@ public:\n \t\treturn ret;\n \t}\n \n-\tconstexpr Vector<T, Rows> operator-(const Vector<T, Rows> &other) const\n+\tconstexpr Vector operator-(const Vector &other) const\n \t{\n-\t\tVector<T, Rows> ret;\n-\t\tfor (unsigned int i = 0; i < Rows; i++)\n-\t\t\tret[i] = data_[i] - other[i];\n-\t\treturn ret;\n+\t\treturn apply(*this, other, std::minus<>{});\n \t}\n \n-\tconstexpr Vector<T, Rows> operator+(const Vector<T, Rows> &other) const\n+\tconstexpr Vector operator+(const Vector &other) const\n \t{\n-\t\tVector<T, Rows> ret;\n-\t\tfor (unsigned int i = 0; i < Rows; i++)\n-\t\t\tret[i] = data_[i] + other[i];\n-\t\treturn ret;\n+\t\treturn apply(*this, other, std::plus<>{});\n \t}\n \n-\tconstexpr Vector<T, Rows> operator*(T factor) const\n+\tconstexpr Vector operator*(T factor) const\n \t{\n-\t\tVector<T, Rows> ret;\n-\t\tfor (unsigned int i = 0; i < Rows; i++)\n-\t\t\tret[i] = data_[i] * factor;\n-\t\treturn ret;\n+\t\treturn apply(*this, factor, std::multiplies<>{});\n \t}\n \n-\tconstexpr Vector<T, Rows> operator/(T factor) const\n+\tconstexpr Vector operator/(T factor) const\n \t{\n-\t\tVector<T, Rows> ret;\n-\t\tfor (unsigned int i = 0; i < Rows; i++)\n-\t\t\tret[i] = data_[i] / factor;\n-\t\treturn ret;\n+\t\treturn apply(*this, factor, std::divides<>{});\n \t}\n \n \tconstexpr T dot(const Vector<T, Rows> &other) const\n@@ -174,6 +164,28 @@ public:\n \t}\n \n private:\n+\ttemplate<class BinaryOp>\n+\tstatic constexpr Vector apply(const Vector &lhs, const Vector &rhs, BinaryOp op)\n+\t{\n+\t\tVector result;\n+\t\tstd::transform(lhs.data_.begin(), lhs.data_.end(),\n+\t\t\t rhs.data_.begin(), result.data_.begin(),\n+\t\t\t op);\n+\n+\t\treturn result;\n+\t}\n+\n+\ttemplate<class BinaryOp>\n+\tstatic constexpr Vector apply(const Vector &lhs, T rhs, BinaryOp op)\n+\t{\n+\t\tVector result;\n+\t\tstd::transform(lhs.data_.begin(), lhs.data_.end(),\n+\t\t\t result.data_.begin(),\n+\t\t\t [&op, rhs](T v) { return op(v, rhs); });\n+\n+\t\treturn result;\n+\t}\n+\n \tstd::array<T, Rows> data_;\n };\n \n", "prefixes": [ "v4", "06/17" ] }