//================================================================================================== /* ROTGEN - Runtime Overlay for Eigen Copyright : CODE RECKONS SPDX-License-Identifier: BSL-1.0 */ //================================================================================================== #define TTS_MAIN #include #include "tts.hpp" template struct MatrixDescriptor { std::size_t rows, cols; std::function init_fn; }; template void test_matrix_unary_ops(std::size_t rows, std::size_t cols, const std::function &init_fn) { MatrixType original(rows, cols); MatrixType transposed_matrix(cols, rows); for (std::size_t r = 0; r < rows; ++r) for (std::size_t c = 0; c < cols; ++c) init_fn(original, r, c); for (std::size_t r = 0; r < rows; ++r) for (std::size_t c = 0; c < cols; ++c) transposed_matrix(c, r) = original(r, c); TTS_EQUAL(original.transpose(), transposed_matrix); TTS_EQUAL(original.conjugate(), original); TTS_EQUAL(original.adjoint(), transposed_matrix); original.transposeInPlace(); TTS_EQUAL(original, transposed_matrix); original.transposeInPlace(); original.adjointInPlace(); TTS_EQUAL(original, transposed_matrix); } TTS_CASE("Matrix unary operations: transpose, adjoint, conjugate") { std::vector>> test_matrices = { {3, 3, [](auto& m, std::size_t r, std::size_t c) { m(r, c) = r + 3 * c - 2.5; }}, {4, 9, [](auto& m, std::size_t r, std::size_t c) { m(r, c) = r*r + 3.12 * c + 6.87; }}, {2, 7, [](auto& m, std::size_t r, std::size_t c) { m(r, c) = 1.1 * (r - c); }}, {1, 5, [](auto &m, std::size_t r, std::size_t c) { m(r, c) = 9.99; }}, {4, 2, [](auto& m, std::size_t r, std::size_t c) { m(r, c) = 0.0; }}, {3, 3, [](auto& m, std::size_t r, std::size_t c) { m(r, c) = (r == c) ? 1.0 : 0.0; }}, {2, 2, [](auto& m, std::size_t r, std::size_t c) { m(r, c) = (r + c) * 1e-10; }}, {2, 2, [](auto& m, std::size_t r, std::size_t c) { m(r, c) = (r + 1) * 1e+10; }}, }; for (auto const &desc : test_matrices) test_matrix_unary_ops>(desc.rows, desc.cols, desc.init_fn); };