//================================================================================================== /* ROTGEN - Runtime Overlay for Eigen Copyright : CODE RECKONS SPDX-License-Identifier: BSL-1.0 */ //================================================================================================== #include "unit/tests.hpp" #include #include TTS_CASE_TPL("Matrix norm-related operations", rotgen::tests::types) ( tts::type< tts::types> ) { std::vector test_matrices = { { 3, 3, [](int r, int c) { return r + c; }}, { 2, 3, [](int , int ) { return T{0}; }}, { 2, 7, [](int r, int c) { return -r*r*r - c*c - T(1.23); }}, {17, 3, [](int r, int c) { return r*c + T(0.98); }}, { 1, 1, [](int , int ) { return 42; }}, {10, 11, [](int r, int c) { return std::tan(T(r + c)); }}, { 1, 5, [](int r, int c) { return T(-1.5)*r + T(2.56)*c + T(3.33); }}, { 7, 1, [](int r, int c) { return r == c ? T(1) : T(0); }}, { 0, 0, [](int r, int c) { return r == c ? T(1) : T(0); }}, }; for (const auto& [rows, cols, fn] : test_matrices) { rotgen::matrix matrix(rows, cols); Eigen::Matrix ref(rows, cols); for (rotgen::Index r = 0; r < rows; ++r) { for (rotgen::Index c = 0; c < cols; ++c) { ref(r, c) = matrix(r, c) = fn(r,c); } } TTS_EQUAL(matrix.norm(), ref.norm()); TTS_EQUAL(matrix.squaredNorm(), ref.squaredNorm()); TTS_EQUAL(matrix.template lpNorm<1>() , ref.template lpNorm<1>()); TTS_EQUAL(matrix.template lpNorm<2>() , ref.template lpNorm<2>()); TTS_EQUAL(matrix.template lpNorm(), ref.template lpNorm()); } };