Show a patch.

GET /api/patches/17868/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 17868,
    "url": "https://patchwork.libcamera.org/api/patches/17868/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/17868/",
    "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": "<20221124113550.2182342-3-paul.elder@ideasonboard.com>",
    "date": "2022-11-24T11:35:40",
    "name": "[libcamera-devel,v4,02/12] utils: tuning: libtuning: Implement math helpers",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "2949a92c173a7dd37acf57f932017125c41cd289",
    "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/17868/mbox/",
    "series": [
        {
            "id": 3636,
            "url": "https://patchwork.libcamera.org/api/series/3636/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=3636",
            "date": "2022-11-24T11:35:38",
            "name": "utils: tuning: Add a new tuning infrastructure",
            "version": 4,
            "mbox": "https://patchwork.libcamera.org/series/3636/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/17868/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/17868/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 4CCF9BDE6B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 24 Nov 2022 11:36:08 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id D482F63322;\n\tThu, 24 Nov 2022 12:36:07 +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 7F34263319\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 24 Nov 2022 12:36:05 +0100 (CET)",
            "from pyrite.tail37cf.ts.net (h175-177-042-159.catv02.itscom.jp\n\t[175.177.42.159])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 0815C496;\n\tThu, 24 Nov 2022 12:36:03 +0100 (CET)"
        ],
        "DKIM-Signature": [
            "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1669289767;\n\tbh=OR7jA3ja3gZEENbFWFk1feLfnKtXrfWePxElS6rcrGg=;\n\th=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=1/0N6aIZmMX41x+JUUx0YwLjZ+IiiKb66o2oBSr5XFcSmDQW0ZB9w1PYjwcTzmqzL\n\tWT0VIVVlQI6wVjgL2STx9QNRd+fr7O5IK6O9+eoHbJ4UPM962/eR+EMK/9S0fS04W9\n\t50U1AFh/DU8T7miegqNw+oWFX9I4tKsRLp9okhMrDQifxPVeJEpqnZzv9mcVIwSC6e\n\tSTdS0NSQCf09bZArsgK+nzb/aw3oKaJgvrVgpi2jUjscL3u82fKVr9Z27OqU9zh46B\n\tm1StblRboFmAr0S5kjDQydzduZ7Yrq4ngQzjBmuxNqbvE23GMpDoSe8E1L5RoCYM+M\n\t+1FRkMFdKOJGw==",
            "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1669289765;\n\tbh=OR7jA3ja3gZEENbFWFk1feLfnKtXrfWePxElS6rcrGg=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=l1ti99znjcbb+40GYJ1reu+HLlMBGi4mwaJaDV2F8zDIHa3gm8J1W9b2UNBk00VzG\n\t4TPV1tXJkrNbAfWYI19vDxiX79LXanh8BbtZ/SK4GtP3R80YTlNURulHXzKIhXhXrM\n\t460790BPeRmwCj0yHgGXavpzqOr2uOUBzDNKiwNU="
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"l1ti99zn\"; dkim-atps=neutral",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Thu, 24 Nov 2022 20:35:40 +0900",
        "Message-Id": "<20221124113550.2182342-3-paul.elder@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.35.1",
        "In-Reply-To": "<20221124113550.2182342-1-paul.elder@ideasonboard.com>",
        "References": "<20221124113550.2182342-1-paul.elder@ideasonboard.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v4 02/12] utils: tuning: libtuning:\n\tImplement math helpers",
        "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>",
        "From": "Paul Elder via libcamera-devel <libcamera-devel@lists.libcamera.org>",
        "Reply-To": "Paul Elder <paul.elder@ideasonboard.com>",
        "Errors-To": "libcamera-devel-bounces@lists.libcamera.org",
        "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"
    },
    "content": "Implement math helpers for libtuning. This includes:\n- Average, a wrapper class for numpy averaging functions\n- Gradient, a class that represents gradients, for distributing and\n  mapping\n- Smoothing, a wrapper class for cv2 smoothing functions\n\nSigned-off-by: Paul Elder <paul.elder@ideasonboard.com>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n---\nChanges in v4:\n- fix typo (leftover comma)\n\nChanges in v3:\n- Newly split from the first patch \"utils: tuning: libtuning: Implement\n  the core of libtuning\"\n  - See changelog from that patch\n---\n utils/tuning/libtuning/average.py   | 21 ++++++++\n utils/tuning/libtuning/gradient.py  | 75 +++++++++++++++++++++++++++++\n utils/tuning/libtuning/smoothing.py | 24 +++++++++\n 3 files changed, 120 insertions(+)\n create mode 100644 utils/tuning/libtuning/average.py\n create mode 100644 utils/tuning/libtuning/gradient.py\n create mode 100644 utils/tuning/libtuning/smoothing.py",
    "diff": "diff --git a/utils/tuning/libtuning/average.py b/utils/tuning/libtuning/average.py\nnew file mode 100644\nindex 00000000..e28770d7\n--- /dev/null\n+++ b/utils/tuning/libtuning/average.py\n@@ -0,0 +1,21 @@\n+# SPDX-License-Identifier: GPL-2.0-or-later\n+#\n+# Copyright (C) 2022, Paul Elder <paul.elder@ideasonboard.com>\n+#\n+# average.py - Wrapper for numpy averaging functions to enable duck-typing\n+\n+import numpy as np\n+\n+\n+# @brief Wrapper for np averaging functions so that they can be duck-typed\n+class Average(object):\n+    def __init__(self):\n+        pass\n+\n+    def average(self, np_array):\n+        raise NotImplementedError\n+\n+\n+class Mean(Average):\n+    def average(self, np_array):\n+        return np.mean(np_array)\ndiff --git a/utils/tuning/libtuning/gradient.py b/utils/tuning/libtuning/gradient.py\nnew file mode 100644\nindex 00000000..5106f821\n--- /dev/null\n+++ b/utils/tuning/libtuning/gradient.py\n@@ -0,0 +1,75 @@\n+# SPDX-License-Identifier: GPL-2.0-or-later\n+#\n+# Copyright (C) 2022, Paul Elder <paul.elder@ideasonboard.com>\n+#\n+# gradient.py - Gradients that can be used to distribute or map numbers\n+\n+import libtuning as lt\n+\n+import math\n+from numbers import Number\n+\n+\n+# @brief Gradient for how to allocate pixels to sectors\n+# @description There are no parameters for the gradients as the domain is the\n+#              number of pixels and the range is the number of sectors, and\n+#              there is only one curve that has a startpoint and endpoint at\n+#              (0, 0) and at (#pixels, #sectors). The exception is for curves\n+#              that *do* have multiple solutions for only two points, such as\n+#              gaussian, and curves of higher polynomial orders if we had them.\n+#\n+# \\todo There will probably be a helper in the Gradient class, as I have a\n+# feeling that all the other curves (besides Linear and Gaussian) can be\n+# implemented in the same way.\n+class Gradient(object):\n+    def __init__(self):\n+        pass\n+\n+    # @brief Distribute pixels into sectors (only in one dimension)\n+    # @param domain Number of pixels\n+    # @param sectors Number of sectors\n+    # @return A list of number of pixels in each sector\n+    def distribute(self, domain: list, sectors: list) -> list:\n+        raise NotImplementedError\n+\n+    # @brief Map a number on a curve\n+    # @param domain Domain of the curve\n+    # @param rang Range of the curve\n+    # @param x Input on the domain of the curve\n+    # @return y from the range of the curve\n+    def map(self, domain: tuple, rang: tuple, x: Number) -> Number:\n+        raise NotImplementedError\n+\n+\n+class Linear(Gradient):\n+    # @param remainder Mode of handling remainder\n+    def __init__(self, remainder: lt.Remainder = lt.Remainder.Float):\n+        self.remainder = remainder\n+\n+    def distribute(self, domain: list, sectors: list) -> list:\n+        size = domain / sectors\n+        rem = domain % sectors\n+\n+        if rem == 0:\n+            return [int(size)] * sectors\n+\n+        size = math.ceil(size)\n+        rem = domain % size\n+        output_sectors = [int(size)] * (sectors - 1)\n+\n+        if self.remainder == lt.Remainder.Float:\n+            size = domain / sectors\n+            output_sectors = [size] * sectors\n+        elif self.remainder == lt.Remainder.DistributeFront:\n+            output_sectors.append(int(rem))\n+        elif self.remainder == lt.Remainder.DistributeBack:\n+            output_sectors.insert(0, int(rem))\n+        else:\n+            raise ValueError\n+\n+        return output_sectors\n+\n+    def map(self, domain: tuple, rang: tuple, x: Number) -> Number:\n+        m = (rang[1] - rang[0]) / (domain[1] - domain[0])\n+        b = rang[0] - m * domain[0]\n+        return m * x + b\ndiff --git a/utils/tuning/libtuning/smoothing.py b/utils/tuning/libtuning/smoothing.py\nnew file mode 100644\nindex 00000000..b8a5a242\n--- /dev/null\n+++ b/utils/tuning/libtuning/smoothing.py\n@@ -0,0 +1,24 @@\n+# SPDX-License-Identifier: GPL-2.0-or-later\n+#\n+# Copyright (C) 2022, Paul Elder <paul.elder@ideasonboard.com>\n+#\n+# smoothing.py - Wrapper for cv2 smoothing functions to enable duck-typing\n+\n+import cv2\n+\n+\n+# @brief Wrapper for cv2 smoothing functions so that they can be duck-typed\n+class Smoothing(object):\n+    def __init__(self):\n+        pass\n+\n+    def smoothing(self, src):\n+        raise NotImplementedError\n+\n+\n+class MedianBlur(Smoothing):\n+    def __init__(self, ksize):\n+        self.ksize = ksize\n+\n+    def smoothing(self, src):\n+        return cv2.medianBlur(src.astype('float32'), self.ksize).astype('float64')\n",
    "prefixes": [
        "libcamera-devel",
        "v4",
        "02/12"
    ]
}