Clarify single index API for data access.

This commit is contained in:
Joel Falcou 2025-09-18 14:31:33 +02:00
parent a50098f761
commit d89da18709
13 changed files with 249 additions and 128 deletions

View file

@ -66,18 +66,43 @@ TTS_CASE_TPL("Test coefficient accessors", rotgen::tests::types)
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";
auto m = [&]()
{
if constexpr(O::value == rotgen::ColMajor)
{
using base = rotgen::matrix<T,1,rotgen::Dynamic>;
rotgen::map<base> a(data,12);
return a;
}
else
{
using base = rotgen::matrix<T,rotgen::Dynamic,1>;
rotgen::map<base> a(data,12);
return a;
}
}();
a(1) = 42;
TTS_EXPECT(m.IsVectorAtCompileTime);
for(rotgen::Index i=0;i<m.size();i++)
TTS_EQUAL(m(i), data[i]) << "Index: " << i << "\n";
for(rotgen::Index i=0;i<m.size();i++)
TTS_EQUAL(m[i], data[i]) << "Index: " << i << "\n";
m(1) = 42;
TTS_EQUAL(data[1], 42);
T& ref = a(2);
T& ref = m(2);
ref = 17;
TTS_EQUAL(data[2], 17);
m[1] = 77;
TTS_EQUAL(data[1], 77);
T& bref = m[3];
bref = 331;
TTS_EQUAL(data[3], 331);
};