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
164
test/unit/matrix/basic_api.cpp
Normal file
164
test/unit/matrix/basic_api.cpp
Normal file
|
|
@ -0,0 +1,164 @@
|
|||
//==================================================================================================
|
||||
/*
|
||||
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>> )
|
||||
{
|
||||
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> empty_matrix;
|
||||
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> matrix(3,4);
|
||||
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> row_vector(9,1);
|
||||
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> column_vector(1,5);
|
||||
|
||||
TTS_EQUAL(empty_matrix.size(), rotgen::Index{0});
|
||||
TTS_EQUAL(matrix.size(), rotgen::Index{12});
|
||||
TTS_EQUAL(row_vector.size(), rotgen::Index{9});
|
||||
TTS_EQUAL(column_vector.size(), rotgen::Index{5});
|
||||
};
|
||||
|
||||
TTS_CASE_TPL("Resizing dynamic matrix", rotgen::tests::types)
|
||||
<typename T, typename O>( tts::type< tts::types<T,O>> )
|
||||
{
|
||||
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> a(2, 3);
|
||||
|
||||
for(rotgen::Index r=0;r<a.rows();++r)
|
||||
for(rotgen::Index c=0;c<a.cols();++c)
|
||||
a(r,c) = 42 + 2*c + r;
|
||||
|
||||
a.resize(3, 2);
|
||||
TTS_EQUAL(a.rows(), rotgen::Index(3));
|
||||
TTS_EQUAL(a.cols(), rotgen::Index(2));
|
||||
|
||||
for(rotgen::Index r=0;r<a.rows();++r)
|
||||
for(rotgen::Index c=0;c<a.cols();++c)
|
||||
TTS_GREATER(a(r,c),0);
|
||||
|
||||
a.resize(2,2);
|
||||
TTS_EQUAL(a.rows(), rotgen::Index(2));
|
||||
TTS_EQUAL(a.cols(), rotgen::Index(2));
|
||||
};
|
||||
|
||||
TTS_CASE_TPL("Resizing static matrix", rotgen::tests::types)
|
||||
<typename T, typename O>( tts::type< tts::types<T,O>> )
|
||||
{
|
||||
rotgen::matrix<double, 3, 3> a;
|
||||
TTS_EXPECT_NOT_COMPILES(a, { a.resize(4, 5); });
|
||||
};
|
||||
|
||||
TTS_CASE_TPL("Dynamix matrix conservative resizing", rotgen::tests::types)
|
||||
<typename T, typename O>( tts::type< tts::types<T,O>> )
|
||||
{
|
||||
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> a(2, 3);
|
||||
|
||||
int i = 1;
|
||||
for(rotgen::Index r=0;r<a.rows();++r)
|
||||
for(rotgen::Index c=0;c<a.cols();++c)
|
||||
a(r, c) = i++;
|
||||
|
||||
a.conservativeResize(2, 3);
|
||||
TTS_EQUAL(a.rows(), rotgen::Index(2));
|
||||
TTS_EQUAL(a.cols(), rotgen::Index(3));
|
||||
|
||||
i = 1;
|
||||
for(rotgen::Index r=0;r<a.rows();++r)
|
||||
for(rotgen::Index c=0;c<a.cols();++c)
|
||||
TTS_EQUAL(a(r,c),i++);
|
||||
|
||||
a.conservativeResize(3, 2);
|
||||
TTS_EQUAL(a.rows(), rotgen::Index(3));
|
||||
TTS_EQUAL(a.cols(), rotgen::Index(2));
|
||||
int expected[3][2] = { {1, 2}, {4, 5} };
|
||||
for(rotgen::Index r = 0; r < 2; ++r)
|
||||
for(rotgen::Index c = 0; c < 2; ++c)
|
||||
TTS_EQUAL(a(r, c), expected[r][c]);
|
||||
|
||||
a.conservativeResize(4, 4);
|
||||
TTS_EQUAL(a.rows(), rotgen::Index(4));
|
||||
TTS_EQUAL(a.cols(), rotgen::Index(4));
|
||||
TTS_EQUAL(a(0,0), 1);
|
||||
TTS_EQUAL(a(3,3), 0);
|
||||
|
||||
a.conservativeResize(2, 2);
|
||||
TTS_EQUAL(a.rows(), rotgen::Index(2));
|
||||
TTS_EQUAL(a.cols(), rotgen::Index(2));
|
||||
TTS_EQUAL(a(0,0), 1);
|
||||
TTS_EQUAL(a(1,1), 5);
|
||||
|
||||
a.conservativeResize(1, 2);
|
||||
TTS_EQUAL(a.rows(), rotgen::Index(1));
|
||||
TTS_EQUAL(a.cols(), rotgen::Index(2));
|
||||
TTS_EQUAL(a(0,0), 1);
|
||||
TTS_EQUAL(a(0,1), 2);
|
||||
|
||||
a.conservativeResize(0, 0);
|
||||
TTS_EQUAL(a.rows(), rotgen::Index(0));
|
||||
TTS_EQUAL(a.cols(), rotgen::Index(0));
|
||||
|
||||
a.conservativeResize(3, 3);
|
||||
TTS_EQUAL(a.rows(), rotgen::Index(3));
|
||||
TTS_EQUAL(a.cols(), rotgen::Index(3));
|
||||
};
|
||||
|
||||
TTS_CASE_TPL("Static matrix conservative resizing", rotgen::tests::types)
|
||||
<typename T, typename O>( tts::type< tts::types<T,O>> )
|
||||
{
|
||||
rotgen::matrix<double, 3, 3> a;
|
||||
TTS_EXPECT_NOT_COMPILES(a, { a.conservativeResize(4, 5); });
|
||||
};
|
||||
|
||||
TTS_CASE_TPL("Test coefficient accessors", rotgen::tests::types)
|
||||
<typename T, typename O>( tts::type< tts::types<T,O>> )
|
||||
{
|
||||
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> a(3, 5);
|
||||
|
||||
for(rotgen::Index r=0;r<a.rows();++r)
|
||||
for(rotgen::Index c=0;c<a.cols();++c)
|
||||
a(r, c) = r + 2 * c + 3;
|
||||
|
||||
TTS_EQUAL(a(0,0), 3);
|
||||
TTS_EQUAL(a(1,1), 6);
|
||||
TTS_EQUAL(a(1,0), 4);
|
||||
TTS_EQUAL(a(2,2), 9);
|
||||
TTS_EQUAL(a(2,4), 13);
|
||||
|
||||
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>> )
|
||||
{
|
||||
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> a(2, 4);
|
||||
|
||||
int i = 1;
|
||||
if constexpr(!O::value)
|
||||
{
|
||||
for(rotgen::Index c=0;c<a.cols();++c)
|
||||
for(rotgen::Index r=0;r<a.rows();++r)
|
||||
a(r, c) = i++;
|
||||
}
|
||||
else
|
||||
{
|
||||
for(rotgen::Index r=0;r<a.rows();++r)
|
||||
for(rotgen::Index c=0;c<a.cols();++c)
|
||||
a(r, c) = i++;
|
||||
}
|
||||
|
||||
i = 1;
|
||||
for(rotgen::Index r=0;r<a.rows()*a.cols();++r)
|
||||
TTS_EQUAL(a(r), i++) << a;
|
||||
|
||||
T& ref = a(2);
|
||||
ref = 999.5;
|
||||
TTS_EQUAL(a(2), 999.5);
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue