Implements map and ref for both static & dynamic mode
See merge request oss/rotgen!12
This commit is contained in:
parent
aacae1cbb1
commit
6c2b260229
58 changed files with 4121 additions and 1205 deletions
104
test/unit/block/basic_api.cpp
Normal file
104
test/unit/block/basic_api.cpp
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
//==================================================================================================
|
||||
/*
|
||||
ROTGEN - Runtime Overlay for Eigen
|
||||
Copyright : CODE RECKONS
|
||||
SPDX-License-Identifier: BSL-1.0
|
||||
*/
|
||||
//==================================================================================================
|
||||
#include "unit/tests.hpp"
|
||||
#include <rotgen/rotgen.hpp>
|
||||
|
||||
TTS_CASE_TPL("Function size", rotgen::tests::types)
|
||||
<typename T, typename O>(tts::type<tts::types<T, O>>)
|
||||
{
|
||||
T data[] = {1,2,3,4,5,6,7,8,9,10,11,12};
|
||||
|
||||
// Helper: fill matrix from raw data
|
||||
auto fill = [&](auto& m, int r, int c) {
|
||||
for(int k = 0; k < r * c; ++k) m.data()[k] = data[k];
|
||||
};
|
||||
|
||||
// 1x12 dynamic block at (0,0)
|
||||
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> dm(1,12);
|
||||
fill(dm,1,12);
|
||||
auto b1 = rotgen::block<decltype(dm), rotgen::Dynamic, rotgen::Dynamic, false, O::value>(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<decltype(dm), rotgen::Dynamic, rotgen::Dynamic, false, O::value>(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<T, rotgen::Dynamic, rotgen::Dynamic, O::value> dm2(4,6);
|
||||
fill(dm2,4,6);
|
||||
auto b3 = rotgen::block<decltype(dm2), rotgen::Dynamic, rotgen::Dynamic, false, O::value>(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<T,3,4,O::value> sm;
|
||||
fill(sm,3,4);
|
||||
auto b4 = rotgen::block<decltype(sm), 3, 4, false, O::value>(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<T,6,2,O::value> sm2;
|
||||
fill(sm2,6,2);
|
||||
auto b5 = rotgen::block<decltype(sm2), 6, 2, false, O::value>(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)
|
||||
<typename T, typename O>( tts::type< tts::types<T,O>> )
|
||||
{
|
||||
using base = rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value>;
|
||||
|
||||
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<base,rotgen::Dynamic,rotgen::Dynamic,false,O::value>(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)
|
||||
<typename T, typename O>( tts::type< tts::types<T,O>> )
|
||||
{
|
||||
using base = rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value>;
|
||||
|
||||
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<base,rotgen::Dynamic,rotgen::Dynamic,false,O::value>(mat, 0, 0, 4, 3);
|
||||
for(rotgen::Index i=0;i<b.size();i++)
|
||||
TTS_EQUAL(b(i), data[i]) << "Index: " << i << "\n";
|
||||
|
||||
b(1) = 42;
|
||||
TTS_EQUAL(mat.data()[1], 42);
|
||||
|
||||
T& ref = b(2);
|
||||
ref = 17;
|
||||
TTS_EQUAL(mat.data()[2], 17);
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue