Co-authored-by: Jules Pénuchot <jules@penuchot.com> Co-authored-by: Joel FALCOU <jfalcou@codereckons.com> See merge request oss/rotgen!41
46 lines
1.6 KiB
C++
46 lines
1.6 KiB
C++
//==================================================================================================
|
|
/*
|
|
ROTGEN - Runtime Overlay for Eigen
|
|
Copyright : CODE RECKONS
|
|
SPDX-License-Identifier: BSL-1.0
|
|
*/
|
|
//==================================================================================================
|
|
#include <rotgen/rotgen.hpp>
|
|
#include <Eigen/Dense>
|
|
#include <vector>
|
|
#include <tuple>
|
|
|
|
namespace rotgen::tests
|
|
{
|
|
template<typename T> void check_norms_functions(T const& input)
|
|
{
|
|
using EigenMatrix =
|
|
Eigen::Matrix<typename T::value_type, Eigen::Dynamic, Eigen::Dynamic>;
|
|
|
|
EigenMatrix ref(input.rows(), input.cols());
|
|
|
|
prepare([&](auto r, auto c) { return input(r, c); }, ref);
|
|
|
|
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)
|
|
{
|
|
EigenMatrix e_norm = ref.normalized();
|
|
using mat_t = rotgen::matrix<typename T::value_type, rotgen::Dynamic,
|
|
rotgen::Dynamic, T::storage_order>;
|
|
mat_t norm_ref(input.rows(), input.cols());
|
|
prepare([&](auto r, auto c) { return e_norm(r, c); }, norm_ref);
|
|
|
|
TTS_EQUAL(rotgen::normalized(input), norm_ref);
|
|
|
|
auto f_norm = input;
|
|
rotgen::normalize(f_norm);
|
|
TTS_EQUAL(f_norm, norm_ref);
|
|
}
|
|
}
|
|
}
|