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
83
test/unit/map/basic_api.cpp
Normal file
83
test/unit/map/basic_api.cpp
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
//==================================================================================================
|
||||
/*
|
||||
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};
|
||||
|
||||
rotgen::map<rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value>> dyn_map(data,1,12);
|
||||
TTS_EQUAL(dyn_map.rows(), rotgen::Index{1});
|
||||
TTS_EQUAL(dyn_map.cols(), rotgen::Index{12});
|
||||
|
||||
rotgen::map<rotgen::matrix<T,1,12,rotgen::RowMajor>> s112_map(data);
|
||||
TTS_EQUAL(s112_map.rows(), rotgen::Index{1});
|
||||
TTS_EQUAL(s112_map.cols(), rotgen::Index{12});
|
||||
TTS_EQUAL(s112_map.size(), rotgen::Index{12});
|
||||
|
||||
rotgen::map<rotgen::matrix<T,12,1,rotgen::ColMajor>> s121_map(data);
|
||||
TTS_EQUAL(s121_map.rows(), rotgen::Index{12});
|
||||
TTS_EQUAL(s121_map.cols(), rotgen::Index{1});
|
||||
TTS_EQUAL(s121_map.size(), rotgen::Index{12});
|
||||
|
||||
rotgen::map<rotgen::matrix<T,3,4,O::value>> s34_map(data);
|
||||
TTS_EQUAL(s34_map.rows(), rotgen::Index{3});
|
||||
TTS_EQUAL(s34_map.cols(), rotgen::Index{4});
|
||||
TTS_EQUAL(s34_map.size(), rotgen::Index{12});
|
||||
|
||||
rotgen::map<rotgen::matrix<T,6,2,O::value>> s62_map(data);
|
||||
TTS_EQUAL(s62_map.rows(), rotgen::Index{6});
|
||||
TTS_EQUAL(s62_map.cols(), rotgen::Index{2});
|
||||
TTS_EQUAL(s62_map.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};
|
||||
|
||||
rotgen::map<base> a(data,4,3);
|
||||
for(rotgen::Index i=0;i<4;i++)
|
||||
{
|
||||
for(rotgen::Index j=0;j<3;j++)
|
||||
{
|
||||
if constexpr(O::value) TTS_EQUAL(a(i,j), data[j+3*i]);
|
||||
else TTS_EQUAL(a(i,j), data[i+4*j]);
|
||||
}
|
||||
}
|
||||
|
||||
a(1, 1) = 42;
|
||||
TTS_EQUAL(a(1,1), 42);
|
||||
|
||||
T& ref = a(2, 2);
|
||||
ref = 17;
|
||||
TTS_EQUAL(a(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};
|
||||
|
||||
rotgen::map<base> a(data,4,3);
|
||||
for(rotgen::Index i=0;i<a.size();i++)
|
||||
TTS_EQUAL(a(i), data[i]) << "Index: " << i << "\n";
|
||||
|
||||
a(1) = 42;
|
||||
TTS_EQUAL(data[1], 42);
|
||||
|
||||
T& ref = a(2);
|
||||
ref = 17;
|
||||
TTS_EQUAL(data[2], 17);
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue