[{"id":34100,"web_url":"https://patchwork.libcamera.org/comment/34100/","msgid":"<174617230579.1586992.9724528768103785519@ping.linuxembedded.co.uk>","date":"2025-05-02T07:51:45","subject":"Re: [PATCH v3 06/16] test: Add minimal test for Matrix","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Stefan Klug (2025-04-03 16:49:11)\n> Add a few tests for the Matrix class. This is not full fledged but at\n> least a starter.\n> \n> Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> \n> ---\n> \n> Changes in v2:\n> - Added this patch\n> \n> Changes in v3:\n> - Fixed test class name\n> ---\n>  test/matrix.cpp  | 53 ++++++++++++++++++++++++++++++++++++++++++++++++\n>  test/meson.build |  1 +\n>  2 files changed, 54 insertions(+)\n>  create mode 100644 test/matrix.cpp\n> \n> diff --git a/test/matrix.cpp b/test/matrix.cpp\n> new file mode 100644\n> index 000000000000..3a1c8b4c88a2\n> --- /dev/null\n> +++ b/test/matrix.cpp\n> @@ -0,0 +1,53 @@\n> +/* SPDX-License-Identifier: GPL-2.0-or-later */\n> +/*\n> + * Copyright (C) 2024, Ideas on Board Oy\n> + *\n> + * Vector tests\n> + */\n> +\n> +#include \"libcamera/internal/matrix.h\"\n> +\n> +#include <cmath>\n> +#include <iostream>\n> +\n> +#include \"test.h\"\n> +\n> +using namespace libcamera;\n> +\n> +#define ASSERT_EQ(a, b)                                                   \\\n> +       if ((a) != (b)) {                                                 \\\n> +               std::cout << #a \" != \" #b << \" (line \" << __LINE__ << \")\" \\\n> +                         << std::endl;                                   \\\n> +               return TestFail;                                          \\\n> +       }\n> +\n> +class MatrixTest : public Test\n> +{\n> +protected:\n> +       int run()\n> +       {\n> +               Matrix<double, 3, 3> m1;\n> +\n> +               ASSERT_EQ(m1[0][0], 0.0);\n> +               ASSERT_EQ(m1[0][1], 0.0);\n> +\n> +               constexpr Matrix<float, 2, 2> m2 = Matrix<float, 2, 2>().identity();\n> +               ASSERT_EQ(m2[0][0], 1.0);\n> +               ASSERT_EQ(m2[0][1], 0.0);\n> +               ASSERT_EQ(m2[1][0], 0.0);\n> +               ASSERT_EQ(m2[1][1], 1.0);\n> +\n> +               Matrix<float, 2, 2> m3{ { 2.0, 0.0, 0.0, 2.0 } };\n> +               Matrix<float, 2, 2> m4 = m3.inverse();\n\nAre there any corner cases we should test on the inverse()?\n\nAnyway, this gets it in place!\n\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n> +\n> +               Matrix<float, 2, 2> m5 = m3 * m4;\n> +               ASSERT_EQ(m5[0][0], 1.0);\n> +               ASSERT_EQ(m5[0][1], 0.0);\n> +               ASSERT_EQ(m5[1][0], 0.0);\n> +               ASSERT_EQ(m5[1][1], 1.0);\n> +\n> +               return TestPass;\n> +       }\n> +};\n> +\n> +TEST_REGISTER(MatrixTest)\n> diff --git a/test/meson.build b/test/meson.build\n> index 4095664994fd..52f04364e4fc 100644\n> --- a/test/meson.build\n> +++ b/test/meson.build\n> @@ -60,6 +60,7 @@ internal_tests = [\n>      {'name': 'file', 'sources': ['file.cpp']},\n>      {'name': 'flags', 'sources': ['flags.cpp']},\n>      {'name': 'hotplug-cameras', 'sources': ['hotplug-cameras.cpp']},\n> +    {'name': 'matrix', 'sources': ['matrix.cpp']},\n>      {'name': 'message', 'sources': ['message.cpp']},\n>      {'name': 'object', 'sources': ['object.cpp']},\n>      {'name': 'object-delete', 'sources': ['object-delete.cpp']},\n> -- \n> 2.43.0\n>","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 2C50DC327D\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri,  2 May 2025 07:51:51 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 82F9F68B24;\n\tFri,  2 May 2025 09:51:50 +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 C7AA968ACB\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  2 May 2025 09:51:48 +0200 (CEST)","from pendragon.ideasonboard.com\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 F1FAF353;\n\tFri,  2 May 2025 09:51:40 +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=\"HvJ/TsAI\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1746172301;\n\tbh=RWtNRkeochwcMiag9IkkctmnglPwQLcYkQZbpoRQbvg=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=HvJ/TsAIKGf/15oc0hn0dJK5zhggg4vVKbtMW+DjSaPXGhHwiakcQddb33XN4RXuE\n\tIriKq+hsYxeq80+9P8ne/tb/ejICtKFmtYwACVwid/ff0rP3Cr5kFa2S97jHw7JSaG\n\toyt8NQ1m4P0yUcOdDORfgZbiT41+zdijg9P2oig8=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20250403154925.382973-7-stefan.klug@ideasonboard.com>","References":"<20250403154925.382973-1-stefan.klug@ideasonboard.com>\n\t<20250403154925.382973-7-stefan.klug@ideasonboard.com>","Subject":"Re: [PATCH v3 06/16] test: Add minimal test for Matrix","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"Stefan Klug <stefan.klug@ideasonboard.com>,\n\tLaurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Stefan Klug <stefan.klug@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Fri, 02 May 2025 08:51:45 +0100","Message-ID":"<174617230579.1586992.9724528768103785519@ping.linuxembedded.co.uk>","User-Agent":"alot/0.10","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>"}},{"id":34143,"web_url":"https://patchwork.libcamera.org/comment/34143/","msgid":"<aBuNwDDOrn0eNMN6@pyrite.rasen.tech>","date":"2025-05-07T16:43:44","subject":"Re: [PATCH v3 06/16] test: Add minimal test for Matrix","submitter":{"id":17,"url":"https://patchwork.libcamera.org/api/people/17/","name":"Paul Elder","email":"paul.elder@ideasonboard.com"},"content":"On Thu, Apr 03, 2025 at 05:49:11PM +0200, Stefan Klug wrote:\n> Add a few tests for the Matrix class. This is not full fledged but at\n> least a starter.\n> \n> Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> \n> ---\n> \n> Changes in v2:\n> - Added this patch\n> \n> Changes in v3:\n> - Fixed test class name\n> ---\n>  test/matrix.cpp  | 53 ++++++++++++++++++++++++++++++++++++++++++++++++\n>  test/meson.build |  1 +\n>  2 files changed, 54 insertions(+)\n>  create mode 100644 test/matrix.cpp\n> \n> diff --git a/test/matrix.cpp b/test/matrix.cpp\n> new file mode 100644\n> index 000000000000..3a1c8b4c88a2\n> --- /dev/null\n> +++ b/test/matrix.cpp\n> @@ -0,0 +1,53 @@\n> +/* SPDX-License-Identifier: GPL-2.0-or-later */\n> +/*\n> + * Copyright (C) 2024, Ideas on Board Oy\n> + *\n> + * Vector tests\n\ns/Vector/Matrix/ ...?\n\nReviewed-by: Paul Elder <paul.elder@ideasonboard.com>\n\n> + */\n> +\n> +#include \"libcamera/internal/matrix.h\"\n> +\n> +#include <cmath>\n> +#include <iostream>\n> +\n> +#include \"test.h\"\n> +\n> +using namespace libcamera;\n> +\n> +#define ASSERT_EQ(a, b)                                                   \\\n> +\tif ((a) != (b)) {                                                 \\\n> +\t\tstd::cout << #a \" != \" #b << \" (line \" << __LINE__ << \")\" \\\n> +\t\t\t  << std::endl;                                   \\\n> +\t\treturn TestFail;                                          \\\n> +\t}\n> +\n> +class MatrixTest : public Test\n> +{\n> +protected:\n> +\tint run()\n> +\t{\n> +\t\tMatrix<double, 3, 3> m1;\n> +\n> +\t\tASSERT_EQ(m1[0][0], 0.0);\n> +\t\tASSERT_EQ(m1[0][1], 0.0);\n> +\n> +\t\tconstexpr Matrix<float, 2, 2> m2 = Matrix<float, 2, 2>().identity();\n> +\t\tASSERT_EQ(m2[0][0], 1.0);\n> +\t\tASSERT_EQ(m2[0][1], 0.0);\n> +\t\tASSERT_EQ(m2[1][0], 0.0);\n> +\t\tASSERT_EQ(m2[1][1], 1.0);\n> +\n> +\t\tMatrix<float, 2, 2> m3{ { 2.0, 0.0, 0.0, 2.0 } };\n> +\t\tMatrix<float, 2, 2> m4 = m3.inverse();\n> +\n> +\t\tMatrix<float, 2, 2> m5 = m3 * m4;\n> +\t\tASSERT_EQ(m5[0][0], 1.0);\n> +\t\tASSERT_EQ(m5[0][1], 0.0);\n> +\t\tASSERT_EQ(m5[1][0], 0.0);\n> +\t\tASSERT_EQ(m5[1][1], 1.0);\n> +\n> +\t\treturn TestPass;\n> +\t}\n> +};\n> +\n> +TEST_REGISTER(MatrixTest)\n> diff --git a/test/meson.build b/test/meson.build\n> index 4095664994fd..52f04364e4fc 100644\n> --- a/test/meson.build\n> +++ b/test/meson.build\n> @@ -60,6 +60,7 @@ internal_tests = [\n>      {'name': 'file', 'sources': ['file.cpp']},\n>      {'name': 'flags', 'sources': ['flags.cpp']},\n>      {'name': 'hotplug-cameras', 'sources': ['hotplug-cameras.cpp']},\n> +    {'name': 'matrix', 'sources': ['matrix.cpp']},\n>      {'name': 'message', 'sources': ['message.cpp']},\n>      {'name': 'object', 'sources': ['object.cpp']},\n>      {'name': 'object-delete', 'sources': ['object-delete.cpp']},\n> -- \n> 2.43.0\n>","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 1CDC3C3226\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  7 May 2025 16:43:50 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 6BCB668B2F;\n\tWed,  7 May 2025 18:43:49 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id D926868AD8\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  7 May 2025 18:43:47 +0200 (CEST)","from pyrite.rasen.tech (unknown\n\t[IPv6:2001:861:3a80:3300:4f2f:8c2c:b3ef:17d4])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 293F86D5;\n\tWed,  7 May 2025 18:43:36 +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=\"Lmqsv8c5\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1746636216;\n\tbh=Y7GSoP8A+4IAuFL7429AFBpUClfC1uARgcRFCKtcky4=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=Lmqsv8c5cSKhxRBGQg1Z6TTHg0nwmdcEQppiBCJCPGtE1tzWQuByP6kuaxIg2usKc\n\txaIEWg+Yog0XCLL0I+U3INh4ySgSIWVfCFoC8mc3ZTNKRMMr7sUzV9A1kuTaU+ORkI\n\t02k5B/TJhStCu9bs9QEhwqBycZHwqmLRud76cUsM=","Date":"Wed, 7 May 2025 18:43:44 +0200","From":"Paul Elder <paul.elder@ideasonboard.com>","To":"Stefan Klug <stefan.klug@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org,\n\tLaurent Pinchart <laurent.pinchart@ideasonboard.com>","Subject":"Re: [PATCH v3 06/16] test: Add minimal test for Matrix","Message-ID":"<aBuNwDDOrn0eNMN6@pyrite.rasen.tech>","References":"<20250403154925.382973-1-stefan.klug@ideasonboard.com>\n\t<20250403154925.382973-7-stefan.klug@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=us-ascii","Content-Disposition":"inline","In-Reply-To":"<20250403154925.382973-7-stefan.klug@ideasonboard.com>","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>"}}]