//================================================================================================== /* ROTGEN - Runtime Overlay for Eigen Copyright : CODE RECKONS SPDX-License-Identifier: BSL-1.0 */ //================================================================================================== #include "unit/tests.hpp" #include // Helper: fill matrix from raw data // NB: This function must not be turned into a lambda, otherwise // `test-ubuntu-gcc-release` will not pass and the CI will fail. // This is likely due to a compilation bug from GCC 13.3.0. void fill(auto &m, int r, int c, auto data[]) { for (int k = 0; k < r * c; ++k) m.data()[k] = data[k]; } TTS_CASE_TPL("Function size", rotgen::tests::types) (tts::type>) { T data[] = {1,2,3,4,5,6,7,8,9,10,11,12}; // 1x12 dynamic block at (0,0) rotgen::matrix dm(1,12); fill(dm,1,12,data); auto b1 = rotgen::block(dm, 0,0,1,12); TTS_EQUAL(b1.rows(), rotgen::Index{1}); TTS_EQUAL(b1.cols(), rotgen::Index{12}); // 1x5 dynamic block at (0,2) auto b2 = rotgen::block(dm, 0,2,1,5); TTS_EQUAL(b2.rows(), rotgen::Index{1}); TTS_EQUAL(b2.cols(), rotgen::Index{5}); // 3x2 dynamic block at (1,4) in 4x6 rotgen::matrix dm2(4,6); fill(dm2,4,6,data); auto b3 = rotgen::block(dm2, 1,4,3,2); TTS_EQUAL(b3.rows(), rotgen::Index{3}); TTS_EQUAL(b3.cols(), rotgen::Index{2}); TTS_EQUAL(b3.size(), rotgen::Index{6}); // 3x4 static block rotgen::matrix sm; fill(sm,3,4,data); auto b4 = rotgen::block(sm, 0,0); TTS_EQUAL(b4.rows(), rotgen::Index{3}); TTS_EQUAL(b4.cols(), rotgen::Index{4}); TTS_EQUAL(b4.size(), rotgen::Index{12}); // 6x2 static block rotgen::matrix sm2; fill(sm2,6,2,data); auto b5 = rotgen::block(sm2, 0,0); TTS_EQUAL(b5.rows(), rotgen::Index{6}); TTS_EQUAL(b5.cols(), rotgen::Index{2}); TTS_EQUAL(b5.size(), rotgen::Index{12}); }; TTS_CASE_TPL("Test coefficient accessors", rotgen::tests::types) ( tts::type< tts::types> ) { using base = rotgen::matrix; T data[] = {1,2,3,4,5,6,7,8,9,10,11,12}; base mat(4,3); for(int k=0;k<12;++k) mat.data()[k] = data[k]; auto b = rotgen::block(mat, 0, 0, 4, 3); for(rotgen::Index i=0;i<4;i++) { for(rotgen::Index j=0;j<3;j++) { if constexpr(O::value) TTS_EQUAL(b(i,j), data[j+3*i]); else TTS_EQUAL(b(i,j), data[i+4*j]); } } b(1, 1) = 42; TTS_EQUAL(b(1,1), 42); T& ref = b(2, 2); ref = 17; TTS_EQUAL(b(2, 2), 17); }; TTS_CASE_TPL("Test one index coefficient accessors", rotgen::tests::types) ( tts::type< tts::types> ) { auto vs = [&]() { if constexpr(O::value == rotgen::ColMajor) { using base = rotgen::matrix; base m(12); for(int k=0;k<12;++k) m(k) = k+1; return std::tuple{m,rotgen::block(m, 0, 0, 1, 12)}; } else { using base = rotgen::matrix; base m(12); for(int k=0;k<12;++k) m(k) = k+1; return std::tuple{m,rotgen::block(m, 0, 0, 12, 1)}; } }(); auto mat = get<0>(vs); auto b = get<1>(vs); TTS_EXPECT(b.IsVectorAtCompileTime); for(rotgen::Index i=0;i