Patch Detail
Show a patch.
GET /api/1.1/patches/19815/?format=api
{ "id": 19815, "url": "https://patchwork.libcamera.org/api/1.1/patches/19815/?format=api", "web_url": "https://patchwork.libcamera.org/patch/19815/", "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": "<20240327085933.281180-1-paul.elder@ideasonboard.com>", "date": "2024-03-27T08:59:33", "name": "ipa: libipa: Add Matrix class", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "f1955da4d43db6c9e9c76c8a51e639ad58867b33", "submitter": { "id": 17, "url": "https://patchwork.libcamera.org/api/1.1/people/17/?format=api", "name": "Paul Elder", "email": "paul.elder@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/19815/mbox/", "series": [ { "id": 4243, "url": "https://patchwork.libcamera.org/api/1.1/series/4243/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4243", "date": "2024-03-27T08:59:33", "name": "ipa: libipa: Add Matrix class", "version": 1, "mbox": "https://patchwork.libcamera.org/series/4243/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/19815/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/19815/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 A69B8C0DA4\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 27 Mar 2024 08:59:53 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id DCD7063339;\n\tWed, 27 Mar 2024 09:59:52 +0100 (CET)", "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 2642762CA2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 27 Mar 2024 09:59:51 +0100 (CET)", "from pyrite.hamster-moth.ts.net (h175-177-049-156.catv02.itscom.jp\n\t[175.177.49.156])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id D9A22675;\n\tWed, 27 Mar 2024 09:59:17 +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=\"OuCsZs8v\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1711529958;\n\tbh=yoIPKnJu0YrXxqs0VarqZxoyCPZT3+RtTGgcnqXb+d0=;\n\th=From:To:Cc:Subject:Date:From;\n\tb=OuCsZs8vV87JHBAcC2cDxXiZz1odKPcAd3S+Gguc3tIWLySYq8B3xCRC0oEeMpwXR\n\tcg2LgBt931x//7igz9Zb+oJ0xs1WbNudHRP83wS4CAW6R0HQAzjt2/6WL2ik8hgFBg\n\tdRLxU/S/Hj6jrWCMZzq3gKKN2SKmfbQTVuTS33Yw=", "From": "Paul Elder <paul.elder@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Cc": "Paul Elder <paul.elder@ideasonboard.com>", "Subject": "[PATCH] ipa: libipa: Add Matrix class", "Date": "Wed, 27 Mar 2024 17:59:33 +0900", "Message-Id": "<20240327085933.281180-1-paul.elder@ideasonboard.com>", "X-Mailer": "git-send-email 2.39.2", "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 class to represent a Matrix object and its corresponding\noperations.\n\nSigned-off-by: Paul Elder <paul.elder@ideasonboard.com>\n---\n src/ipa/libipa/matrix.cpp | 17 +++++\n src/ipa/libipa/matrix.h | 138 +++++++++++++++++++++++++++++++++++++\n src/ipa/libipa/meson.build | 2 +\n 3 files changed, 157 insertions(+)\n create mode 100644 src/ipa/libipa/matrix.cpp\n create mode 100644 src/ipa/libipa/matrix.h", "diff": "diff --git a/src/ipa/libipa/matrix.cpp b/src/ipa/libipa/matrix.cpp\nnew file mode 100644\nindex 00000000..c222c3f0\n--- /dev/null\n+++ b/src/ipa/libipa/matrix.cpp\n@@ -0,0 +1,17 @@\n+/* SPDX-License-Identifier: BSD-2-Clause */\n+/*\n+ * Copyright (C) 2019, Raspberry Pi Ltd\n+ * Copyright (C) 2024, Paul Elder <paul.elder@ideasonboard.com>\n+ *\n+ * matrix.cpp - Matrix and related operations\n+ */\n+\n+#include \"matrix.h\"\n+\n+#include <libcamera/base/log.h>\n+\n+namespace libcamera {\n+\n+LOG_DEFINE_CATEGORY(Matrix)\n+\n+} /* namespace libcamera */\ndiff --git a/src/ipa/libipa/matrix.h b/src/ipa/libipa/matrix.h\nnew file mode 100644\nindex 00000000..1fd191c7\n--- /dev/null\n+++ b/src/ipa/libipa/matrix.h\n@@ -0,0 +1,138 @@\n+/* SPDX-License-Identifier: BSD-2-Clause */\n+/*\n+ * Copyright (C) 2019, Raspberry Pi Ltd\n+ * Copyright (C) 2024, Paul Elder <paul.elder@ideasonboard.com>\n+ *\n+ * matrix.cpp - Matrix and related operations\n+ */\n+#pragma once\n+\n+#include <algorithm>\n+#include <cmath>\n+#include <sstream>\n+#include <tuple>\n+#include <vector>\n+\n+#include <libcamera/base/log.h>\n+\n+#include \"libcamera/internal/yaml_parser.h\"\n+\n+namespace libcamera {\n+\n+LOG_DECLARE_CATEGORY(Matrix)\n+\n+namespace ipa {\n+\n+template<typename T>\n+struct Matrix {\n+public:\n+\tMatrix(){};\n+\t~Matrix(){};\n+\n+\tMatrix(const unsigned int &_rows, const unsigned int &_cols,\n+\t const std::vector<T> &_data)\n+\t\t: rows(_rows), cols(_cols)\n+\t{\n+\t\tfor (const T &x : _data)\n+\t\t\tdata.push_back(x);\n+\n+\t\twhile (rows * cols < data.size())\n+\t\t\tdata.push_back(0);\n+\t}\n+\n+\tint readYaml(unsigned int _rows, unsigned int _cols,\n+\t\t const libcamera::YamlObject &yaml)\n+\t{\n+\t\trows = _rows;\n+\t\tcols = _cols;\n+\n+\t\tif (yaml.size() != rows * cols) {\n+\t\t\tLOG(Matrix, Error)\n+\t\t\t\t<< \"Wrong number of values in matrix: expected \"\n+\t\t\t\t<< rows * cols << \", got \" << yaml.size();\n+\t\t\treturn -EINVAL;\n+\t\t}\n+\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(Matrix, Error) << \"Failed to read matrix value \" << *value;\n+\t\t\t\treturn -EINVAL;\n+\t\t\t}\n+\t\t\tdata.push_back(*value);\n+\t\t}\n+\n+\t\treturn 0;\n+\t}\n+\n+\tconst std::string toString() const\n+\t{\n+\t\tstd::stringstream ss;\n+\t\tss << \"Matrix { \";\n+\t\tfor (unsigned int i = 0; i < rows; i++) {\n+\t\t\tss << \"[ \";\n+\t\t\tfor (unsigned int j = 0; j < cols; j++) {\n+\t\t\t\tss << data[i * cols + j];\n+\t\t\t\tss << ((j + 1 < cols) ? \", \" : \" \");\n+\t\t\t}\n+\t\t\tss << ((i + 1 < rows) ? \"], \" : \"]\");\n+\t\t}\n+\t\tss << \" }\";\n+\n+\t\treturn ss.str();\n+\t}\n+\n+\tconst T &operator[](unsigned int i) const { return data.at(i); }\n+\n+\tunsigned int rows;\n+\tunsigned int cols;\n+\tstd::vector<T> data;\n+};\n+\n+template<typename T>\n+Matrix<T> operator*(T d, const Matrix<T> &m)\n+{\n+\tstd::vector<T> result(m.data.size());\n+\n+\tfor (const T &x : m.data)\n+\t\tresult.push_back(d * x);\n+\n+\treturn Matrix(m.rows, m.cols, result);\n+}\n+\n+template<typename T>\n+Matrix<T> operator*(const Matrix<T> &m1, const Matrix<T> &m2)\n+{\n+\tASSERT(m1.cols == m2.rows);\n+\n+\tstd::vector<T> result(m1.rows * m2.cols);\n+\n+\tfor (unsigned int i = 0; i < m1.rows; i++) {\n+\t\tT sum = 0;\n+\n+\t\tfor (unsigned int j = 0; j < m2.cols; j++)\n+\t\t\tsum += m1[i * m1.cols + j] * m2[j * m2.cols + i];\n+\n+\t\tresult.push_back(sum);\n+\t}\n+\n+\treturn Matrix<T>(m1.rows, m2.cols, result);\n+}\n+\n+template<typename T>\n+Matrix<T> operator+(const Matrix<T> &m1, const Matrix<T> &m2)\n+{\n+\tASSERT(m1.cols == m2.cols && m1.rows == m2.rows);\n+\n+\tunsigned int len = m1.rows * m1.cols;\n+\tstd::vector<T> result(len);\n+\n+\tfor (unsigned int i = 0; i < len; i++)\n+\t\tresult[i] = m1[i] + m2[i];\n+\n+\treturn Matrix<T>(m1.rows, m1.cols, result);\n+}\n+\n+} /* namespace ipa */\n+\n+} /* namespace libcamera */\ndiff --git a/src/ipa/libipa/meson.build b/src/ipa/libipa/meson.build\nindex 817a09cf..5d5ba5e5 100644\n--- a/src/ipa/libipa/meson.build\n+++ b/src/ipa/libipa/meson.build\n@@ -6,6 +6,7 @@ libipa_headers = files([\n 'exposure_mode_helper.h',\n 'fc_queue.h',\n 'histogram.h',\n+ 'matrix.h',\n 'module.h',\n 'pwl.h',\n ])\n@@ -16,6 +17,7 @@ libipa_sources = files([\n 'exposure_mode_helper.cpp',\n 'fc_queue.cpp',\n 'histogram.cpp',\n+ 'matrix.cpp',\n 'module.cpp',\n 'pwl.cpp'\n ])\n", "prefixes": [] }