Clarify single index API for data access.
This commit is contained in:
parent
a50098f761
commit
d89da18709
13 changed files with 249 additions and 128 deletions
|
|
@ -85,20 +85,45 @@ 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>;
|
||||
auto vs = [&]()
|
||||
{
|
||||
if constexpr(O::value == rotgen::ColMajor)
|
||||
{
|
||||
using base = rotgen::matrix<T,1,rotgen::Dynamic>;
|
||||
base m(12);
|
||||
for(int k=0;k<12;++k) m(k) = k+1;
|
||||
return std::tuple{m,rotgen::block<base,1,rotgen::Dynamic>(m, 0, 0, 1, 12)};
|
||||
}
|
||||
else
|
||||
{
|
||||
using base = rotgen::matrix<T,rotgen::Dynamic,1>;
|
||||
base m(12);
|
||||
for(int k=0;k<12;++k) m(k) = k+1;
|
||||
return std::tuple{m,rotgen::block<base,rotgen::Dynamic,1>(m, 0, 0, 12, 1)};
|
||||
}
|
||||
}();
|
||||
|
||||
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 mat = get<0>(vs);
|
||||
auto b = get<1>(vs);
|
||||
TTS_EXPECT(b.IsVectorAtCompileTime);
|
||||
|
||||
auto b = rotgen::block<base,rotgen::Dynamic,rotgen::Dynamic>(mat, 0, 0, 4, 3);
|
||||
for(rotgen::Index i=0;i<b.size();i++)
|
||||
TTS_EQUAL(b(i), data[i]) << "Index: " << i << "\n";
|
||||
TTS_EQUAL(b(i), mat(i)) << "Index: " << i << "\n";
|
||||
|
||||
for(rotgen::Index i=0;i<b.size();i++)
|
||||
TTS_EQUAL(b[i], mat(i)) << "Index: " << i << "\n";
|
||||
|
||||
b(1) = 42;
|
||||
TTS_EQUAL(mat.data()[1], 42);
|
||||
TTS_EQUAL(mat(1), 42);
|
||||
|
||||
T& ref = b(2);
|
||||
ref = 17;
|
||||
TTS_EQUAL(mat.data()[2], 17);
|
||||
TTS_EQUAL(mat(2), 17);
|
||||
|
||||
b[1] = 77;
|
||||
TTS_EQUAL(mat(1), 77);
|
||||
|
||||
T& bref = b[3];
|
||||
bref = 331;
|
||||
TTS_EQUAL(mat(3), 331);
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue