@@ -24,6 +24,9 @@ LOG_DECLARE_CATEGORY(Matrix)
template<typename T>
bool matrixInvert(std::span<const T> dataIn, std::span<T> dataOut, unsigned int dim,
std::span<T> scratchBuffer, std::span<unsigned int> swapBuffer);
+template<typename T>
+void matrixTranspose(std::span<const T> dataIn, std::span<T> dataOut,
+ unsigned int rows, unsigned int cols);
#endif /* __DOXYGEN__ */
template<typename T, unsigned int Rows, unsigned int Cols>
@@ -115,6 +118,15 @@ public:
return inverse;
}
+ Matrix<T, Cols, Rows> transpose() const
+ {
+ Matrix<T, Cols, Rows> transposed;
+ matrixTranspose(std::span<const T>(data_),
+ std::span<T>(transposed.data_),
+ Rows, Cols);
+ return transposed;
+ }
+
private:
/*
* \todo The initializer is only necessary for the constructor to be
@@ -107,6 +107,16 @@ LOG_DEFINE_CATEGORY(Matrix)
* \return The inverse of the matrix
*/
+/**
+ * \fn Matrix::transpose() const
+ * \brief Compute the transpose of the matrix
+ *
+ * This function computes the transpose of the matrix. It is only implemented
+ * for matrices of float and double types.
+ *
+ * \return The transpose of the matrix
+ */
+
/**
* \fn Matrix::operator[](size_t i)
* \copydoc Matrix::operator[](size_t i) const
@@ -309,6 +319,23 @@ template bool matrixInvert<double>(std::span<const double> data, std::span<doubl
unsigned int dim, std::span<double> scratchBuffer,
std::span<unsigned int> swapBuffer);
+template<typename T>
+void matrixTranspose(std::span<const T> dataIn, std::span<T> dataOut,
+ unsigned int rows, unsigned int cols)
+{
+ for (unsigned int row = 0; row < rows; ++row) {
+ for (unsigned int col = 0; col < cols; ++col)
+ dataOut[col * rows + row] = dataIn[row * cols + col];
+ }
+}
+
+template void matrixTranspose(std::span<const float> dataIn,
+ std::span<float> dataOut,
+ unsigned int rows, unsigned int cols);
+template void matrixTranspose(std::span<const double> dataIn,
+ std::span<double> dataOut,
+ unsigned int rows, unsigned int cols);
+
/*
* The value node 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
The Matrix class has a member function to invert a matrix, but no function to transpose it. We already have one open-coded transpose operation in the software ISP implementation, and more would likely be added. Add a transpose() member function to the Matrix class to cover this need. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> --- include/libcamera/internal/matrix.h | 12 ++++++++++++ src/libcamera/matrix.cpp | 27 +++++++++++++++++++++++++++ 2 files changed, 39 insertions(+)