Show a patch.

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

{
    "id": 20191,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/20191/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/20191/",
    "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": "<20240603125324.3472888-1-paul.elder@ideasonboard.com>",
    "date": "2024-06-03T12:53:24",
    "name": "test: ipa: rkisp1: utils: Fix floating and fixed point conversion test",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "5656f7cbe15216b631e56ed0a05624f95cb19889",
    "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/20191/mbox/",
    "series": [
        {
            "id": 4353,
            "url": "https://patchwork.libcamera.org/api/1.1/series/4353/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4353",
            "date": "2024-06-03T12:53:24",
            "name": "test: ipa: rkisp1: utils: Fix floating and fixed point conversion test",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/4353/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/20191/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/20191/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 7190BBD87C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon,  3 Jun 2024 12:53:42 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 8B9AB634CA;\n\tMon,  3 Jun 2024 14:53:41 +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 5977F61A3B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon,  3 Jun 2024 14:53:39 +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 AA54EA38;\n\tMon,  3 Jun 2024 14:53:30 +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=\"ZT1PZi7L\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1717419212;\n\tbh=dzJITavxX6PJQrAsh/RNpGl+aej7PPmyypWSn7oFdV8=;\n\th=From:To:Cc:Subject:Date:From;\n\tb=ZT1PZi7LNOrafUh6YbiHNH5lXg3IwtlYTsOnlv4lN7U4+99F4AxtUwCIWhSflXn7t\n\tidYgLW1gMaCJ8Ta3S/R5Rs0Brry4qNB7HC3pb7+NqxRp4oYNq+lRqfkQniHC5x0pza\n\tsL/tPdbHiKRgyN1GapHGHU+e25EJBmTHPCj1bBDY=",
        "From": "Paul Elder <paul.elder@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Cc": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>,\n\tpobrn@protonmail.com, Paul Elder <paul.elder@ideasonboard.com>",
        "Subject": "[PATCH] test: ipa: rkisp1: utils: Fix floating and fixed point\n\tconversion test",
        "Date": "Mon,  3 Jun 2024 21:53:24 +0900",
        "Message-Id": "<20240603125324.3472888-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": "There was an issue where using map to store the test cases meant that\nthe test for ignoring unused bits was skipped because of clashing keys.\nFix this by changing the test to an array of tuples.\n\nWhile at it, reorganize the tests so that it's possible to test only\nreverse conversion, which was the case here to test that multiple fixed\npoint numbers (due to unused bits) would result in the same floating\npoint number.\n\nWhile at it, also change the arbitrary floating comparison precision to\nbe more precise.\n\nAlso fix a missing documentation brief.\n\nFixes: 9d152e9c6 ipa: rkisp1: Add a helper to convert floating-point to\nfixed-point\nSigned-off-by: Paul Elder <paul.elder@ideasonboard.com>\n---\n src/ipa/rkisp1/utils.cpp         |  1 +\n test/ipa/rkisp1/rkisp1-utils.cpp | 97 +++++++++++++++++++++++---------\n 2 files changed, 70 insertions(+), 28 deletions(-)",
    "diff": "diff --git a/src/ipa/rkisp1/utils.cpp b/src/ipa/rkisp1/utils.cpp\nindex 960ec64e9..8edcf5bf7 100644\n--- a/src/ipa/rkisp1/utils.cpp\n+++ b/src/ipa/rkisp1/utils.cpp\n@@ -9,6 +9,7 @@\n \n /**\n  * \\file utils.h\n+ * \\brief Utility functions for rkisp1\n  */\n \n namespace libcamera {\ndiff --git a/test/ipa/rkisp1/rkisp1-utils.cpp b/test/ipa/rkisp1/rkisp1-utils.cpp\nindex e48f8d362..4757ca069 100644\n--- a/test/ipa/rkisp1/rkisp1-utils.cpp\n+++ b/test/ipa/rkisp1/rkisp1-utils.cpp\n@@ -7,8 +7,8 @@\n \n #include <cmath>\n #include <iostream>\n-#include <map>\n #include <stdint.h>\n+#include <tuple>\n \n #include \"../src/ipa/rkisp1/utils.h\"\n \n@@ -21,53 +21,94 @@ using namespace ipa::rkisp1;\n class RkISP1UtilsTest : public Test\n {\n protected:\n-\ttemplate<unsigned int IntPrec, unsigned FracPrec, typename T>\n-\tint testSingleFixedPoint(double input, T expected)\n+\t/* R for real, I for integer */\n+\ttemplate<unsigned int IntPrec, unsigned FracPrec, typename I, typename R>\n+\tint testFixedToFloat(I input, R expected, R *output = nullptr)\n \t{\n-\t\tT ret = utils::floatingToFixedPoint<IntPrec, FracPrec, T>(input);\n-\t\tif (ret != expected) {\n-\t\t\tcerr << \"Expected \" << input << \" to convert to \"\n-\t\t\t     << expected << \", got \" << ret << std::endl;\n+\t\tR out = utils::fixedToFloatingPoint<IntPrec, FracPrec, R>(input);\n+\t\tif (output)\n+\t\t\t*output = out;\n+\t\tR prec = 1.0 / (1 << FracPrec);\n+\t\tif (std::abs(out - expected) > prec) {\n+\t\t\tcerr << \"Reverse conversion expected \" << input\n+\t\t\t     << \" to convert to \" << expected\n+\t\t\t     << \", got \" << out << std::endl;\n \t\t\treturn TestFail;\n \t\t}\n \n-\t\t/*\n-\t\t * The precision check is fairly arbitrary but is based on what\n-\t\t * the rkisp1 is capable of in the crosstalk module.\n-\t\t */\n-\t\tdouble f = utils::fixedToFloatingPoint<IntPrec, FracPrec, double>(ret);\n-\t\tif (std::abs(f - input) > 0.005) {\n-\t\t\tcerr << \"Reverse conversion expected \" << ret\n-\t\t\t     << \" to convert to \" << input\n-\t\t\t     << \", got \" << f << std::endl;\n+\t\treturn TestPass;\n+\t}\n+\n+\t/* R for real, I for integer */\n+\ttemplate<unsigned int IntPrec, unsigned FracPrec, typename R, typename I>\n+\tint testFloatToFixed(R input, I expected, I *output = nullptr)\n+\t{\n+\t\tI out = utils::floatingToFixedPoint<IntPrec, FracPrec, I>(input);\n+\t\tif (output)\n+\t\t\t*output = out;\n+\t\tif (out != expected) {\n+\t\t\tcerr << \"Expected \" << input << \" to convert to \"\n+\t\t\t     << expected << \", got \" << out << std::endl;\n \t\t\treturn TestFail;\n \t\t}\n \n \t\treturn TestPass;\n \t}\n \n+\t/* R for real, I for integer */\n+\ttemplate<unsigned int IntPrec, unsigned FracPrec, typename R, typename I>\n+\tint testFullConversion(R input, I expected)\n+\t{\n+\t\tI outInt;\n+\t\tR outReal;\n+\t\tint status;\n+\n+\t\tstatus = testFloatToFixed<IntPrec, FracPrec, R, I>(input, expected, &outInt);\n+\t\tif (status != TestPass)\n+\t\t\treturn status;\n+\n+\t\tstatus = testFixedToFloat<IntPrec, FracPrec, I, R>(outInt, input, &outReal);\n+\t\tif (status != TestPass)\n+\t\t\treturn status;\n+\n+\t\treturn TestPass;\n+\t}\n+\n+\n \tint testFixedPoint()\n \t{\n \t\t/*\n \t\t * The second 7.992 test is to test that unused bits don't\n \t\t * affect the result.\n+\t\t *\n+\t\t * Third parameter is for testing forward, fourth parameter is\n+\t\t * for testing reverse.\n \t\t */\n-\t\tstd::map<double, uint16_t> testCases = {\n-\t\t\t{ 7.992, 0x3ff },\n-\t\t\t{ 7.992, 0xbff },\n-\t\t\t{   0.2, 0x01a },\n-\t\t\t{  -0.2, 0x7e6 },\n-\t\t\t{  -0.8, 0x79a },\n-\t\t\t{  -0.4, 0x7cd },\n-\t\t\t{  -1.4, 0x74d },\n-\t\t\t{    -8, 0x400 },\n-\t\t\t{     0, 0 },\n+\t\tstatic const std::tuple<double, uint16_t, bool, bool> testCases[] = {\n+\t\t\t{ 7.992, 0x3ff,  true, true },\n+\t\t\t{ 7.992, 0xbff, false, true },\n+\t\t\t{   0.2, 0x01a,  true, true },\n+\t\t\t{  -0.2, 0x7e6,  true, true },\n+\t\t\t{  -0.8, 0x79a,  true, true },\n+\t\t\t{  -0.4, 0x7cd,  true, true },\n+\t\t\t{  -1.4, 0x74d,  true, true },\n+\t\t\t{    -8, 0x400,  true, true },\n+\t\t\t{     0,     0,  true, true },\n \t\t};\n \n \t\tint ret;\n \t\tfor (const auto &testCase : testCases) {\n-\t\t\tret = testSingleFixedPoint<4, 7, uint16_t>(testCase.first,\n-\t\t\t\t\t\t\t\t   testCase.second);\n+\t\t\tdouble floating;\n+\t\t\tuint16_t fixed;\n+\t\t\tbool forward, backward;\n+\t\t\tstd::tie(floating, fixed, forward, backward) = testCase;\n+\t\t\tif (forward && backward)\n+\t\t\t\tret = testFullConversion<4, 7, double, uint16_t>(floating, fixed);\n+\t\t\telse if (forward)\n+\t\t\t\tret = testFloatToFixed<4, 7, double, uint16_t>(floating, fixed);\n+\t\t\telse if (backward)\n+\t\t\t\tret = testFixedToFloat<4, 7, uint16_t, double>(fixed, floating);\n+\n \t\t\tif (ret != TestPass)\n \t\t\t\treturn ret;\n \t\t}\n",
    "prefixes": []
}