From patchwork Tue Nov 19 10:37:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Klug X-Patchwork-Id: 21997 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id A8509C326B for ; Tue, 19 Nov 2024 10:38:15 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 512E565F12; Tue, 19 Nov 2024 11:38:15 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="oXnnjtIG"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 63F1165EFF for ; Tue, 19 Nov 2024 11:38:11 +0100 (CET) Received: from ideasonboard.com (unknown [IPv6:2a00:6020:448c:6c00:bf40:cdab:103d:2270]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 1FB8C641; Tue, 19 Nov 2024 11:37:54 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1732012674; bh=mo0kYvDy4aCnLczfuCSMiHcKR8tGKXb4yjQpxWuh6+0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oXnnjtIGgp25X/RuyNlmpWDdUPNe0Yt3Izakx8oes+/qdYXWKJN1GFWS9jLaPY6e5 TC6hehPzR8ZZ3wRDJy86KIy9UjIcfOOv3PGlGSfc4f2hLnTdrf+nhkVWJdbvIlX5F7 VaHf94mzxOBLT8mLdeeoQbANOK/v5hbkvecRHBq8= From: Stefan Klug To: libcamera-devel@lists.libcamera.org Cc: Stefan Klug Subject: [PATCH v2 9/9] libipa: Drop Matrix class Date: Tue, 19 Nov 2024 11:37:36 +0100 Message-ID: <20241119103740.1919807-10-stefan.klug@ideasonboard.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241119103740.1919807-1-stefan.klug@ideasonboard.com> References: <20241119103740.1919807-1-stefan.klug@ideasonboard.com> MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" There are no users of the libipa::Matrix class anymore. Drop it. Signed-off-by: Stefan Klug Reviewed-by: Laurent Pinchart --- src/ipa/libipa/matrix.cpp | 149 --------------------------- src/ipa/libipa/matrix.h | 203 ------------------------------------- src/ipa/libipa/meson.build | 2 - 3 files changed, 354 deletions(-) delete mode 100644 src/ipa/libipa/matrix.cpp delete mode 100644 src/ipa/libipa/matrix.h diff --git a/src/ipa/libipa/matrix.cpp b/src/ipa/libipa/matrix.cpp deleted file mode 100644 index 8346f0d34160..000000000000 --- a/src/ipa/libipa/matrix.cpp +++ /dev/null @@ -1,149 +0,0 @@ -/* SPDX-License-Identifier: LGPL-2.1-or-later */ -/* - * Copyright (C) 2024, Paul Elder - * - * Matrix and related operations - */ - -#include "matrix.h" - -#include - -/** - * \file matrix.h - * \brief Matrix class - */ - -namespace libcamera { - -LOG_DEFINE_CATEGORY(Matrix) - -namespace ipa { - -/** - * \class Matrix - * \brief Matrix class - * \tparam T Type of numerical values to be stored in the matrix - * \tparam Rows Number of rows in the matrix - * \tparam Cols Number of columns in the matrix - */ - -/** - * \fn Matrix::Matrix() - * \brief Construct a zero matrix - */ - -/** - * \fn Matrix::Matrix(const std::vector &data) - * \brief Construct a matrix from supplied data - * \param[in] data Data from which to construct a matrix - * - * \a data is a one-dimensional vector and will be turned into a matrix in - * row-major order. The size of \a data must be equal to the product of the - * number of rows and columns of the matrix (Rows x Cols). - */ - -/** - * \fn Matrix::identity() - * \brief Construct an identity matrix - */ - -/** - * \fn Matrix::toString() - * \brief Assemble and return a string describing the matrix - * \return A string describing the matrix - */ - -/** - * \fn Span Matrix::operator[](size_t i) const - * \brief Index to a row in the matrix - * \param[in] i Index of row to retrieve - * - * This operator[] returns a Span, which can then be indexed into again with - * another operator[], allowing a convenient m[i][j] to access elements of the - * matrix. Note that the lifetime of the Span returned by this first-level - * operator[] is bound to that of the Matrix itself, so it is not recommended - * to save the Span that is the result of this operator[]. - * - * \return Row \a i from the matrix, as a Span - */ - -/** - * \fn Matrix::operator[](size_t i) - * \copydoc Matrix::operator[](size_t i) const - */ - -/** - * \fn Matrix &Matrix::operator*=(U d) - * \brief Multiply the matrix by a scalar in-place - * \tparam U Type of the numerical scalar value - * \param d The scalar multiplier - * \return Product of this matrix and scalar \a d - */ - -/** - * \fn Matrix::Matrix operator*(T d, const Matrix &m) - * \brief Multiply the matrix by a scalar - * \tparam T Type of the numerical scalar value - * \tparam U Type of numerical values in the matrix - * \tparam Rows Number of rows in the matrix - * \tparam Cols Number of columns in the matrix - * \param d The scalar multiplier - * \param m The matrix - * \return Product of scalar \a d and matrix \a m - */ - -/** - * \fn Matrix::Matrix operator*(const Matrix &m, T d) - * \copydoc operator*(T d, const Matrix &m) - */ - -/** - * \fn Matrix operator*(const Matrix &m1, const Matrix &m2) - * \brief Matrix multiplication - * \tparam T Type of numerical values in the matrices - * \tparam R1 Number of rows in the first matrix - * \tparam C1 Number of columns in the first matrix - * \tparam R2 Number of rows in the second matrix - * \tparam C2 Number of columns in the second matrix - * \param m1 Multiplicand matrix - * \param m2 Multiplier matrix - * \return Matrix product of matrices \a m1 and \a m2 - */ - -/** - * \fn Matrix operator+(const Matrix &m1, const Matrix &m2) - * \brief Matrix addition - * \tparam T Type of numerical values in the matrices - * \tparam Rows Number of rows in the matrices - * \tparam Cols Number of columns in the matrices - * \param m1 Summand matrix - * \param m2 Summand matrix - * \return Matrix sum of matrices \a m1 and \a m2 - */ - -#ifndef __DOXYGEN__ -/* - * The YAML data shall be a list of numerical values. Its size shall be equal - * to the product of the number of rows and columns of the matrix (Rows x - * Cols). The values shall be stored in row-major order. - */ -bool matrixValidateYaml(const YamlObject &obj, unsigned int size) -{ - if (!obj.isList()) - return false; - - if (obj.size() != size) { - LOG(Matrix, Error) - << "Wrong number of values in matrix: expected " - << size << ", got " << obj.size(); - return false; - } - - return true; -} -#endif /* __DOXYGEN__ */ - -} /* namespace ipa */ - -} /* namespace libcamera */ diff --git a/src/ipa/libipa/matrix.h b/src/ipa/libipa/matrix.h deleted file mode 100644 index 5471e6975b74..000000000000 --- a/src/ipa/libipa/matrix.h +++ /dev/null @@ -1,203 +0,0 @@ -/* SPDX-License-Identifier: LGPL-2.1-or-later */ -/* - * Copyright (C) 2024, Paul Elder - * - * Matrix and related operations - */ -#pragma once - -#include -#include -#include - -#include -#include - -#include "libcamera/internal/yaml_parser.h" - -namespace libcamera { - -LOG_DECLARE_CATEGORY(Matrix) - -namespace ipa { - -#ifndef __DOXYGEN__ -template> * = nullptr> -#else -template -#endif /* __DOXYGEN__ */ -class Matrix -{ -public: - Matrix() - { - data_.fill(static_cast(0)); - } - - Matrix(const std::vector &data) - { - std::copy(data.begin(), data.end(), data_.begin()); - } - - static Matrix identity() - { - Matrix ret; - for (size_t i = 0; i < std::min(Rows, Cols); i++) - ret[i][i] = static_cast(1); - return ret; - } - - ~Matrix() = default; - - const std::string toString() const - { - std::stringstream out; - - out << "Matrix { "; - for (unsigned int i = 0; i < Rows; i++) { - out << "[ "; - for (unsigned int j = 0; j < Cols; j++) { - out << (*this)[i][j]; - out << ((j + 1 < Cols) ? ", " : " "); - } - out << ((i + 1 < Rows) ? "], " : "]"); - } - out << " }"; - - return out.str(); - } - - Span operator[](size_t i) const - { - return Span{ &data_.data()[i * Cols], Cols }; - } - - Span operator[](size_t i) - { - return Span{ &data_.data()[i * Cols], Cols }; - } - -#ifndef __DOXYGEN__ - template>> -#else - template -#endif /* __DOXYGEN__ */ - Matrix &operator*=(U d) - { - for (unsigned int i = 0; i < Rows * Cols; i++) - data_[i] *= d; - return *this; - } - -private: - std::array data_; -}; - -#ifndef __DOXYGEN__ -template> * = nullptr> -#else -template -#endif /* __DOXYGEN__ */ -Matrix operator*(T d, const Matrix &m) -{ - Matrix result; - - for (unsigned int i = 0; i < Rows; i++) { - for (unsigned int j = 0; j < Cols; j++) - result[i][j] = d * m[i][j]; - } - - return result; -} - -#ifndef __DOXYGEN__ -template> * = nullptr> -#else -template -#endif /* __DOXYGEN__ */ -Matrix operator*(const Matrix &m, T d) -{ - return d * m; -} - -#ifndef __DOXYGEN__ -template * = nullptr> -#else -template -#endif /* __DOXYGEN__ */ -Matrix operator*(const Matrix &m1, const Matrix &m2) -{ - Matrix result; - - for (unsigned int i = 0; i < R1; i++) { - for (unsigned int j = 0; j < C2; j++) { - T sum = 0; - - for (unsigned int k = 0; k < C1; k++) - sum += m1[i][k] * m2[k][j]; - - result[i][j] = sum; - } - } - - return result; -} - -template -Matrix operator+(const Matrix &m1, const Matrix &m2) -{ - Matrix result; - - for (unsigned int i = 0; i < Rows; i++) { - for (unsigned int j = 0; j < Cols; j++) - result[i][j] = m1[i][j] + m2[i][j]; - } - - return result; -} - -#ifndef __DOXYGEN__ -bool matrixValidateYaml(const YamlObject &obj, unsigned int size); -#endif /* __DOXYGEN__ */ - -} /* namespace ipa */ - -#ifndef __DOXYGEN__ -template -std::ostream &operator<<(std::ostream &out, const ipa::Matrix &m) -{ - out << m.toString(); - return out; -} - -template -struct YamlObject::Getter> { - std::optional> get(const YamlObject &obj) const - { - if (!ipa::matrixValidateYaml(obj, Rows * Cols)) - return std::nullopt; - - ipa::Matrix matrix; - T *data = &matrix[0][0]; - - unsigned int i = 0; - for (const YamlObject &entry : obj.asList()) { - const auto value = entry.get(); - if (!value) - return std::nullopt; - - data[i++] = *value; - } - - return matrix; - } -}; -#endif /* __DOXYGEN__ */ - -} /* namespace libcamera */ diff --git a/src/ipa/libipa/meson.build b/src/ipa/libipa/meson.build index e78cbcd63633..84cf0c9a00d8 100644 --- a/src/ipa/libipa/meson.build +++ b/src/ipa/libipa/meson.build @@ -9,7 +9,6 @@ libipa_headers = files([ 'histogram.h', 'interpolator.h', 'lsc_polynomial.h', - 'matrix.h', 'module.h', 'pwl.h', 'vector.h', @@ -24,7 +23,6 @@ libipa_sources = files([ 'histogram.cpp', 'interpolator.cpp', 'lsc_polynomial.cpp', - 'matrix.cpp', 'module.cpp', 'pwl.cpp', 'vector.cpp',