Closes #18 Co-authored-by: Jules Pénuchot <jules@penuchot.com> See merge request oss/rotgen!50
112 lines
3.1 KiB
C++
112 lines
3.1 KiB
C++
//==================================================================================================
|
|
/*
|
|
ROTGEN - Runtime Overlay for Eigen
|
|
Copyright : CODE RECKONS
|
|
SPDX-License-Identifier: BSL-1.0
|
|
*/
|
|
//==================================================================================================
|
|
#include <rotgen/rotgen.hpp>
|
|
|
|
#include "unit/tests.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(rows(dyn_map), rotgen::Index{1});
|
|
TTS_EQUAL(cols(dyn_map), rotgen::Index{12});
|
|
|
|
rotgen::map<rotgen::matrix<T, 1, 12, rotgen::RowMajor>> s112_map(data);
|
|
TTS_EQUAL(rows(s112_map), rotgen::Index{1});
|
|
TTS_EQUAL(cols(s112_map), 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(rows(s121_map), rotgen::Index{12});
|
|
TTS_EQUAL(cols(s121_map), 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(rows(s34_map), rotgen::Index{3});
|
|
TTS_EQUAL(cols(s34_map), 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(rows(s62_map), rotgen::Index{6});
|
|
TTS_EQUAL(cols(s62_map), 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>>)
|
|
{
|
|
T data[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
|
|
|
|
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;
|
|
}
|
|
}();
|
|
|
|
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 = 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);
|
|
};
|