{"id":25034,"url":"https://patchwork.libcamera.org/api/patches/25034/?format=json","web_url":"https://patchwork.libcamera.org/patch/25034/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20251114005428.90024-5-kieran.bingham@ideasonboard.com>","date":"2025-11-14T00:54:08","name":"[v4,04/21] test: libipa: Provide FixedPoint Quantized tests","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"02e9a79ef63787d850285f0f0ec03c3cd2f5f9ec","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/?format=json","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/25034/mbox/","series":[{"id":5589,"url":"https://patchwork.libcamera.org/api/series/5589/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=5589","date":"2025-11-14T00:54:04","name":"libipa: Introduce a Quantized type","version":4,"mbox":"https://patchwork.libcamera.org/series/5589/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/25034/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/25034/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 A64A3C32DB\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 14 Nov 2025 00:54:59 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id B1A8960AB1;\n\tFri, 14 Nov 2025 01:54:53 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 6DB79609E0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 14 Nov 2025 01:54:49 +0100 (CET)","from charm.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 E331E19B5;\n\tFri, 14 Nov 2025 01:52:48 +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=\"PXVI2SSY\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1763081569;\n\tbh=n3/3tFyiHOCWPNZM8/CpMp27FgZ2l3bqMyskBwyknmk=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=PXVI2SSYPXGiIbSQMyt9LkzulfV1R08+bH/BCSRFQ9GWNwU0jIjIo94Hsfw2/MZOV\n\tRh2fTU1ri7pQNICSSKxVoUzGNfvxS5ojK5d4TnmTMKqWenEMbdO21BkP9Yss/T5Vf5\n\tAX9O76WCc71hnzEZzY2GDRTdtJzoCJgGYb8DBDUA=","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","To":"libcamera devel <libcamera-devel@lists.libcamera.org>","Cc":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Subject":"[PATCH v4 04/21] test: libipa: Provide FixedPoint Quantized tests","Date":"Fri, 14 Nov 2025 00:54:08 +0000","Message-ID":"<20251114005428.90024-5-kieran.bingham@ideasonboard.com>","X-Mailer":"git-send-email 2.51.1","In-Reply-To":"<20251114005428.90024-1-kieran.bingham@ideasonboard.com>","References":"<20251114005428.90024-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":"Validate the new fixed-point Quantized types with tests covering Q1.7,\nUQ1.7, Q12.4 and UQ12.4 types.\n\nSigned-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n---\nv3:\n- Rename quantized_type to QuantizedType\n\n test/ipa/libipa/fixedpoint.cpp | 120 +++++++++++++++++++++++++++++++--\n 1 file changed, 116 insertions(+), 4 deletions(-)","diff":"diff --git a/test/ipa/libipa/fixedpoint.cpp b/test/ipa/libipa/fixedpoint.cpp\nindex 99eb662ddf4e..935412771851 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,124 @@ 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\tcerr << \"  Checking \" << input << \" == \" << q.toString() << std::endl;\n+\n+\t\tT quantized = q.quantized();\n+\t\tif (quantized != expected) {\n+\t\t\tcerr << \"    ** Q Expected \" << input\n+\t\t\t     << \" to quantize to \" << utils::hex(expected)\n+\t\t\t     << \", got \" << utils::hex(quantized)\n+\t\t\t     << \" - (\" << q.toString() << \")\"\n+\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\tcerr << \"    ** V Expected \" << input\n+\t\t\t     << \" to quantize to \" << value\n+\t\t\t     << \", got \" << q.value()\n+\t\t\t     << \" - (\" << q.toString() << \")\"\n+\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+\tint introduce(std::string type)\n+\t{\n+\t\tusing T = typename Q::QuantizedType;\n+\n+\t\tstd::cerr << std::endl;\n+\n+\t\tcerr << type << \"(\" << Q::TraitsType::min << \" .. \" << Q::TraitsType::max << \") \"\n+\t\t     << \" Min: \" << Q(Q::TraitsType::min).toString()\n+\t\t     << \" -- Max: \" << Q(Q::TraitsType::max).toString()\n+\t\t     << \" Step:\" << Q(T(1)).value()\n+\t\t     << std::endl;\n+\n+\t\tif (Q::TraitsType::min > Q::TraitsType::max) {\n+\t\t\tcerr << \"    *** \" << type\n+\t\t\t     << \" Min (\" << Q::TraitsType::min\n+\t\t\t     << \") must be less than max (\"\n+\t\t\t     << Q::TraitsType::max << \")\" << std::endl;\n+\t\t\treturn 1;\n+\t\t}\n+\n+\t\treturn 0;\n+\t}\n+\n+\tint testFixedPointQuantizers()\n+\t{\n+\t\tunsigned int fails = 0;\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\tfails += introduce<Q1_7>(\"Q1_7\");\n+\t\tfails += quantizedCheck<Q1_7>(-1.000f, 0b1'0000000, -1.0f);\t\t/* Min */\n+\t\tfails += quantizedCheck<Q1_7>(-0.992f, 0b1'0000001, -0.992188f);\t/* Min + 1 step */\n+\t\tfails += quantizedCheck<Q1_7>(-0.006f, 0b1'1111111, -0.0078125f);\t/* -1 step */\n+\t\tfails += quantizedCheck<Q1_7>( 0.000f, 0b0'0000000,  0.0f);\t\t/* Zero */\n+\t\tfails += quantizedCheck<Q1_7>( 0.008f, 0b0'0000001,  0.0078125f);\t/* +1 step */\n+\t\tfails += quantizedCheck<Q1_7>( 0.992f, 0b0'1111111,  0.992188f);\t/* Max */\n+\n+\t\t/* UQ1_7(0 .. 1.99219)  Min: [0x00:0] -- Max: [0xff:1.99219] Step:0.0078125 */\n+\t\tfails += introduce<UQ1_7>(\"UQ1_7\");\n+\t\tfails += quantizedCheck<UQ1_7>(0.0f,   0b0'0000000, 0.0f);\t\t/* Min / Zero */\n+\t\tfails += quantizedCheck<UQ1_7>(1.0f,   0b1'0000000, 1.0f);\t\t/* Mid */\n+\t\tfails += quantizedCheck<UQ1_7>(1.992f, 0b1'1111111, 1.99219f);\t\t/* Max */\n+\n+\t\t/* Q12.4(-2048 .. 2047.94)  Min: [0x8000:-2048] -- Max: [0x7fff:2047.94] Step:0.0625 */\n+\t\tintroduce<Q12_4>(\"Q12_4\");\n+\t\tfails += quantizedCheck<Q12_4>(0.0f, 0b000000000000'0000, 0.0f);\n+\t\tfails += quantizedCheck<Q12_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<UQ12_4>(\"UQ12_4\");\n+\t\tfails += quantizedCheck<UQ12_4>(0.0f, 0b000000000000'0000, 0.0f);\n+\t\tfails += quantizedCheck<UQ12_4>(7.5f, 0b000000000111'1000, 7.5f);\n+\n+\t\t/* Validate that exceeding limits clamps to type range */\n+\t\tcerr << std::endl << \"Range validation:\" << std::endl;\n+\t\tfails += quantizedCheck<Q1_7>(-100.0f, 0b1'0000000, -1.0f);\n+\t\tfails += quantizedCheck<Q1_7>(+100.0f, 0b0'1111111, 0.992188f);\n+\t\tfails += quantizedCheck<UQ1_7>(-100.0f, 0b0'0000000, 0.0f);\n+\t\tfails += quantizedCheck<UQ1_7>(+100.0f, 0b1'1111111, 1.99219f);\n+\n+\t\t/* clang-format on */\n+\n+\t\tstd::cerr << std::endl;\n+\n+\t\tif (fails > 0) {\n+\t\t\tcerr << \"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":["v4","04/21"]}