Testing functional API only (oss/rotgen#17)
Co-authored-by: Jules Pénuchot <jules@penuchot.com> See merge request oss/rotgen!42
This commit is contained in:
parent
6fa95fb22d
commit
4a7aa08cdb
11 changed files with 192 additions and 192 deletions
|
|
@ -5,42 +5,47 @@
|
|||
SPDX-License-Identifier: BSL-1.0
|
||||
*/
|
||||
//==================================================================================================
|
||||
#pragma once
|
||||
|
||||
#include <rotgen/rotgen.hpp>
|
||||
|
||||
#include "tts.hpp"
|
||||
#include <Eigen/Dense>
|
||||
#include <vector>
|
||||
#include <tuple>
|
||||
|
||||
namespace rotgen::tests
|
||||
{
|
||||
template<typename T> void check_norms_functions(T const& input)
|
||||
template<typename T> void check_norms_functions(T const& rotgen_input)
|
||||
{
|
||||
using EigenMatrix =
|
||||
using eigen_mat_t =
|
||||
Eigen::Matrix<typename T::value_type, Eigen::Dynamic, Eigen::Dynamic>;
|
||||
|
||||
EigenMatrix ref(input.rows(), input.cols());
|
||||
eigen_mat_t eigen_ref(rotgen_input.rows(), rotgen_input.cols());
|
||||
|
||||
prepare([&](auto r, auto c) { return input(r, c); }, ref);
|
||||
prepare([&](auto row, auto col) { return rotgen_input(row, col); },
|
||||
eigen_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>());
|
||||
TTS_EQUAL(rotgen::norm(rotgen_input), eigen_ref.norm());
|
||||
TTS_EQUAL(rotgen::squaredNorm(rotgen_input), eigen_ref.squaredNorm());
|
||||
TTS_EQUAL(rotgen::lpNorm<1>(rotgen_input), eigen_ref.template lpNorm<1>());
|
||||
TTS_EQUAL(rotgen::lpNorm<2>(rotgen_input), eigen_ref.template lpNorm<2>());
|
||||
TTS_EQUAL(rotgen::lpNorm<rotgen::Infinity>(rotgen_input),
|
||||
eigen_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);
|
||||
eigen_mat_t eigen_normalized = eigen_ref.normalized();
|
||||
using rotgen_mat_t =
|
||||
rotgen::matrix<typename T::value_type, rotgen::Dynamic, rotgen::Dynamic,
|
||||
T::storage_order>;
|
||||
rotgen_mat_t rotgen_norm_ref(rotgen_input.rows(), rotgen_input.cols());
|
||||
prepare([&](auto row, auto col) { return eigen_normalized(row, col); },
|
||||
rotgen_norm_ref);
|
||||
|
||||
TTS_EQUAL(rotgen::normalized(input), norm_ref);
|
||||
TTS_EQUAL(rotgen::normalized(rotgen_input), rotgen_norm_ref);
|
||||
|
||||
auto f_norm = input;
|
||||
rotgen::normalize(f_norm);
|
||||
TTS_EQUAL(f_norm, norm_ref);
|
||||
auto rotgen_f_norm = rotgen_input;
|
||||
rotgen::normalize(rotgen_f_norm);
|
||||
TTS_EQUAL(rotgen_f_norm, rotgen_norm_ref);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue