parent
5d8a084070
commit
b6fcd4b341
34 changed files with 972 additions and 139 deletions
|
|
@ -30,7 +30,10 @@ MatrixType make_initialized_matrix(rotgen::tests::matrix_block_test_case<MatrixT
|
|||
auto[d,i0,j0,ni,nj] = matrix_construct;
|
||||
auto[r,c,fn] = d;
|
||||
|
||||
MatrixType matrix(r, c);
|
||||
MatrixType matrix;
|
||||
|
||||
if constexpr(MatrixType::RowsAtCompileTime == -1 &&MatrixType::ColsAtCompileTime == -1)
|
||||
rotgen::resize(matrix, r, c);
|
||||
|
||||
for(rotgen::Index i = 0; i < r; ++i)
|
||||
for(rotgen::Index j = 0; j < c; ++j)
|
||||
|
|
|
|||
|
|
@ -21,17 +21,11 @@ namespace rotgen::tests
|
|||
|
||||
prepare([&](auto r, auto c) { return input(r,c); }, ref);
|
||||
|
||||
TTS_EQUAL(input.norm() , ref.norm());
|
||||
TTS_EQUAL(input.squaredNorm() , ref.squaredNorm());
|
||||
TTS_EQUAL(input.template lpNorm<1>() , ref.template lpNorm<1>());
|
||||
TTS_EQUAL(input.template lpNorm<2>() , ref.template lpNorm<2>());
|
||||
TTS_EQUAL(input.template lpNorm<rotgen::Infinity>() , ref.template lpNorm<Eigen::Infinity>());
|
||||
|
||||
TTS_EQUAL(norm(input) , ref.norm());
|
||||
TTS_EQUAL(squaredNorm(input) , ref.squaredNorm());
|
||||
TTS_EQUAL(lpNorm<1>(input) , ref.template lpNorm<1>());
|
||||
TTS_EQUAL(lpNorm<2>(input) , ref.template lpNorm<2>());
|
||||
TTS_EQUAL(lpNorm<rotgen::Infinity>(input) , ref.template lpNorm<Eigen::Infinity>());
|
||||
TTS_EQUAL(rotgen::norm(input) , ref.norm());
|
||||
TTS_EQUAL(rotgen::squaredNorm(input) , ref.squaredNorm());
|
||||
TTS_EQUAL(rotgen::lpNorm<1>(input) , ref.template lpNorm<1>());
|
||||
TTS_EQUAL(rotgen::lpNorm<2>(input) , ref.template lpNorm<2>());
|
||||
TTS_EQUAL(rotgen::lpNorm<rotgen::Infinity>(input) , ref.template lpNorm<Eigen::Infinity>());
|
||||
|
||||
if constexpr(T::IsVectorAtCompileTime)
|
||||
{
|
||||
|
|
@ -40,14 +34,10 @@ namespace rotgen::tests
|
|||
mat_t norm_ref(input.rows(), input.cols());
|
||||
prepare([&](auto r, auto c) { return e_norm(r,c); }, norm_ref);
|
||||
|
||||
TTS_EQUAL(input.normalized(), norm_ref);
|
||||
TTS_EQUAL(normalized(input), norm_ref);
|
||||
auto m_norm = input;
|
||||
m_norm.normalize();
|
||||
TTS_EQUAL(m_norm, norm_ref);
|
||||
TTS_EQUAL(rotgen::normalized(input), norm_ref);
|
||||
|
||||
auto f_norm = input;
|
||||
normalize(f_norm);
|
||||
rotgen::normalize(f_norm);
|
||||
TTS_EQUAL(f_norm, norm_ref);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
79
test/unit/functions/svd.cpp
Normal file
79
test/unit/functions/svd.cpp
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
//==================================================================================================
|
||||
/*
|
||||
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("SVD decomposition - Dynamic case", rotgen::tests::types)
|
||||
<typename T, typename O>( tts::type< tts::types<T,O>> )
|
||||
{
|
||||
int rank, i = 5;
|
||||
auto eps = std::numeric_limits<T>::epsilon();
|
||||
|
||||
auto m = rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value>::Random(5,5);
|
||||
auto decomp = rotgen::svd(m);
|
||||
|
||||
do
|
||||
{
|
||||
rank = decomp.rank();
|
||||
|
||||
auto u = decomp.U(rank);
|
||||
auto d = decomp.singular_values(rank);
|
||||
auto dd = decomp.D(rank);
|
||||
auto v = decomp.V(rank);
|
||||
|
||||
TTS_EQUAL(rank, i);
|
||||
|
||||
auto rec = (u * dd * rotgen::transpose(v));
|
||||
auto error = m - rec;
|
||||
|
||||
TTS_LESS_EQUAL(rotgen::maxCoeff(rotgen::abs(error)) / eps, 16.)
|
||||
<< "Result:\n" << rec << "\n"
|
||||
<< "Residuals:\n" << error << "\n";
|
||||
|
||||
// Reduce rank by duplicating one column
|
||||
i--;
|
||||
col(m,i) = col(m,0);
|
||||
decomp = rotgen::svd(m);
|
||||
|
||||
}while(rank != 1);
|
||||
};
|
||||
|
||||
TTS_CASE_TPL("SVD decomposition - Static case", rotgen::tests::types)
|
||||
<typename T, typename O>( tts::type< tts::types<T,O>> )
|
||||
{
|
||||
int rank, i = 5;
|
||||
auto eps = std::numeric_limits<T>::epsilon();
|
||||
|
||||
auto m = rotgen::matrix<T,5,5,O::value>::Random();
|
||||
auto decomp = rotgen::svd(m);
|
||||
|
||||
do
|
||||
{
|
||||
rank = decomp.rank();
|
||||
|
||||
auto u = decomp.U(rank);
|
||||
auto d = decomp.singular_values(rank);
|
||||
auto dd = decomp.D(rank);
|
||||
auto v = decomp.V(rank);
|
||||
|
||||
TTS_EQUAL(rank, i);
|
||||
|
||||
auto rec = (u * dd * rotgen::transpose(v));
|
||||
auto error = m - rec;
|
||||
|
||||
TTS_LESS_EQUAL(rotgen::maxCoeff(rotgen::abs(error)) / eps, 16.)
|
||||
<< "Result:\n" << rec << "\n"
|
||||
<< "Residuals:\n" << error << "\n";
|
||||
|
||||
// Reduce rank by duplicating one column
|
||||
i--;
|
||||
col(m,i) = col(m,0);
|
||||
decomp = rotgen::svd(m);
|
||||
|
||||
}while(rank != 1);
|
||||
};
|
||||
|
|
@ -35,13 +35,28 @@ TTS_CASE_TPL("Dynamic matrix constructor with row and columns", rotgen::tests::t
|
|||
TTS_EQUAL(matrix.cols(), rotgen::Index{5});
|
||||
};
|
||||
|
||||
TTS_CASE_TPL("Static matrix constructor with row and columns", rotgen::tests::types)
|
||||
<typename T, typename O>( tts::type< tts::types<T,O>> )
|
||||
TTS_CASE_TPL("Static matrix constructor with row and columns", float, double)
|
||||
<typename T>( tts::type<T> )
|
||||
{
|
||||
rotgen::matrix<T,6,11,O::value> matrix(6, 11);
|
||||
rotgen::matrix<T,1,2> v2(6, 11);
|
||||
rotgen::matrix<T,2,1> w2(6, 11);
|
||||
|
||||
TTS_EQUAL(matrix.rows(), rotgen::Index{6});
|
||||
TTS_EQUAL(matrix.cols(), rotgen::Index{11});
|
||||
TTS_EQUAL(v2(0), T{6});
|
||||
TTS_EQUAL(v2(1), T{11});
|
||||
|
||||
TTS_EQUAL(w2(0), T{6});
|
||||
TTS_EQUAL(w2(1), T{11});
|
||||
|
||||
rotgen::matrix<T,1,3> v3(6, 11, 125);
|
||||
rotgen::matrix<T,3,1> w3(6, 11, 125);
|
||||
|
||||
TTS_EQUAL(v3(0), T{6});
|
||||
TTS_EQUAL(v3(1), T{11});
|
||||
TTS_EQUAL(v3(2), T{125});
|
||||
|
||||
TTS_EQUAL(w3(0), T{6});
|
||||
TTS_EQUAL(w3(1), T{11});
|
||||
TTS_EQUAL(w3(2), T{125});
|
||||
};
|
||||
|
||||
TTS_CASE_TPL("Copy constructor produces identical but independent matrix", rotgen::tests::types)
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ TTS_CASE_TPL("Test zero", rotgen::tests::types)
|
|||
test_value(setZero(matrix<T, 1, 1, O::value>{} ), 1, 1, 0);
|
||||
test_value(setZero(matrix<T, 10, 10, O::value>{} ), 10, 10, 0);
|
||||
test_value(setZero(matrix<T,Dynamic,Dynamic, O::value>{3, 4}), 3, 4, 0);
|
||||
test_value(setZero(matrix<T, 7, 5, O::value>{7, 5} ), 7, 5, 0);
|
||||
test_value(setZero(matrix<T, 7, 5, O::value>{} ), 7, 5, 0);
|
||||
test_value(setZero(matrix<T, 9,Dynamic>{9, 3} ), 9, 3, 0);
|
||||
test_value(setZero(matrix<T,Dynamic, 3>{2, 3} ), 2, 3, 0);
|
||||
};
|
||||
|
|
@ -72,7 +72,7 @@ TTS_CASE_TPL("Test ones", rotgen::tests::types)
|
|||
test_value(setOnes(matrix<T, 1, 1, O::value>{} ), 1, 1, 1);
|
||||
test_value(setOnes(matrix<T, 10, 10, O::value>{} ), 10, 10, 1);
|
||||
test_value(setOnes(matrix<T,Dynamic,Dynamic, O::value>{3, 4}), 3, 4, 1);
|
||||
test_value(setOnes(matrix<T, 7, 5, O::value>{7, 5} ), 7, 5, 1);
|
||||
test_value(setOnes(matrix<T, 7, 5, O::value>{} ), 7, 5, 1);
|
||||
test_value(setOnes(matrix<T, 9,Dynamic>{9, 3} ), 9, 3, 1);
|
||||
test_value(setOnes(matrix<T,Dynamic, 3>{2, 3} ), 2, 3, 1);
|
||||
};
|
||||
|
|
@ -93,7 +93,7 @@ TTS_CASE_TPL("Test constant", rotgen::tests::types)
|
|||
test_value(setConstant(matrix<T, 1, 1, O::value>{} , T(5.12)), 1, 1, T(5.12));
|
||||
test_value(setConstant(matrix<T, 10, 10, O::value>{} , T(5.12)), 10, 10, T(5.12));
|
||||
test_value(setConstant(matrix<T,Dynamic,Dynamic, O::value>{3, 4}, T(5.12)), 3, 4, T(5.12));
|
||||
test_value(setConstant(matrix<T, 7, 5, O::value>{7, 5} , T(5.12)), 7, 5, T(5.12));
|
||||
test_value(setConstant(matrix<T, 7, 5, O::value>{} , T(5.12)), 7, 5, T(5.12));
|
||||
test_value(setConstant(matrix<T, 9,Dynamic>{9, 3} , T(5.12)), 9, 3, T(5.12));
|
||||
test_value(setConstant(matrix<T,Dynamic, 3>{2, 3} , T(5.12)), 2, 3, T(5.12));
|
||||
};
|
||||
|
|
@ -114,7 +114,7 @@ TTS_CASE_TPL("Test random", rotgen::tests::types)
|
|||
test_random(setRandom(matrix<T, 1, 1, O::value>{} ), 1, 1);
|
||||
test_random(setRandom(matrix<T, 10, 10, O::value>{} ), 10, 10);
|
||||
test_random(setRandom(matrix<T,Dynamic,Dynamic, O::value>{3, 4}), 3, 4);
|
||||
test_random(setRandom(matrix<T, 7, 5, O::value>{7, 5} ), 7, 5);
|
||||
test_random(setRandom(matrix<T, 7, 5, O::value>{} ), 7, 5);
|
||||
test_random(setRandom(matrix<T, 9,Dynamic>{9, 3} ), 9, 3);
|
||||
test_random(setRandom(matrix<T,Dynamic, 3>{2, 3} ), 2, 3);
|
||||
};
|
||||
|
|
@ -135,7 +135,7 @@ TTS_CASE_TPL("Test identity", rotgen::tests::types)
|
|||
test_identity(setIdentity(matrix<T, 1, 1, O::value>{} ), 1, 1);
|
||||
test_identity(setIdentity(matrix<T, 10, 10, O::value>{} ), 10, 10);
|
||||
test_identity(setIdentity(matrix<T,Dynamic,Dynamic, O::value>{3, 4}), 3, 4);
|
||||
test_identity(setIdentity(matrix<T, 7, 5, O::value>{7, 5} ), 7, 5);
|
||||
test_identity(setIdentity(matrix<T, 7, 5, O::value>{} ), 7, 5);
|
||||
test_identity(setIdentity(matrix<T, 9,Dynamic>{9, 3} ), 9, 3);
|
||||
test_identity(setIdentity(matrix<T,Dynamic, 3>{2, 3} ), 2, 3);
|
||||
};
|
||||
62
test/unit/matrix/inverse.cpp
Normal file
62
test/unit/matrix/inverse.cpp
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
//==================================================================================================
|
||||
/*
|
||||
ROTGEN - Runtime Overlay for Eigen
|
||||
Copyright : CODE RECKONS
|
||||
SPDX-License-Identifier: BSL-1.0
|
||||
*/
|
||||
//==================================================================================================
|
||||
#include "unit/tests.hpp"
|
||||
#include "unit/common/arithmetic.hpp"
|
||||
#include <rotgen/rotgen.hpp>
|
||||
|
||||
TTS_CASE_TPL("Test dynamic matrix inverse", rotgen::tests::types)
|
||||
<typename T, typename O>( tts::type< tts::types<T,O>> )
|
||||
{
|
||||
using mat_t = rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value>;
|
||||
auto eps = std::numeric_limits<T>::epsilon();
|
||||
|
||||
auto const cases = rotgen::tests::generate_matrix_references();
|
||||
for (const auto& [r, c, fn] : cases)
|
||||
{
|
||||
if(r == c)
|
||||
{
|
||||
auto input = mat_t::Random(r, c);
|
||||
auto inv = rotgen::inverse(input);
|
||||
|
||||
auto rec = input * inv;
|
||||
auto id = mat_t::Identity(rotgen::rows(rec),rotgen::cols(rec));
|
||||
auto error = rec - id;
|
||||
|
||||
TTS_LESS_EQUAL(rotgen::maxCoeff(rotgen::abs(error)) / eps, 64.)
|
||||
<< "Result:\n" << rec << "\n"
|
||||
<< "Residuals:\n" << error << "\n";
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
TTS_CASE_TPL("Test static matrix inverse", rotgen::tests::types)
|
||||
<typename T, typename O>( tts::type< tts::types<T,O>> )
|
||||
{
|
||||
using mat_t = rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value>;
|
||||
auto eps = std::numeric_limits<T>::epsilon();
|
||||
auto const cases = rotgen::tests::generate_static_matrix_references();
|
||||
|
||||
auto process = [&]<typename D>(D const&)
|
||||
{
|
||||
if constexpr(D::rows == D::cols)
|
||||
{
|
||||
auto input = rotgen::matrix<T,D::rows,D::cols,O::value>::Random();
|
||||
auto inv = rotgen::inverse(input);
|
||||
|
||||
auto rec = input * inv;
|
||||
auto id = mat_t::Identity(rotgen::rows(rec),rotgen::cols(rec));
|
||||
auto error = rec - id;
|
||||
|
||||
TTS_LESS_EQUAL(rotgen::maxCoeff(rotgen::abs(error)) / eps, 64.)
|
||||
<< "Result:\n" << rec << "\n"
|
||||
<< "Residuals:\n" << error << "\n";
|
||||
}
|
||||
};
|
||||
|
||||
std::apply([&](auto const&... d) { (process(d),...);}, cases);
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue