{"id":18432,"url":"https://patchwork.libcamera.org/api/patches/18432/?format=json","web_url":"https://patchwork.libcamera.org/patch/18432/","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":"<20230322130612.5208-6-naush@raspberrypi.com>","date":"2023-03-22T13:06:07","name":"[libcamera-devel,v1,05/10] ipa: raspberrypi: alsc: Use a better type name for sparse arrays","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"c0eddf9838a1b38bca38c4fdf6282a7f8f921581","submitter":{"id":34,"url":"https://patchwork.libcamera.org/api/people/34/?format=json","name":"Naushir Patuck","email":"naush@raspberrypi.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/18432/mbox/","series":[{"id":3810,"url":"https://patchwork.libcamera.org/api/series/3810/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=3810","date":"2023-03-22T13:06:02","name":"Raspberry Pi: Generalised algorithms","version":1,"mbox":"https://patchwork.libcamera.org/series/3810/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/18432/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/18432/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 361E3C329F\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 22 Mar 2023 13:06:28 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id C1D4662716;\n\tWed, 22 Mar 2023 14:06:27 +0100 (CET)","from mail-io1-xd2e.google.com (mail-io1-xd2e.google.com\n\t[IPv6:2607:f8b0:4864:20::d2e])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 7D283626DB\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 22 Mar 2023 14:06:23 +0100 (CET)","by mail-io1-xd2e.google.com with SMTP id m22so8407009ioy.4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 22 Mar 2023 06:06:23 -0700 (PDT)","from localhost.localdomain ([93.93.133.154])\n\tby smtp.gmail.com with ESMTPSA id\n\tl6-20020a026646000000b003c488204c6fsm4927960jaf.76.2023.03.22.06.06.21\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tWed, 22 Mar 2023 06:06:22 -0700 (PDT)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1679490387;\n\tbh=GzdIKbckX0bRqpgpUVf0MR/k60yQLQR4p9/YtYtkHlU=;\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=gVcAPgT6Hx4EC+zS/Wd2/W7N/u9dxhkrKDaq72vIHH3twX38TGSQbHuOqtL20T2y1\n\to9gXV0/48sfMwfGrXkggBbnk6ep11TLYDV2u1U2JxA+Sn/230o077+R40mjHVBMZuy\n\tPK496yvYqsvm1dBOLvMsnN4xjA3n/SXZyK7KRHCOlAa18DSasdDfGbt/h6yPsVJRMz\n\t+SzpqGW/rSUCaQ7A4uyqEyP0MLWiGfDMGqljpqlp77O0t303YG2r4ORxOp3wo9BxUh\n\tu4JxYddmIrAWOGx1pWWvhVXbYuLZfQhmoK/VzP6UGo70y9M/P7TdpYz2qSwaz2eyUd\n\tmuhNjAuWjFRmQ==","v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google; t=1679490383;\n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:from:to:cc:subject:date\n\t:message-id:reply-to;\n\tbh=eKdjahHZlI08PdsXsAVyS9pD8aARi8WXwJYPUcC+57Y=;\n\tb=g883W8OVh5Uh0SgWdoS33FtJgYBeXlZcAYc0ghroYnhrp3BgJyO5rjJS1S3P/hd8AB\n\t+fSAyKyz+JjBhTLJet59YbnsAWtus5bFZ/792OD42C6eH/kYoq2/EzrWZHCJ5KOZf2Hl\n\tAOJ2jlEUa0MOuNEfRhSb5u/s2oRBWppI42j/t3/VnCvthT7pJp6f7vTb4qeTB2ry1+XJ\n\t+XgW7/rhnaVUOHljKPFySCD1atu6NBhpv9EhGlExFuw8+iAibWroRae8HK8JamgnKLVW\n\t5rN/TdaZKJEH18VwZi7y+G0pfkvLSWEceewWoqBdd5W4ECYZQsY2QLaHOebJTz7aqu8q\n\t837Q=="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected) header.d=raspberrypi.com\n\theader.i=@raspberrypi.com\n\theader.b=\"g883W8OV\"; dkim-atps=neutral","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112; t=1679490383;\n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc\n\t:subject:date:message-id:reply-to;\n\tbh=eKdjahHZlI08PdsXsAVyS9pD8aARi8WXwJYPUcC+57Y=;\n\tb=rBXvA1rvZgDwT+M0orN6nANwNwKE94VVsw/7D4ejmSJ96mnPFBRBjPQtPiVP7VvFAz\n\t0EXzs/h0TJ2n8deBDY8zEr/6JPu95RjBP+gTUYN8EFJCveVWurcHB4FDmrt20Vom9Nt9\n\tjyOaZr79mnfUZQr2hS87fjqXq5PJIBVh4YXllyVGWMcfEAaJ+zjZm8IymioJi0jFtKxb\n\t6iX1JqdSriE+m8l9eB3t3ededwuvD8DLR1zPGV4OtOm6GJ+noLsmPF7HTc1hMUf6FKZa\n\t3PQIodi/7eGWG0UOOoe6T5Y/fuIh1isbIvIFY7pZtHMFnDcVQOtT3vKHMRfzLpYqjBD5\n\t6Ttw==","X-Gm-Message-State":"AO0yUKWMC7BRZ+TLD1xdl4Vcvya59EWOPEdw/N2HrGOOZUP9nA6W0QaZ\n\tIuehfvIZ9gWy+9Ry+rFM1xu5o8NJ4XyPxBMwfpjA6w==","X-Google-Smtp-Source":"AK7set8WvT6o8fUxeO1cxO3mUZqgX7LK0o9ySCl/98BoHKkpQc99O96ajEww5K6jYtXtXjeNm1GXEg==","X-Received":"by 2002:a5e:de46:0:b0:752:ee32:322d with SMTP id\n\te6-20020a5ede46000000b00752ee32322dmr4002575ioq.18.1679490382932; \n\tWed, 22 Mar 2023 06:06:22 -0700 (PDT)","To":"libcamera-devel@lists.libcamera.org","Date":"Wed, 22 Mar 2023 13:06:07 +0000","Message-Id":"<20230322130612.5208-6-naush@raspberrypi.com>","X-Mailer":"git-send-email 2.34.1","In-Reply-To":"<20230322130612.5208-1-naush@raspberrypi.com>","References":"<20230322130612.5208-1-naush@raspberrypi.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v1 05/10] ipa: raspberrypi: alsc: Use a\n\tbetter type name for sparse arrays","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":"Naushir Patuck via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Naushir Patuck <naush@raspberrypi.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"From: David Plowman <david.plowman@raspberrypi.com>\n\nThe algorithm uses the data type std::vector<std::array<double, 4>> to\nrepresent the large sparse matrices that are XY (X, Y being the ALSC\ngrid size) high but with only 4 non-zero elements on each row.\n\nReplace this slightly long type name by SparseArray<double>.\n\nNo functional changes.\n\nSigned-off-by: David Plowman <david.plowman@raspberrypi.com>\nReviewed-by: Naushir Patuck <naush@raspberrypi.com>\n---\n src/ipa/raspberrypi/controller/rpi/alsc.cpp | 24 ++++++++++-----------\n src/ipa/raspberrypi/controller/rpi/alsc.h   | 10 ++++++++-\n 2 files changed, 21 insertions(+), 13 deletions(-)","diff":"diff --git a/src/ipa/raspberrypi/controller/rpi/alsc.cpp b/src/ipa/raspberrypi/controller/rpi/alsc.cpp\nindex 524c48093590..3a2e8fe00ca6 100644\n--- a/src/ipa/raspberrypi/controller/rpi/alsc.cpp\n+++ b/src/ipa/raspberrypi/controller/rpi/alsc.cpp\n@@ -607,7 +607,7 @@ static double computeWeight(double Ci, double Cj, double sigma)\n \n /* Compute all weights. */\n static void computeW(const Array2D<double> &C, double sigma,\n-\t\t     std::vector<std::array<double, 4>> &W)\n+\t\t     SparseArray<double> &W)\n {\n \tsize_t XY = C.size();\n \tsize_t X = C.dimensions().width;\n@@ -623,8 +623,8 @@ static void computeW(const Array2D<double> &C, double sigma,\n \n /* Compute M, the large but sparse matrix such that M * lambdas = 0. */\n static void constructM(const Array2D<double> &C,\n-\t\t       const std::vector<std::array<double, 4>> &W,\n-\t\t       std::vector<std::array<double, 4>> &M)\n+\t\t       const SparseArray<double> &W,\n+\t\t       SparseArray<double> &M)\n {\n \tsize_t XY = C.size();\n \tsize_t X = C.dimensions().width;\n@@ -651,37 +651,37 @@ static void constructM(const Array2D<double> &C,\n  * left/right neighbours are zero down the left/right edges, so we don't need\n  * need to test the i value to exclude them.\n  */\n-static double computeLambdaBottom(int i, const std::vector<std::array<double, 4>> &M,\n+static double computeLambdaBottom(int i, const SparseArray<double> &M,\n \t\t\t\t  Array2D<double> &lambda)\n {\n \treturn M[i][1] * lambda[i + 1] + M[i][2] * lambda[i + lambda.dimensions().width] +\n \t       M[i][3] * lambda[i - 1];\n }\n-static double computeLambdaBottomStart(int i, const std::vector<std::array<double, 4>> &M,\n+static double computeLambdaBottomStart(int i, const SparseArray<double> &M,\n \t\t\t\t       Array2D<double> &lambda)\n {\n \treturn M[i][1] * lambda[i + 1] + M[i][2] * lambda[i + lambda.dimensions().width];\n }\n-static double computeLambdaInterior(int i, const std::vector<std::array<double, 4>> &M,\n+static double computeLambdaInterior(int i, const SparseArray<double> &M,\n \t\t\t\t    Array2D<double> &lambda)\n {\n \treturn M[i][0] * lambda[i - lambda.dimensions().width] + M[i][1] * lambda[i + 1] +\n \t       M[i][2] * lambda[i + lambda.dimensions().width] + M[i][3] * lambda[i - 1];\n }\n-static double computeLambdaTop(int i, const std::vector<std::array<double, 4>> &M,\n+static double computeLambdaTop(int i, const SparseArray<double> &M,\n \t\t\t       Array2D<double> &lambda)\n {\n \treturn M[i][0] * lambda[i - lambda.dimensions().width] + M[i][1] * lambda[i + 1] +\n \t       M[i][3] * lambda[i - 1];\n }\n-static double computeLambdaTopEnd(int i, const std::vector<std::array<double, 4>> &M,\n+static double computeLambdaTopEnd(int i, const SparseArray<double> &M,\n \t\t\t\t  Array2D<double> &lambda)\n {\n \treturn M[i][0] * lambda[i - lambda.dimensions().width] + M[i][3] * lambda[i - 1];\n }\n \n /* Gauss-Seidel iteration with over-relaxation. */\n-static double gaussSeidel2Sor(const std::vector<std::array<double, 4>> &M, double omega,\n+static double gaussSeidel2Sor(const SparseArray<double> &M, double omega,\n \t\t\t      Array2D<double> &lambda, double lambdaBound)\n {\n \tint XY = lambda.size();\n@@ -753,8 +753,8 @@ static void reaverage(Array2D<double> &data)\n \n static void runMatrixIterations(const Array2D<double> &C,\n \t\t\t\tArray2D<double> &lambda,\n-\t\t\t\tconst std::vector<std::array<double, 4>> &W,\n-\t\t\t\tstd::vector<std::array<double, 4>> &M, double omega,\n+\t\t\t\tconst SparseArray<double> &W,\n+\t\t\t\tSparseArray<double> &M, double omega,\n \t\t\t\tunsigned int nIter, double threshold, double lambdaBound)\n {\n \tconstructM(C, W, M);\n@@ -813,7 +813,7 @@ void Alsc::doAlsc()\n {\n \tArray2D<double> &cr = tmpC_[0], &cb = tmpC_[1], &calTableR = tmpC_[2],\n \t\t\t&calTableB = tmpC_[3], &calTableTmp = tmpC_[4];\n-\tstd::vector<std::array<double, 4>> &wr = tmpM_[0], &wb = tmpM_[1], &M = tmpM_[2];\n+\tSparseArray<double> &wr = tmpM_[0], &wb = tmpM_[1], &M = tmpM_[2];\n \n \t/*\n \t * Calculate our R/B (\"Cr\"/\"Cb\") colour statistics, and assess which are\ndiff --git a/src/ipa/raspberrypi/controller/rpi/alsc.h b/src/ipa/raspberrypi/controller/rpi/alsc.h\nindex 1ab61299c4cd..0b6d9478073c 100644\n--- a/src/ipa/raspberrypi/controller/rpi/alsc.h\n+++ b/src/ipa/raspberrypi/controller/rpi/alsc.h\n@@ -68,6 +68,14 @@ private:\n \tstd::vector<T> data_;\n };\n \n+/*\n+ * We'll use the term SparseArray for the large sparse matrices that are\n+ * XY tall but have only 4 non-zero elements on each row.\n+ */\n+\n+template<typename T>\n+using SparseArray = std::vector<std::array<T, 4>>;\n+\n struct AlscCalibration {\n \tdouble ct;\n \tArray2D<double> table;\n@@ -160,7 +168,7 @@ private:\n \n \t/* Temporaries for the computations */\n \tstd::array<Array2D<double>, 5> tmpC_;\n-\tstd::array<std::vector<std::array<double, 4>>, 3> tmpM_;\n+\tstd::array<SparseArray<double>, 3> tmpM_;\n };\n \n } /* namespace RPiController */\n","prefixes":["libcamera-devel","v1","05/10"]}