Patch Detail
Show a patch.
GET /api/patches/25912/?format=api
{ "id": 25912, "url": "https://patchwork.libcamera.org/api/patches/25912/?format=api", "web_url": "https://patchwork.libcamera.org/patch/25912/", "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": "<20260121173737.376113-6-kieran.bingham@ideasonboard.com>", "date": "2026-01-21T17:37:24", "name": "[v6,05/16] test: libipa: Provide FixedPoint Quantized tests", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "3e5867ca2f429aef8f57652aacbf5ce15eaf1a93", "submitter": { "id": 4, "url": "https://patchwork.libcamera.org/api/people/4/?format=api", "name": "Kieran Bingham", "email": "kieran.bingham@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/25912/mbox/", "series": [ { "id": 5730, "url": "https://patchwork.libcamera.org/api/series/5730/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=5730", "date": "2026-01-21T17:37:19", "name": "libipa: Introduce a Quantized type", "version": 6, "mbox": "https://patchwork.libcamera.org/series/5730/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/25912/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/25912/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 69803BDCBF\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 21 Jan 2026 17:37:54 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 6990361FEC;\n\tWed, 21 Jan 2026 18:37:51 +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 2E64461FCF\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 21 Jan 2026 18:37:43 +0100 (CET)", "from Monstersaurus.hippo-penny.ts.net\n\t(cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 34DC11E31;\n\tWed, 21 Jan 2026 18:37:11 +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=\"ehk4YfEb\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1769017031;\n\tbh=YPKAZ8pQo2lbCK5qntmjX92Vn+/WMTCEJzmlbRelYro=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=ehk4YfEbY7EXfZ5GcnG0V2xG1vvvKcG4ItBZ8xAY566UUJjCngU5kZzjzqYivGrrh\n\tmCYs5PRrmSwK/eAyA1XpO+OYCID80aO/rjgmxesNNdpoWUjUyslUqAu7zW9NMjHyTH\n\tLPfSiWgXlChuKeYROXd3mmuB/sO8T2VclBtQaUoA=", "From": "Kieran Bingham <kieran.bingham@ideasonboard.com>", "To": "libcamera devel <libcamera-devel@lists.libcamera.org>", "Cc": "Kieran Bingham <kieran.bingham@ideasonboard.com>", "Subject": "[PATCH v6 05/16] test: libipa: Provide FixedPoint Quantized tests", "Date": "Wed, 21 Jan 2026 17:37:24 +0000", "Message-ID": "<20260121173737.376113-6-kieran.bingham@ideasonboard.com>", "X-Mailer": "git-send-email 2.52.0", "In-Reply-To": "<20260121173737.376113-1-kieran.bingham@ideasonboard.com>", "References": "<20260121173737.376113-1-kieran.bingham@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": "Provide tests to validate the conditions of FixedPoint types used\nwithin libcamera explicitly.\n\nSigned-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n---\nv3:\n- Rename quantized_type to QuantizedType\n\nv5:\n\n- Use string_view for introduction of type\n- move min/max check to static assert\n- Squash down all tests into a single implementation and remove extra\n type proliferation.\n- Use Q/UQ types directly.\n- use std::cout consistently\n\nv6:\n- Add notes on test introduction\n- Expand Q12.4 to include clamp tests to validate int16_t range usage\n- Add storage selection assertion checks\n- Move clamp checks to their types to expand\n- Add {U,}Q<4,20> to check up to 24 bit precision\n\nSigned-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n---\n test/ipa/libipa/fixedpoint.cpp | 162 ++++++++++++++++++++++++++++++++-\n 1 file changed, 158 insertions(+), 4 deletions(-)", "diff": "diff --git a/test/ipa/libipa/fixedpoint.cpp b/test/ipa/libipa/fixedpoint.cpp\nindex 4b017e86a74f..500cd308be98 100644\n--- a/test/ipa/libipa/fixedpoint.cpp\n+++ b/test/ipa/libipa/fixedpoint.cpp\n@@ -5,12 +5,14 @@\n * Fixed / Floating point utility tests\n */\n \n+#include \"../src/ipa/libipa/fixedpoint.h\"\n+\n #include <cmath>\n #include <iostream>\n #include <map>\n #include <stdint.h>\n \n-#include \"../src/ipa/libipa/fixedpoint.h\"\n+#include <libcamera/base/utils.h>\n \n #include \"test.h\"\n \n@@ -95,14 +97,166 @@ protected:\n \t\treturn TestPass;\n \t}\n \n-\tint run()\n+\ttemplate<typename Q>\n+\tint quantizedCheck(float input, typename Q::QuantizedType expected, float value)\n \t{\n-\t\t/* fixed point conversion test */\n-\t\tif (testFixedPoint() != TestPass)\n+\t\tQ q(input);\n+\t\tusing T = typename Q::QuantizedType;\n+\n+\t\tstd::cout << \" Checking \" << input << \" == \" << q << std::endl;\n+\n+\t\tT quantized = q.quantized();\n+\t\tif (quantized != expected) {\n+\t\t\tstd::cout << \" ** Q Expected \" << input\n+\t\t\t\t << \" to quantize to \" << utils::hex(expected)\n+\t\t\t\t << \", got \" << utils::hex(quantized)\n+\t\t\t\t << \" - (\" << q << \")\"\n+\t\t\t\t << std::endl;\n+\t\t\treturn 1;\n+\t\t}\n+\n+\t\tif ((std::abs(q.value() - value)) > 0.0001f) {\n+\t\t\tstd::cout << \" ** V Expected \" << input\n+\t\t\t\t << \" to quantize to \" << value\n+\t\t\t\t << \", got \" << q.value()\n+\t\t\t\t << \" - (\" << q << \")\"\n+\t\t\t\t << std::endl;\n+\t\t\treturn 1;\n+\t\t}\n+\n+\t\treturn 0;\n+\t}\n+\n+\ttemplate<typename Q>\n+\tvoid introduce(std::string_view type)\n+\t{\n+\t\tusing T = typename Q::QuantizedType;\n+\n+\t\tstd::cout << std::endl;\n+\n+\t\tstd::cout << type\n+\t\t\t << \"(\" << Q::TraitsType::min << \" .. \" << Q::TraitsType::max << \") \"\n+\t\t\t << \" Min: \" << Q(Q::TraitsType::min)\n+\t\t\t << \" -- Max: \" << Q(Q::TraitsType::max)\n+\t\t\t << \" Step:\" << Q(T(1)).value()\n+\t\t\t << std::endl;\n+\t}\n+\n+\tint testFixedPointQuantizers()\n+\t{\n+\t\tunsigned int fails = 0;\n+\n+\t\t/*\n+\t\t * These aim to specifically test all the corner cases of the\n+\t\t * quantization and de-quantization process. Including clamping\n+\t\t * to min/max, zero points and making sure that steps are\n+\t\t * correct.\n+\t\t *\n+\t\t * In particular test signed and unsigned types and a mix of the\n+\t\t * highest bit width of a storage type and smaller widths that\n+\t\t * require bit masking and sign extension.\n+\t\t *\n+\t\t * Note we must hard code these. Any calculation of expected\n+\t\t * values risks replicating bugs in the implementation.\n+\t\t *\n+\t\t * As the underlying types are integer and float the limit of\n+\t\t * precision is around 24 bits so we do not test wider types.\n+\t\t */\n+\n+\t\t/* clang-format off */\n+\n+\t\t/* Q1.7(-1 .. 0.992188) Min: [0x80:-1] -- Max: [0x7f:0.992188] Step:0.0078125*/\n+\t\tintroduce<Q<1, 7>>(\"Q1.7\");\n+\t\tfails += quantizedCheck<Q<1, 7>>(-2.000f, 0b1'0000000, -1.0f);\t\t/* Clamped to Min */\n+\t\tfails += quantizedCheck<Q<1, 7>>(-1.000f, 0b1'0000000, -1.0f);\t\t/* Min */\n+\t\tfails += quantizedCheck<Q<1, 7>>(-0.992f, 0b1'0000001, -0.992188f);\t/* Min + 1 step */\n+\t\tfails += quantizedCheck<Q<1, 7>>(-0.006f, 0b1'1111111, -0.0078125f);\t/* -1 step */\n+\t\tfails += quantizedCheck<Q<1, 7>>( 0.000f, 0b0'0000000, 0.0f);\t\t/* Zero */\n+\t\tfails += quantizedCheck<Q<1, 7>>( 0.008f, 0b0'0000001, 0.0078125f);\t/* +1 step */\n+\t\tfails += quantizedCheck<Q<1, 7>>( 0.992f, 0b0'1111111, 0.992188f);\t/* Max */\n+\t\tfails += quantizedCheck<Q<1, 7>>( 2.000f, 0b0'1111111, 0.992188f);\t/* Clamped to Max */\n+\n+\t\t/* UQ1.7(0 .. 1.99219) Min: [0x00:0] -- Max: [0xff:1.99219] Step:0.0078125 */\n+\t\tintroduce<UQ<1, 7>>(\"UQ1.7\");\n+\t\tfails += quantizedCheck<UQ<1, 7>>(-1.0f, 0b0'0000000, 0.0f);\t\t/* Clamped to Min */\n+\t\tfails += quantizedCheck<UQ<1, 7>>( 0.0f, 0b0'0000000, 0.0f);\t\t/* Min / Zero */\n+\t\tfails += quantizedCheck<UQ<1, 7>>( 1.0f, 0b1'0000000, 1.0f);\t\t/* Mid */\n+\t\tfails += quantizedCheck<UQ<1, 7>>( 1.992f, 0b1'1111111, 1.99219f);\t/* Max */\n+\t\tfails += quantizedCheck<UQ<1, 7>>( 2.000f, 0b1'1111111, 1.99219f);\t/* Clamped to Max */\n+\n+\t\t/* UQ4.8(0 .. 15.9961) Min: [0x0000:0] -- Max: [0x0fff:15.9961] Step:0.00390625 */\n+\t\tintroduce<UQ<4, 8>>(\"UQ4.8\");\n+\t\tfails += quantizedCheck<UQ<4, 8>>( 0.0f, 0b0000'00000000, 0.00f);\n+\t\tfails += quantizedCheck<UQ<4, 8>>(16.0f, 0b1111'11111111, 15.9961f);\n+\n+\t\t/* Q5.4(-16 .. 15.9375) Min: [0x0100:-16] -- Max: [0x00ff:15.9375] Step:0.0625 */\n+\t\tintroduce<Q<5, 4>>(\"Q5.4\");\n+\t\tfails += quantizedCheck<Q<5, 4>>(-16.00f, 0b10000'0000, -16.00f);\n+\t\tfails += quantizedCheck<Q<5, 4>>( 15.94f, 0b01111'1111, 15.9375f);\n+\n+\t\t/* UQ5.8(0 .. 31.9961) Min: [0x0000:0] -- Max: [0x1fff:31.9961] Step:0.00390625 */\n+\t\tintroduce<UQ<5, 8>>(\"UQ5.8\");\n+\t\tfails += quantizedCheck<UQ<5, 8>>( 0.00f, 0b00000'00000000, 0.00f);\n+\t\tfails += quantizedCheck<UQ<5, 8>>(32.00f, 0b11111'11111111, 31.9961f);\n+\n+\t\t/* Q12.4(-2048 .. 2047.94) Min: [0x8000:-2048] -- Max: [0x7fff:2047.94] Step:0.0625 */\n+\t\tintroduce<Q<12, 4>>(\"Q12.4\");\n+\t\tfails += quantizedCheck<Q<12, 4>>( 0.0f, 0b000000000000'0000, 0.0f);\n+\t\tfails += quantizedCheck<Q<12, 4>>( 7.5f, 0b000000000111'1000, 7.5f);\n+\n+\t\t/* UQ12.4(0 .. 4095.94) Min: [0x0000:0] -- Max: [0xffff:4095.94] Step:0.0625 */\n+\t\tintroduce<UQ<12, 4>>(\"UQ12.4\");\n+\t\tfails += quantizedCheck<UQ<12, 4>>(0.0f, 0b000000000000'0000, 0.0f);\n+\t\tfails += quantizedCheck<UQ<12, 4>>(7.5f, 0b000000000111'1000, 7.5f);\n+\n+\t\t/* Q4.20 */\n+\t\tintroduce<Q<4, 20>>(\"Q4.20\");\n+\t\tfails += quantizedCheck<Q<4, 20>>( -9.0f, 0b1000'00000000000000000000, -8.0f);\n+\t\tfails += quantizedCheck<Q<4, 20>>( -8.0f, 0b1000'00000000000000000000, -8.0f);\n+\t\tfails += quantizedCheck<Q<4, 20>>( 8.0f, 0b0111'11111111111111111111, 8.0f);\n+\t\tfails += quantizedCheck<Q<4, 20>>( 9.0f, 0b0111'11111111111111111111, 8.0f);\n+\n+\t\t/* UQ4.20 */\n+\t\tintroduce<UQ<4, 20>>(\"UQ4.20\");\n+\t\tfails += quantizedCheck<UQ<4, 20>>(-1.0f, 0b0000'00000000000000000000, 0.0f);\n+\t\tfails += quantizedCheck<UQ<4, 20>>( 0.0f, 0b0000'00000000000000000000, 0.0f);\n+\t\tfails += quantizedCheck<UQ<4, 20>>(16.0f, 0b1111'11111111111111111111, 16.0f);\n+\t\tfails += quantizedCheck<UQ<4, 20>>(20.0f, 0b1111'11111111111111111111, 16.0f);\n+\n+\t\t/* Storage selection tests */\n+\t\tstatic_assert(std::is_same_v<typename Q<4, 4>::TraitsType::QuantizedType, int8_t>);\n+\t\tstatic_assert(std::is_same_v<typename UQ<4, 4>::TraitsType::QuantizedType, uint8_t>);\n+\t\tstatic_assert(std::is_same_v<typename Q<8, 8>::TraitsType::QuantizedType, int16_t>);\n+\t\tstatic_assert(std::is_same_v<typename UQ<8, 8>::TraitsType::QuantizedType, uint16_t>);\n+\t\tstatic_assert(std::is_same_v<typename Q<20, 4>::TraitsType::QuantizedType, int32_t>);\n+\t\tstatic_assert(std::is_same_v<typename UQ<20, 4>::TraitsType::QuantizedType, uint32_t>);\n+\n+\t\t/* clang-format on */\n+\n+\t\tstd::cout << std::endl;\n+\n+\t\tif (fails > 0) {\n+\t\t\tcout << \"Fixed point quantizer tests failed: \"\n+\t\t\t << std::dec << fails << \" failures.\" << std::endl;\n \t\t\treturn TestFail;\n+\t\t}\n \n \t\treturn TestPass;\n \t}\n+\n+\tint run()\n+\t{\n+\t\tunsigned int fails = 0;\n+\n+\t\t/* fixed point conversion test */\n+\t\tif (testFixedPoint() != TestPass)\n+\t\t\tfails++;\n+\n+\t\tif (testFixedPointQuantizers() != TestPass)\n+\t\t\tfails++;\n+\n+\t\treturn fails ? TestFail : TestPass;\n+\t}\n };\n \n TEST_REGISTER(FixedPointUtilsTest)\n", "prefixes": [ "v6", "05/16" ] }