{"id":18474,"url":"https://patchwork.libcamera.org/api/patches/18474/?format=json","web_url":"https://patchwork.libcamera.org/patch/18474/","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":"<20230327122030.11756-6-naush@raspberrypi.com>","date":"2023-03-27T12:20:25","name":"[libcamera-devel,v2,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/18474/mbox/","series":[{"id":3819,"url":"https://patchwork.libcamera.org/api/series/3819/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=3819","date":"2023-03-27T12:20:20","name":"Raspberry Pi: Generalised algorithms","version":2,"mbox":"https://patchwork.libcamera.org/series/3819/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/18474/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/18474/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 EE1FDC326C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 27 Mar 2023 12:20:51 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id A116562767;\n\tMon, 27 Mar 2023 14:20:51 +0200 (CEST)","from mail-il1-x12a.google.com (mail-il1-x12a.google.com\n\t[IPv6:2607:f8b0:4864:20::12a])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 3E81962747\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 27 Mar 2023 14:20:47 +0200 (CEST)","by mail-il1-x12a.google.com with SMTP id h11so4512717ild.11\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 27 Mar 2023 05:20:47 -0700 (PDT)","from localhost.localdomain ([93.93.133.154])\n\tby smtp.gmail.com with ESMTPSA id\n\tr7-20020a5edb47000000b00758ff97aaedsm3239026iop.16.2023.03.27.05.20.44\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tMon, 27 Mar 2023 05:20:45 -0700 (PDT)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1679919651;\n\tbh=klPCji71t9ff50/NTw25Wr7qoGXqjM2oZwi1ptHCVKI=;\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:Cc:\n\tFrom;\n\tb=mtCRhjttbE6t4Hriduc8rqn+NZLzL9l4LIVPnQqqCJY2MpkyfIoh7DVmB0kqKd2Oz\n\tUA0pJK4O9wI8d8/lfVvSGXmxN8ccqQAin4eygsxkzhzzvvCULrApnNIcrQLm+niX/b\n\tQAcPPXzQ3I73C9qMorWFnJZntc86gSF5Eu+BWFNl67h1aRZd/dr43jl7gqbtbUk4Ex\n\tkO5H2ZUc/r5bJP1qnWXnZ8ovqypVs1QTV393dxUcGL+4xZMSst7iUQMIgttLaDgrAa\n\tmDfmV4IrIbUZHci+S0Ttk7NPpiYEc//LUHH4t5uPR2k9C1RsKZP+puVgjeefoys1j0\n\tqIWmEnGKzACAA==","v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google; t=1679919646;\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=548zcSLJYSR6puTSQTcbbtm0W6Y5GofHbCgq+Ac6wj0=;\n\tb=cuCWr7qbrh2dk9ysm9/4Yi+HViFsEDnCNDAuJvvnohN6QwdQaOeSnHUq7yVs6oK83m\n\t3CMCYufg5ipouPZIpEMn2JjLRBjOimaI9ckytp1muPK9Obm+d8umozH2SgJNSFLYx++q\n\tpJn/815uxj016I7wDjLxqNh574tz0wcXnjqvjp8I5OL4QKTaMQhozuUmQuV2jpSmRLo6\n\tWUjTkDuMk7sjvYPUKQGZ3MkajOECj0EY/eLhIn+twgE7Do0NA0lfhKRG3MiL+d+2nEdB\n\tYyJf59reUh70lIstYluOdgfrTINa0UoVLaR4zPlX/2DzOfz8mfBPi8mlIULaBKvCaty8\n\tRJ+A=="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected) header.d=raspberrypi.com\n\theader.i=@raspberrypi.com\n\theader.b=\"cuCWr7qb\"; dkim-atps=neutral","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112; t=1679919646;\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=548zcSLJYSR6puTSQTcbbtm0W6Y5GofHbCgq+Ac6wj0=;\n\tb=2qN0OV5vJe+IiNOrSlmZj9t2kHI34hjA6p8iyDyrAzIB6r98dcPBMJ1Q+44udLY3Gu\n\tkLWf/uBXcfKol7LZlOiDxbngXv9f0BTHRCZjkHeHN28f8l9hWefnpbf8rRuCr2xVxcxD\n\tGk9uuWBgk5K4hXQ7JHWon9zi4hm5+AxnQ/uU9twCpSEur9wciLa24PsEKSJepg4EtEML\n\tvLSDd+XXg1o5yLJc7PF0+mIbckQD9Qjn7lcpo+0gUOXwgMhfIcxhHkyiRPocvqCBgpDF\n\tng6khmDg8/GnR3XGxp5kkFS7h3WpxmkCg1pXo5ui50EZj1t8+Ai589kHhBR6W0TKkXT5\n\tpwZQ==","X-Gm-Message-State":"AAQBX9d+GtSjUBQrt+Ks9E/pdqWgAzzDHoJPOkCkcX+dJ/evBA3j8tZa\n\ttsohcdFZLAPw60OkyZE+KKZyp4RYoc6+JORJRDmQ0Q==","X-Google-Smtp-Source":"AKy350YkYUUcK7HiNDPSGBkShSBbq4CzNDLwmgCdHU3wK+UFUQTeGh5hxYCObXxE7HVXI8lapTqB8g==","X-Received":"by 2002:a92:512:0:b0:316:b0bb:3d99 with SMTP id\n\tq18-20020a920512000000b00316b0bb3d99mr7950014ile.22.1679919645815; \n\tMon, 27 Mar 2023 05:20:45 -0700 (PDT)","To":"libcamera-devel@lists.libcamera.org","Date":"Mon, 27 Mar 2023 13:20:25 +0100","Message-Id":"<20230327122030.11756-6-naush@raspberrypi.com>","X-Mailer":"git-send-email 2.34.1","In-Reply-To":"<20230327122030.11756-1-naush@raspberrypi.com>","References":"<20230327122030.11756-1-naush@raspberrypi.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v2 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>","Cc":"Jacopo Mondi <jacopo.mondi@ideasonboard.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>\nReviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.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","v2","05/10"]}