Patch Detail
Show a patch.
GET /api/patches/20256/?format=api
{ "id": 20256, "url": "https://patchwork.libcamera.org/api/patches/20256/?format=api", "web_url": "https://patchwork.libcamera.org/patch/20256/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/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": "<20240611132430.404814-2-paul.elder@ideasonboard.com>", "date": "2024-06-11T13:24:27", "name": "[v8,1/4] ipa: libipa: Add Vector class", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": false, "hash": "75633b5433ee919ea844a027cb73cd15dc800f43", "submitter": { "id": 17, "url": "https://patchwork.libcamera.org/api/people/17/?format=api", "name": "Paul Elder", "email": "paul.elder@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/20256/mbox/", "series": [ { "id": 4382, "url": "https://patchwork.libcamera.org/api/series/4382/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4382", "date": "2024-06-11T13:24:26", "name": "ipa: Move Pwl from Raspberry Pi to libipa", "version": 8, "mbox": "https://patchwork.libcamera.org/series/4382/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/20256/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/20256/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 73AB1C31E9\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 11 Jun 2024 13:24:50 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 2281665467;\n\tTue, 11 Jun 2024 15:24:50 +0200 (CEST)", "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id DBE1F61A26\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 11 Jun 2024 15:24:47 +0200 (CEST)", "from neptunite.hamster-moth.ts.net\n\t(h175-177-049-156.catv02.itscom.jp [175.177.49.156])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 8CD98183;\n\tTue, 11 Jun 2024 15:24:32 +0200 (CEST)" ], "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"IaTHvhWt\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1718112275;\n\tbh=3QZKjdqSUDTBwBEY8g41XX4YNUw748tdtyr6zlMTklE=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=IaTHvhWt0jyqmfsbe6ZCO4pkgKvX97nKCsdEpQM9Nrq51fJ8G2M4+NlEYfqfqJX2s\n\treacxJ9C/X9utP6JYm2t3teYN86H/vqYu1tfS7ba6x3m0zg+1iabcwwcZrtwrYQjqH\n\tZoTSAaM5sDjhZVB8GCqc37uYK6/nVe/5FX3fWyTU=", "From": "Paul Elder <paul.elder@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Cc": "Paul Elder <paul.elder@ideasonboard.com>,\n\tStefan Klug <stefan.klug@ideasonboard.com>,\n\tKieran Bingham <kieran.bingham@ideasonboard.com>", "Subject": "[PATCH v8 1/4] ipa: libipa: Add Vector class", "Date": "Tue, 11 Jun 2024 22:24:27 +0900", "Message-Id": "<20240611132430.404814-2-paul.elder@ideasonboard.com>", "X-Mailer": "git-send-email 2.39.2", "In-Reply-To": "<20240611132430.404814-1-paul.elder@ideasonboard.com>", "References": "<20240611132430.404814-1-paul.elder@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": "Add a vector class to libipa. The original purpose of this is to replace\nthe floating-point Point class that Raspberry Pi used in their Pwl, as\nthat implementation of Point seemed more akin to a Vector than a Point.\n\nThis is added to libipa instead of to geometry.h to avoid public API\nissues, plus this is not expected to be needed by applications.\n\nSigned-off-by: Paul Elder <paul.elder@ideasonboard.com>\nReviewed-by: Stefan Klug <stefan.klug@ideasonboard.com>\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n---\nChanges in v8:\n- s/D/Rows/ in Vector class\n- add z accessor function\n- move SFINAE for x() and y() (and z()) to the functions instead of the\n class\n- add vector to meson\n\nChanges in v7:\n- fix documentation\n- fix license and copyright\n- remove toString()\n\nNo change in v6\n\nNew in v5\n---\n src/ipa/libipa/meson.build | 2 +\n src/ipa/libipa/vector.cpp | 150 +++++++++++++++++++++++++++\n src/ipa/libipa/vector.h | 203 +++++++++++++++++++++++++++++++++++++\n 3 files changed, 355 insertions(+)\n create mode 100644 src/ipa/libipa/vector.cpp\n create mode 100644 src/ipa/libipa/vector.h", "diff": "diff --git a/src/ipa/libipa/meson.build b/src/ipa/libipa/meson.build\nindex 7ce885da7b99..8b0c8fff901b 100644\n--- a/src/ipa/libipa/meson.build\n+++ b/src/ipa/libipa/meson.build\n@@ -8,6 +8,7 @@ libipa_headers = files([\n 'fc_queue.h',\n 'histogram.h',\n 'module.h',\n+ 'vector.h',\n ])\n \n libipa_sources = files([\n@@ -18,6 +19,7 @@ libipa_sources = files([\n 'fc_queue.cpp',\n 'histogram.cpp',\n 'module.cpp',\n+ 'vector.cpp',\n ])\n \n libipa_includes = include_directories('..')\ndiff --git a/src/ipa/libipa/vector.cpp b/src/ipa/libipa/vector.cpp\nnew file mode 100644\nindex 000000000000..b9fad90386a1\n--- /dev/null\n+++ b/src/ipa/libipa/vector.cpp\n@@ -0,0 +1,150 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2024, Paul Elder <paul.elder@ideasonboard.com>\n+ *\n+ * Vector and related operations\n+ */\n+\n+#include \"vector.h\"\n+\n+#include <libcamera/base/log.h>\n+\n+/**\n+ * \\file vector.h\n+ * \\brief Vector class\n+ */\n+\n+namespace libcamera {\n+\n+LOG_DEFINE_CATEGORY(Vector)\n+\n+namespace ipa {\n+\n+/**\n+ * \\class Vector\n+ * \\brief Vector class\n+ * \\tparam T Type of numerical values to be stored in the vector\n+ * \\tparam Rows Number of dimension of the vector (= number of elements)\n+ */\n+\n+/**\n+ * \\fn Vector::Vector()\n+ * \\brief Construct a zero vector\n+ */\n+\n+/**\n+ * \\fn Vector::Vector(const std::array<T, Rows> &data)\n+ * \\brief Construct vector from supplied data\n+ * \\param data Data from which to construct a vector\n+ *\n+ * The size of \\a data must be equal to the dimension size Rows of the vector.\n+ */\n+\n+/**\n+ * \\fn Vector::readYaml\n+ * \\brief Populate the vector with yaml data\n+ * \\param yaml Yaml data to populate the vector with\n+ *\n+ * Any existing data in the vector will be overwritten. The size of the data\n+ * read from \\a yaml must be equal to the dimension size Rows of the vector.\n+ *\n+ * The yaml data is expected to be a list with elements of type T.\n+ *\n+ * \\return 0 on success, negative error code otherwise\n+ */\n+\n+/**\n+ * \\fn T Vector::operator[](size_t i) const\n+ * \\brief Index to an element in the vector\n+ * \\param i Index of element to retrieve\n+ * \\return Element at index \\a i from the vector\n+ */\n+\n+/**\n+ * \\fn T &Vector::operator[](size_t i)\n+ * \\copydoc Vector::operator[](size_t i) const\n+ */\n+\n+/**\n+ * \\fn Vector::x()\n+ * \\brief Convenience function to access the first element of the vector\n+ */\n+\n+/**\n+ * \\fn Vector::y()\n+ * \\brief Convenience function to access the second element of the vector\n+ */\n+\n+/**\n+ * \\fn Vector::z()\n+ * \\brief Convenience function to access the third element of the vector\n+ */\n+\n+/**\n+ * \\fn Vector::operator-() const\n+ * \\brief Negate a Vector by negating both all of its coordinates\n+ * \\return The negated vector\n+ */\n+\n+/**\n+ * \\fn Vector::operator-(Vector const &other) const\n+ * \\brief Subtract one vector from another\n+ * \\param[in] other The other vector\n+ * \\return The difference of \\a other from this vector\n+ */\n+\n+/**\n+ * \\fn Vector::operator+()\n+ * \\brief Add two vectors together\n+ * \\param[in] other The other vector\n+ * \\return The sum of the two vectors\n+ */\n+\n+/**\n+ * \\fn Vector::operator*(const Vector<T, Rows> &other) const\n+ * \\brief Compute the dot product\n+ * \\param[in] other The other vector\n+ * \\return The dot product of the two vectors\n+ */\n+\n+/**\n+ * \\fn Vector::operator*(T factor) const\n+ * \\brief Multiply the vector by a scalar\n+ * \\param[in] factor The factor\n+ * \\return The vector multiplied by \\a factor\n+ */\n+\n+/**\n+ * \\fn Vector::operator/()\n+ * \\brief Divide the vector by a scalar\n+ * \\param[in] factor The factor\n+ * \\return The vector divided by \\a factor\n+ */\n+\n+/**\n+ * \\fn Vector::length2()\n+ * \\brief Get the squared length of the vector\n+ * \\return The squared length of the vector\n+ */\n+\n+/**\n+ * \\fn Vector::length()\n+ * \\brief Get the length of the vector\n+ * \\return The length of the vector\n+ */\n+\n+/**\n+ * \\fn bool operator==(const Vector<T, Rows> &lhs, const Vector<T, Rows> &rhs)\n+ * \\brief Compare vectors for equality\n+ * \\return True if the two vectors are equal, false otherwise\n+ */\n+\n+/**\n+ * \\fn bool operator!=(const Vector<T, Rows> &lhs, const Vector<T, Rows> &rhs)\n+ * \\brief Compare vectors for inequality\n+ * \\return True if the two vectors are not equal, false otherwise\n+ */\n+\n+} /* namespace ipa */\n+\n+} /* namespace libcamera */\ndiff --git a/src/ipa/libipa/vector.h b/src/ipa/libipa/vector.h\nnew file mode 100644\nindex 000000000000..b281f079365a\n--- /dev/null\n+++ b/src/ipa/libipa/vector.h\n@@ -0,0 +1,203 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2024, Paul Elder <paul.elder@ideasonboard.com>\n+ *\n+ * Vector and related operations\n+ */\n+#pragma once\n+\n+#include <algorithm>\n+#include <array>\n+#include <cmath>\n+#include <sstream>\n+\n+#include <libcamera/base/log.h>\n+#include <libcamera/base/span.h>\n+\n+#include \"libcamera/internal/yaml_parser.h\"\n+\n+namespace libcamera {\n+\n+LOG_DECLARE_CATEGORY(Vector)\n+\n+namespace ipa {\n+\n+#ifndef __DOXYGEN__\n+template<typename T, unsigned int Rows,\n+\t std::enable_if_t<std::is_arithmetic_v<T>> * = nullptr>\n+#else\n+template<typename T, unsigned int Rows>\n+#endif /* __DOXYGEN__ */\n+class Vector\n+{\n+public:\n+\tconstexpr Vector() = default;\n+\n+\tconstexpr Vector(const std::array<T, Rows> &data)\n+\t{\n+\t\tfor (unsigned int i = 0; i < Rows; i++)\n+\t\t\tdata_[i] = data[i];\n+\t}\n+\n+\tint readYaml(const libcamera::YamlObject &yaml)\n+\t{\n+\t\tif (yaml.size() != Rows) {\n+\t\t\tLOG(Vector, Error)\n+\t\t\t\t<< \"Wrong number of values in vector: expected \"\n+\t\t\t\t<< Rows << \", got \" << yaml.size();\n+\t\t\treturn -EINVAL;\n+\t\t}\n+\n+\t\tunsigned int i = 0;\n+\t\tfor (const auto &x : yaml.asList()) {\n+\t\t\tauto value = x.get<T>();\n+\t\t\tif (!value) {\n+\t\t\t\tLOG(Vector, Error) << \"Failed to read vector value\";\n+\t\t\t\treturn -EINVAL;\n+\t\t\t}\n+\n+\t\t\tdata_[i++] = *value;\n+\t\t}\n+\n+\t\treturn 0;\n+\t}\n+\n+\tconst T &operator[](size_t i) const\n+\t{\n+\t\tASSERT(i < data_.size());\n+\t\treturn data_[i];\n+\t}\n+\n+\tT &operator[](size_t i)\n+\t{\n+\t\tASSERT(i < data_.size());\n+\t\treturn data_[i];\n+\t}\n+\n+#ifndef __DOXYGEN__\n+\ttemplate<bool Dependent = false, typename = std::enable_if_t<Dependent || Rows >= 1>>\n+#endif /* __DOXYGEN__ */\n+\tconstexpr T x() const\n+\t{\n+\t\treturn data_[0];\n+\t}\n+\n+#ifndef __DOXYGEN__\n+\ttemplate<bool Dependent = false, typename = std::enable_if_t<Dependent || Rows >= 2>>\n+#endif /* __DOXYGEN__ */\n+\tconstexpr T y() const\n+\t{\n+\t\treturn data_[1];\n+\t}\n+\n+#ifndef __DOXYGEN__\n+\ttemplate<bool Dependent = false, typename = std::enable_if_t<Dependent || Rows >= 3>>\n+#endif /* __DOXYGEN__ */\n+\tconstexpr T z() const\n+\t{\n+\t\treturn data_[2];\n+\t}\n+\n+\tconstexpr Vector<T, Rows> operator-() 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];\n+\t\treturn ret;\n+\t}\n+\n+\tconstexpr Vector<T, Rows> operator-(const Vector<T, Rows> &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}\n+\n+\tconstexpr Vector<T, Rows> operator+(const Vector<T, Rows> &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}\n+\n+\tconstexpr T operator*(const Vector<T, Rows> &other) const\n+\t{\n+\t\tT ret = 0;\n+\t\tfor (unsigned int i = 0; i < Rows; i++)\n+\t\t\tret += data_[i] * other[i];\n+\t\treturn ret;\n+\t}\n+\n+\tconstexpr Vector<T, Rows> 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}\n+\n+\tconstexpr Vector<T, Rows> 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}\n+\n+\tconstexpr double length2() const\n+\t{\n+\t\tdouble ret = 0;\n+\t\tfor (unsigned int i = 0; i < Rows; i++)\n+\t\t\tret += data_[i] * data_[i];\n+\t\treturn ret;\n+\t}\n+\n+\tconstexpr double length() const\n+\t{\n+\t\treturn std::sqrt(length2());\n+\t}\n+\n+private:\n+\tstd::array<T, Rows> data_;\n+};\n+\n+template<typename T, unsigned int Rows>\n+bool operator==(const Vector<T, Rows> &lhs, const Vector<T, Rows> &rhs)\n+{\n+\tfor (unsigned int i = 0; i < Rows; i++)\n+\t\tif (lhs[i] != rhs[i])\n+\t\t\treturn false;\n+\n+\treturn true;\n+}\n+\n+template<typename T, unsigned int Rows>\n+bool operator!=(const Vector<T, Rows> &lhs, const Vector<T, Rows> &rhs)\n+{\n+\tfor (unsigned int i = 0; i < Rows; i++)\n+\t\tif (lhs[i] != rhs[i])\n+\t\t\treturn true;\n+\n+\treturn false;\n+}\n+\n+} /* namespace ipa */\n+\n+#ifndef __DOXYGEN__\n+template<typename T, unsigned int Rows>\n+std::ostream &operator<<(std::ostream &out, const ipa::Vector<T, Rows> &v)\n+{\n+\tout << \"Vector { \";\n+\tfor (unsigned int i = 0; i < Rows; i++) {\n+\t\tout << v[i];\n+\t\tout << ((i + 1 < Rows) ? \", \" : \" \");\n+\t}\n+\tout << \" }\";\n+\n+\treturn out;\n+}\n+#endif /* __DOXYGEN__ */\n+\n+} /* namespace libcamera */\n", "prefixes": [ "v8", "1/4" ] }