[{"id":26723,"web_url":"https://patchwork.libcamera.org/comment/26723/","msgid":"<20230324085520.fqlz27i6v4q6mq3i@uno.localdomain>","date":"2023-03-24T08:55:20","subject":"Re: [libcamera-devel] [PATCH v1 05/10] ipa: raspberrypi: alsc: Use\n\ta better type name for sparse arrays","submitter":{"id":143,"url":"https://patchwork.libcamera.org/api/people/143/","name":"Jacopo Mondi","email":"jacopo.mondi@ideasonboard.com"},"content":"Hi David\n\nOn Wed, Mar 22, 2023 at 01:06:07PM +0000, Naushir Patuck via libcamera-devel wrote:\n> From: David Plowman <david.plowman@raspberrypi.com>\n>\n> The algorithm uses the data type std::vector<std::array<double, 4>> to\n> represent the large sparse matrices that are XY (X, Y being the ALSC\n> grid size) high but with only 4 non-zero elements on each row.\n>\n> Replace this slightly long type name by SparseArray<double>.\n\nNicer to read indeed\nReviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n\nThanks\n  j\n\n>\n> No functional changes.\n>\n> Signed-off-by: David Plowman <david.plowman@raspberrypi.com>\n> Reviewed-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(-)\n>\n> diff --git a/src/ipa/raspberrypi/controller/rpi/alsc.cpp b/src/ipa/raspberrypi/controller/rpi/alsc.cpp\n> index 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\n> diff --git a/src/ipa/raspberrypi/controller/rpi/alsc.h b/src/ipa/raspberrypi/controller/rpi/alsc.h\n> index 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> --\n> 2.34.1\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 B8BBBC0F2A\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 24 Mar 2023 08:55:25 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 1F4D5626E3;\n\tFri, 24 Mar 2023 09:55:25 +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 9999D61ED0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 24 Mar 2023 09:55:23 +0100 (CET)","from ideasonboard.com (93-61-96-190.ip145.fastwebnet.it\n\t[93.61.96.190])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 0454BA49;\n\tFri, 24 Mar 2023 09:55:22 +0100 (CET)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1679648125;\n\tbh=GNGrMS1yvU3wZsmIENQWZl+U3QJg9ZtUWGcKljArxa4=;\n\th=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=Q3HwT4WD8yxBH+R9woKMO/2TTnILF5fcfTOSEnC7RcILr8TqSS+hYNu8N93gYbpEW\n\txCWD3gBt0IAswgcqt/cynaCcNqKPYQOGcmVTFl1xc0gpBjb0fWRqLddrU1vt2PXtOC\n\tnxoGYAuRJVBprZ42UjEdCKAZKF9AwvYZ2c8RWJHW1aiFjs027RteOrtWxxzb+EuqZP\n\tP9VXhvKrNQjvmK5LDInm+SXRE5vCAlNTkrbJwhSLtpZgk7umb7OxdYBFUnyg6TTTvB\n\tvMl0/uUoLrYV2U4LXvQEHXisdMsU84FR/tmBN/iboe6YR46/TylhxOtsuEue7ksuEp\n\tPMcg7ip1KvmmQ==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1679648123;\n\tbh=GNGrMS1yvU3wZsmIENQWZl+U3QJg9ZtUWGcKljArxa4=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=H5QMKnZ7a4ZSXr9l4NFr7YGjEY+RSFjcWZuDy538jS38sQqUjHHXvKwcEhBXEC+7d\n\tTycVErZQku/i5O8olJmGG2jhlr5oGjFbatBlspgeiMeoaBl7wi7wvvenVMM3wx7mUt\n\tQj0kF1aX+O663uDK61MRcWwPrOC1lFdZH6OuH3i8="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"H5QMKnZ7\"; dkim-atps=neutral","Date":"Fri, 24 Mar 2023 09:55:20 +0100","To":"Naushir Patuck <naush@raspberrypi.com>","Message-ID":"<20230324085520.fqlz27i6v4q6mq3i@uno.localdomain>","References":"<20230322130612.5208-1-naush@raspberrypi.com>\n\t<20230322130612.5208-6-naush@raspberrypi.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20230322130612.5208-6-naush@raspberrypi.com>","Subject":"Re: [libcamera-devel] [PATCH v1 05/10] ipa: raspberrypi: alsc: Use\n\ta better 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":"Jacopo Mondi via libcamera-devel <libcamera-devel@lists.libcamera.org>","Reply-To":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]