Patch Detail
Show a patch.
GET /api/patches/22742/?format=api
{ "id": 22742, "url": "https://patchwork.libcamera.org/api/patches/22742/?format=api", "web_url": "https://patchwork.libcamera.org/patch/22742/", "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": "<20250206141018.236272-2-stefan.klug@ideasonboard.com>", "date": "2025-02-06T14:10:08", "name": "[1/4] libcamera: Copy Vector class files from libipa", "commit_ref": "e506b45822472c23368809f4bfe0289826c5756a", "pull_url": null, "state": "accepted", "archived": false, "hash": "07e19002a7b9b8011fd5577b8111a79722c9f32d", "submitter": { "id": 184, "url": "https://patchwork.libcamera.org/api/people/184/?format=api", "name": "Stefan Klug", "email": "stefan.klug@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/22742/mbox/", "series": [ { "id": 4992, "url": "https://patchwork.libcamera.org/api/series/4992/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4992", "date": "2025-02-06T14:10:07", "name": "Move Vector class from libipa to libcamera", "version": 1, "mbox": "https://patchwork.libcamera.org/series/4992/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/22742/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/22742/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 7427EC32EA\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 6 Feb 2025 14:10:28 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 27436685EA;\n\tThu, 6 Feb 2025 15:10:28 +0100 (CET)", "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 957096053F\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 6 Feb 2025 15:10:25 +0100 (CET)", "from ideasonboard.com (unknown\n\t[IPv6:2a00:6020:448c:6c00:6b7d:6f52:efbb:46c8])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 0AD2C1193;\n\tThu, 6 Feb 2025 15:09:12 +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=\"aEhB+sBr\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1738850952;\n\tbh=0jBImBCpJQ48gSW+zJuQBQ57Qc398QkP5SOiIhEoUMc=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=aEhB+sBru6rrBlPpcyCPb7gx/NxX6MiH9/WEVbiEDkvW3FaBLMmmHulbWUVuNZTpC\n\tNL+y+lebDOBTdMyUwKPeeuk0SROI8AuywsfJ4wbnogbdQdMch8GWKhPEOkfdY6YeDp\n\tMj0Y0fi+UIBCWwt8Sw0KYM+kVVJjnch2dGuPaHeM=", "From": "Stefan Klug <stefan.klug@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Cc": "Stefan Klug <stefan.klug@ideasonboard.com>", "Subject": "[PATCH 1/4] libcamera: Copy Vector class files from libipa", "Date": "Thu, 6 Feb 2025 15:10:08 +0100", "Message-ID": "<20250206141018.236272-2-stefan.klug@ideasonboard.com>", "X-Mailer": "git-send-email 2.43.0", "In-Reply-To": "<20250206141018.236272-1-stefan.klug@ideasonboard.com>", "References": "<20250206141018.236272-1-stefan.klug@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": "Prepare the move of the Vector class from libipa to libcamera by copying\nthe relevant files into the corresponding libcamera directories. The\nfiles are copied without modification.\n\nSigned-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n---\n include/libcamera/internal/vector.h | 370 ++++++++++++++++++++++++++++\n src/libcamera/vector.cpp | 351 ++++++++++++++++++++++++++\n test/vector.cpp | 100 ++++++++\n 3 files changed, 821 insertions(+)\n create mode 100644 include/libcamera/internal/vector.h\n create mode 100644 src/libcamera/vector.cpp\n create mode 100644 test/vector.cpp", "diff": "diff --git a/include/libcamera/internal/vector.h b/include/libcamera/internal/vector.h\nnew file mode 100644\nindex 000000000000..fe33c9d6fbd1\n--- /dev/null\n+++ b/include/libcamera/internal/vector.h\n@@ -0,0 +1,370 @@\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 <functional>\n+#include <numeric>\n+#include <optional>\n+#include <ostream>\n+\n+#include <libcamera/base/log.h>\n+#include <libcamera/base/span.h>\n+\n+#include \"libcamera/internal/matrix.h\"\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 explicit Vector(T scalar)\n+\t{\n+\t\tdata_.fill(scalar);\n+\t}\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+\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+\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 operator+(const Vector &other) const\n+\t{\n+\t\treturn apply(*this, other, std::plus<>{});\n+\t}\n+\n+\tconstexpr Vector operator+(T scalar) const\n+\t{\n+\t\treturn apply(*this, scalar, std::plus<>{});\n+\t}\n+\n+\tconstexpr Vector operator-(const Vector &other) const\n+\t{\n+\t\treturn apply(*this, other, std::minus<>{});\n+\t}\n+\n+\tconstexpr Vector operator-(T scalar) const\n+\t{\n+\t\treturn apply(*this, scalar, std::minus<>{});\n+\t}\n+\n+\tconstexpr Vector operator*(const Vector &other) const\n+\t{\n+\t\treturn apply(*this, other, std::multiplies<>{});\n+\t}\n+\n+\tconstexpr Vector operator*(T scalar) const\n+\t{\n+\t\treturn apply(*this, scalar, std::multiplies<>{});\n+\t}\n+\n+\tconstexpr Vector operator/(const Vector &other) const\n+\t{\n+\t\treturn apply(*this, other, std::divides<>{});\n+\t}\n+\n+\tconstexpr Vector operator/(T scalar) const\n+\t{\n+\t\treturn apply(*this, scalar, std::divides<>{});\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 Vector min(const Vector &other) const\n+\t{\n+\t\treturn apply(*this, other, [](T a, T b) { return std::min(a, b); });\n+\t}\n+\n+\tconstexpr Vector min(T scalar) const\n+\t{\n+\t\treturn apply(*this, scalar, [](T a, T b) { return std::min(a, b); });\n+\t}\n+\n+\tconstexpr Vector max(const Vector &other) const\n+\t{\n+\t\treturn apply(*this, other, [](T a, T b) { return std::max(a, b); });\n+\t}\n+\n+\tconstexpr Vector max(T scalar) const\n+\t{\n+\t\treturn apply(*this, scalar, [](T a, T b) -> T { return std::max(a, b); });\n+\t}\n+\n+\tconstexpr T dot(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+#ifndef __DOXYGEN__\n+\ttemplate<bool Dependent = false, typename = std::enable_if_t<Dependent || Rows >= 1>>\n+#endif /* __DOXYGEN__ */\n+\tconstexpr const T &x() const { return data_[0]; }\n+#ifndef __DOXYGEN__\n+\ttemplate<bool Dependent = false, typename = std::enable_if_t<Dependent || Rows >= 2>>\n+#endif /* __DOXYGEN__ */\n+\tconstexpr const T &y() const { return data_[1]; }\n+#ifndef __DOXYGEN__\n+\ttemplate<bool Dependent = false, typename = std::enable_if_t<Dependent || Rows >= 3>>\n+#endif /* __DOXYGEN__ */\n+\tconstexpr const T &z() const { return data_[2]; }\n+#ifndef __DOXYGEN__\n+\ttemplate<bool Dependent = false, typename = std::enable_if_t<Dependent || Rows >= 1>>\n+#endif /* __DOXYGEN__ */\n+\tconstexpr T &x() { return data_[0]; }\n+#ifndef __DOXYGEN__\n+\ttemplate<bool Dependent = false, typename = std::enable_if_t<Dependent || Rows >= 2>>\n+#endif /* __DOXYGEN__ */\n+\tconstexpr T &y() { return data_[1]; }\n+#ifndef __DOXYGEN__\n+\ttemplate<bool Dependent = false, typename = std::enable_if_t<Dependent || Rows >= 3>>\n+#endif /* __DOXYGEN__ */\n+\tconstexpr T &z() { return data_[2]; }\n+\n+#ifndef __DOXYGEN__\n+\ttemplate<bool Dependent = false, typename = std::enable_if_t<Dependent || Rows >= 1>>\n+#endif /* __DOXYGEN__ */\n+\tconstexpr const T &r() const { return data_[0]; }\n+#ifndef __DOXYGEN__\n+\ttemplate<bool Dependent = false, typename = std::enable_if_t<Dependent || Rows >= 2>>\n+#endif /* __DOXYGEN__ */\n+\tconstexpr const T &g() const { return data_[1]; }\n+#ifndef __DOXYGEN__\n+\ttemplate<bool Dependent = false, typename = std::enable_if_t<Dependent || Rows >= 3>>\n+#endif /* __DOXYGEN__ */\n+\tconstexpr const T &b() const { return data_[2]; }\n+#ifndef __DOXYGEN__\n+\ttemplate<bool Dependent = false, typename = std::enable_if_t<Dependent || Rows >= 1>>\n+#endif /* __DOXYGEN__ */\n+\tconstexpr T &r() { return data_[0]; }\n+#ifndef __DOXYGEN__\n+\ttemplate<bool Dependent = false, typename = std::enable_if_t<Dependent || Rows >= 2>>\n+#endif /* __DOXYGEN__ */\n+\tconstexpr T &g() { return data_[1]; }\n+#ifndef __DOXYGEN__\n+\ttemplate<bool Dependent = false, typename = std::enable_if_t<Dependent || Rows >= 3>>\n+#endif /* __DOXYGEN__ */\n+\tconstexpr T &b() { return data_[2]; }\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+\ttemplate<typename R = T>\n+\tconstexpr R sum() const\n+\t{\n+\t\treturn std::accumulate(data_.begin(), data_.end(), R{});\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+\ttemplate<class BinaryOp>\n+\tVector &apply(const Vector &other, BinaryOp op)\n+\t{\n+\t\tauto itOther = other.data_.begin();\n+\t\tstd::for_each(data_.begin(), data_.end(),\n+\t\t\t [&op, &itOther](T &v) { v = op(v, *itOther++); });\n+\n+\t\treturn *this;\n+\t}\n+\n+\ttemplate<class BinaryOp>\n+\tVector &apply(T scalar, BinaryOp op)\n+\t{\n+\t\tstd::for_each(data_.begin(), data_.end(),\n+\t\t\t [&op, scalar](T &v) { v = op(v, scalar); });\n+\n+\t\treturn *this;\n+\t}\n+\n+\tstd::array<T, Rows> data_;\n+};\n+\n+template<typename T>\n+using RGB = Vector<T, 3>;\n+\n+template<typename T, unsigned int Rows, unsigned int Cols>\n+Vector<T, Rows> operator*(const Matrix<T, Rows, Cols> &m, const Vector<T, Cols> &v)\n+{\n+\tVector<T, Rows> result;\n+\n+\tfor (unsigned int i = 0; i < Rows; i++) {\n+\t\tT sum = 0;\n+\t\tfor (unsigned int j = 0; j < Cols; j++)\n+\t\t\tsum += m[i][j] * v[j];\n+\t\tresult[i] = sum;\n+\t}\n+\n+\treturn result;\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+\t}\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+\treturn !(lhs == rhs);\n+}\n+\n+#ifndef __DOXYGEN__\n+bool vectorValidateYaml(const YamlObject &obj, unsigned int size);\n+#endif /* __DOXYGEN__ */\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+\n+template<typename T, unsigned int Rows>\n+struct YamlObject::Getter<ipa::Vector<T, Rows>> {\n+\tstd::optional<ipa::Vector<T, Rows>> get(const YamlObject &obj) const\n+\t{\n+\t\tif (!ipa::vectorValidateYaml(obj, Rows))\n+\t\t\treturn std::nullopt;\n+\n+\t\tipa::Vector<T, Rows> vector;\n+\n+\t\tunsigned int i = 0;\n+\t\tfor (const YamlObject &entry : obj.asList()) {\n+\t\t\tconst auto value = entry.get<T>();\n+\t\t\tif (!value)\n+\t\t\t\treturn std::nullopt;\n+\t\t\tvector[i++] = *value;\n+\t\t}\n+\n+\t\treturn vector;\n+\t}\n+};\n+#endif /* __DOXYGEN__ */\n+\n+} /* namespace libcamera */\ndiff --git a/src/libcamera/vector.cpp b/src/libcamera/vector.cpp\nnew file mode 100644\nindex 000000000000..8019f8cfdc85\n--- /dev/null\n+++ b/src/libcamera/vector.cpp\n@@ -0,0 +1,351 @@\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 an uninitialized vector\n+ */\n+\n+/**\n+ * \\fn Vector::Vector(T scalar)\n+ * \\brief Construct a vector filled with a \\a scalar value\n+ * \\param[in] scalar The scalar value\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 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::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 Calculate the sum of this vector and \\a other element-wise\n+ * \\param[in] other The other vector\n+ * \\return The element-wise sum of this vector and \\a other\n+ */\n+\n+/**\n+ * \\fn Vector::operator+(T scalar) const\n+ * \\brief Calculate the sum of this vector and \\a scalar element-wise\n+ * \\param[in] scalar The scalar\n+ * \\return The element-wise sum of this vector and \\a other\n+ */\n+\n+/**\n+ * \\fn Vector::operator-(Vector const &other) const\n+ * \\brief Calculate the difference of this vector and \\a other element-wise\n+ * \\param[in] other The other vector\n+ * \\return The element-wise subtraction of \\a other from this vector\n+ */\n+\n+/**\n+ * \\fn Vector::operator-(T scalar) const\n+ * \\brief Calculate the difference of this vector and \\a scalar element-wise\n+ * \\param[in] scalar The scalar\n+ * \\return The element-wise subtraction of \\a scalar from this vector\n+ */\n+\n+/**\n+ * \\fn Vector::operator*(const Vector &other) const\n+ * \\brief Calculate the product of this vector and \\a other element-wise\n+ * \\param[in] other The other vector\n+ * \\return The element-wise product of this vector and \\a other\n+ */\n+\n+/**\n+ * \\fn Vector::operator*(T scalar) const\n+ * \\brief Calculate the product of this vector and \\a scalar element-wise\n+ * \\param[in] scalar The scalar\n+ * \\return The element-wise product of this vector and \\a scalar\n+ */\n+\n+/**\n+ * \\fn Vector::operator/(const Vector &other) const\n+ * \\brief Calculate the quotient of this vector and \\a other element-wise\n+ * \\param[in] other The other vector\n+ * \\return The element-wise division of this vector by \\a other\n+ */\n+\n+/**\n+ * \\fn Vector::operator/(T scalar) const\n+ * \\brief Calculate the quotient of this vector and \\a scalar element-wise\n+ * \\param[in] scalar The scalar\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::min(const Vector &other) const\n+ * \\brief Calculate the minimum of this vector and \\a other element-wise\n+ * \\param[in] other The other vector\n+ * \\return The element-wise minimum of this vector and \\a other\n+ */\n+\n+/**\n+ * \\fn Vector::min(T scalar) const\n+ * \\brief Calculate the minimum of this vector and \\a scalar element-wise\n+ * \\param[in] scalar The scalar\n+ * \\return The element-wise minimum of this vector and \\a scalar\n+ */\n+\n+/**\n+ * \\fn Vector::max(const Vector &other) const\n+ * \\brief Calculate the maximum of this vector and \\a other element-wise\n+ * \\param[in] other The other vector\n+ * \\return The element-wise maximum of this vector and \\a other\n+ */\n+\n+/**\n+ * \\fn Vector::max(T scalar) const\n+ * \\brief Calculate the maximum of this vector and \\a scalar element-wise\n+ * \\param[in] scalar The scalar\n+ * \\return The element-wise maximum of this vector and \\a scalar\n+ */\n+\n+/**\n+ * \\fn Vector::dot(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 constexpr T &Vector::x()\n+ * \\brief Convenience function to access the first element of the vector\n+ * \\return The first element of the vector\n+ */\n+\n+/**\n+ * \\fn constexpr T &Vector::y()\n+ * \\brief Convenience function to access the second element of the vector\n+ * \\return The second element of the vector\n+ */\n+\n+/**\n+ * \\fn constexpr T &Vector::z()\n+ * \\brief Convenience function to access the third element of the vector\n+ * \\return The third element of the vector\n+ */\n+\n+/**\n+ * \\fn constexpr const T &Vector::x() const\n+ * \\copydoc Vector::x()\n+ */\n+\n+/**\n+ * \\fn constexpr const T &Vector::y() const\n+ * \\copydoc Vector::y()\n+ */\n+\n+/**\n+ * \\fn constexpr const T &Vector::z() const\n+ * \\copydoc Vector::z()\n+ */\n+\n+/**\n+ * \\fn constexpr T &Vector::r()\n+ * \\brief Convenience function to access the first element of the vector\n+ * \\return The first element of the vector\n+ */\n+\n+/**\n+ * \\fn constexpr T &Vector::g()\n+ * \\brief Convenience function to access the second element of the vector\n+ * \\return The second element of the vector\n+ */\n+\n+/**\n+ * \\fn constexpr T &Vector::b()\n+ * \\brief Convenience function to access the third element of the vector\n+ * \\return The third element of the vector\n+ */\n+\n+/**\n+ * \\fn constexpr const T &Vector::r() const\n+ * \\copydoc Vector::r()\n+ */\n+\n+/**\n+ * \\fn constexpr const T &Vector::g() const\n+ * \\copydoc Vector::g()\n+ */\n+\n+/**\n+ * \\fn constexpr const T &Vector::b() const\n+ * \\copydoc Vector::b()\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 Vector::sum() const\n+ * \\brief Calculate the sum of all the vector elements\n+ * \\tparam R The type of the sum\n+ *\n+ * The type R of the sum defaults to the type T of the elements, but can be set\n+ * explicitly to use a different type in case the type T would risk\n+ * overflowing.\n+ *\n+ * \\return The sum of all the vector elements\n+ */\n+\n+/**\n+ * \\fn Vector<T, Rows> operator*(const Matrix<T, Rows, Cols> &m, const Vector<T, Cols> &v)\n+ * \\brief Multiply a matrix by a vector\n+ * \\tparam T Numerical type of the contents of the matrix and vector\n+ * \\tparam Rows The number of rows in the matrix\n+ * \\tparam Cols The number of columns in the matrix (= rows in the vector)\n+ * \\param m The matrix\n+ * \\param v The vector\n+ * \\return Product of matrix \\a m and vector \\a v\n+ */\n+\n+/**\n+ * \\typedef RGB\n+ * \\brief A Vector of 3 elements representing an RGB pixel value\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+#ifndef __DOXYGEN__\n+bool vectorValidateYaml(const YamlObject &obj, unsigned int size)\n+{\n+\tif (!obj.isList())\n+\t\treturn false;\n+\n+\tif (obj.size() != size) {\n+\t\tLOG(Vector, Error)\n+\t\t\t<< \"Wrong number of values in YAML vector: expected \"\n+\t\t\t<< size << \", got \" << obj.size();\n+\t\treturn false;\n+\t}\n+\n+\treturn true;\n+}\n+#endif /* __DOXYGEN__ */\n+\n+} /* namespace ipa */\n+\n+} /* namespace libcamera */\ndiff --git a/test/vector.cpp b/test/vector.cpp\nnew file mode 100644\nindex 000000000000..8e4ec77d7820\n--- /dev/null\n+++ b/test/vector.cpp\n@@ -0,0 +1,100 @@\n+/* SPDX-License-Identifier: GPL-2.0-or-later */\n+/*\n+ * Copyright (C) 2024, Ideas on Board Oy\n+ *\n+ * Vector tests\n+ */\n+\n+#include \"../src/ipa/libipa/vector.h\"\n+\n+#include <cmath>\n+#include <iostream>\n+\n+#include \"test.h\"\n+\n+using namespace libcamera::ipa;\n+\n+#define ASSERT_EQ(a, b)\t\t\t\t\t\t\t\\\n+if ((a) != (b)) {\t\t\t\t\t\t\t\\\n+\tstd::cout << #a \" != \" #b << \" (line \" << __LINE__ << \")\"\t\\\n+\t\t << std::endl;\t\t\t\t\t\t\\\n+\treturn TestFail;\t\t\t\t\t\t\\\n+}\n+\n+class VectorTest : public Test\n+{\n+protected:\n+\tint run()\n+\t{\n+\t\tVector<double, 3> v1{ 0.0 };\n+\n+\t\tASSERT_EQ(v1[0], 0.0);\n+\t\tASSERT_EQ(v1[1], 0.0);\n+\t\tASSERT_EQ(v1[2], 0.0);\n+\n+\t\tASSERT_EQ(v1.length(), 0.0);\n+\t\tASSERT_EQ(v1.length2(), 0.0);\n+\n+\t\tVector<double, 3> v2{{ 1.0, 4.0, 8.0 }};\n+\n+\t\tASSERT_EQ(v2[0], 1.0);\n+\t\tASSERT_EQ(v2[1], 4.0);\n+\t\tASSERT_EQ(v2[2], 8.0);\n+\n+\t\tASSERT_EQ(v2.x(), 1.0);\n+\t\tASSERT_EQ(v2.y(), 4.0);\n+\t\tASSERT_EQ(v2.z(), 8.0);\n+\n+\t\tASSERT_EQ(v2.r(), 1.0);\n+\t\tASSERT_EQ(v2.g(), 4.0);\n+\t\tASSERT_EQ(v2.b(), 8.0);\n+\n+\t\tASSERT_EQ(v2.length2(), 81.0);\n+\t\tASSERT_EQ(v2.length(), 9.0);\n+\t\tASSERT_EQ(v2.sum(), 13.0);\n+\n+\t\tVector<double, 3> v3{ v2 };\n+\n+\t\tASSERT_EQ(v2, v3);\n+\n+\t\tv3 = Vector<double, 3>{{ 4.0, 4.0, 4.0 }};\n+\n+\t\tASSERT_EQ(v2 + v3, (Vector<double, 3>{{ 5.0, 8.0, 12.0 }}));\n+\t\tASSERT_EQ(v2 + 4.0, (Vector<double, 3>{{ 5.0, 8.0, 12.0 }}));\n+\t\tASSERT_EQ(v2 - v3, (Vector<double, 3>{{ -3.0, 0.0, 4.0 }}));\n+\t\tASSERT_EQ(v2 - 4.0, (Vector<double, 3>{{ -3.0, 0.0, 4.0 }}));\n+\t\tASSERT_EQ(v2 * v3, (Vector<double, 3>{{ 4.0, 16.0, 32.0 }}));\n+\t\tASSERT_EQ(v2 * 4.0, (Vector<double, 3>{{ 4.0, 16.0, 32.0 }}));\n+\t\tASSERT_EQ(v2 / v3, (Vector<double, 3>{{ 0.25, 1.0, 2.0 }}));\n+\t\tASSERT_EQ(v2 / 4.0, (Vector<double, 3>{{ 0.25, 1.0, 2.0 }}));\n+\n+\t\tASSERT_EQ(v2.min(v3), (Vector<double, 3>{{ 1.0, 4.0, 4.0 }}));\n+\t\tASSERT_EQ(v2.min(4.0), (Vector<double, 3>{{ 1.0, 4.0, 4.0 }}));\n+\t\tASSERT_EQ(v2.max(v3), (Vector<double, 3>{{ 4.0, 4.0, 8.0 }}));\n+\t\tASSERT_EQ(v2.max(4.0), (Vector<double, 3>{{ 4.0, 4.0, 8.0 }}));\n+\n+\t\tASSERT_EQ(v2.dot(v3), 52.0);\n+\n+\t\tv2 += v3;\n+\t\tASSERT_EQ(v2, (Vector<double, 3>{{ 5.0, 8.0, 12.0 }}));\n+\t\tv2 -= v3;\n+\t\tASSERT_EQ(v2, (Vector<double, 3>{{ 1.0, 4.0, 8.0 }}));\n+\t\tv2 *= v3;\n+\t\tASSERT_EQ(v2, (Vector<double, 3>{{ 4.0, 16.0, 32.0 }}));\n+\t\tv2 /= v3;\n+\t\tASSERT_EQ(v2, (Vector<double, 3>{{ 1.0, 4.0, 8.0 }}));\n+\n+\t\tv2 += 4.0;\n+\t\tASSERT_EQ(v2, (Vector<double, 3>{{ 5.0, 8.0, 12.0 }}));\n+\t\tv2 -= 4.0;\n+\t\tASSERT_EQ(v2, (Vector<double, 3>{{ 1.0, 4.0, 8.0 }}));\n+\t\tv2 *= 4.0;\n+\t\tASSERT_EQ(v2, (Vector<double, 3>{{ 4.0, 16.0, 32.0 }}));\n+\t\tv2 /= 4.0;\n+\t\tASSERT_EQ(v2, (Vector<double, 3>{{ 1.0, 4.0, 8.0 }}));\n+\n+\t\treturn TestPass;\n+\t}\n+};\n+\n+TEST_REGISTER(VectorTest)\n", "prefixes": [ "1/4" ] }