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,81 +5,85 @@
|
|||
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_shape_functions(T original)
|
||||
template<typename T> void check_shape_functions(T rotgen_input)
|
||||
{
|
||||
using mat_t =
|
||||
using eigen_mat_t =
|
||||
matrix<typename T::value_type, Dynamic, Dynamic, T::storage_order>;
|
||||
|
||||
mat_t result(original.cols(), original.rows());
|
||||
prepare([&](auto r, auto c) { return original(c, r); }, result);
|
||||
eigen_mat_t eigen_result(rotgen_input.cols(), rotgen_input.rows());
|
||||
prepare([&](auto r, auto c) { return rotgen_input(c, r); }, eigen_result);
|
||||
|
||||
TTS_EQUAL(transpose(original), result);
|
||||
TTS_EQUAL(conjugate(original), original);
|
||||
TTS_EQUAL(adjoint(original), result);
|
||||
TTS_EQUAL(transpose(rotgen_input), eigen_result);
|
||||
TTS_EQUAL(conjugate(rotgen_input), rotgen_input);
|
||||
TTS_EQUAL(adjoint(rotgen_input), eigen_result);
|
||||
|
||||
if constexpr (T::is_defined_static)
|
||||
{
|
||||
if constexpr (T::RowsAtCompileTime == T::ColsAtCompileTime)
|
||||
{
|
||||
mat_t ref = original;
|
||||
transposeInPlace(original);
|
||||
TTS_EQUAL(original, result);
|
||||
eigen_mat_t ref = rotgen_input;
|
||||
transposeInPlace(rotgen_input);
|
||||
TTS_EQUAL(rotgen_input, eigen_result);
|
||||
|
||||
adjointInPlace(original);
|
||||
TTS_EQUAL(original, ref);
|
||||
adjointInPlace(rotgen_input);
|
||||
TTS_EQUAL(rotgen_input, ref);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (original.rows() == original.cols())
|
||||
if (rotgen_input.rows() == rotgen_input.cols())
|
||||
{
|
||||
mat_t ref = original;
|
||||
transposeInPlace(original);
|
||||
TTS_EQUAL(original, result);
|
||||
eigen_mat_t eigen_ref = rotgen_input;
|
||||
transposeInPlace(rotgen_input);
|
||||
TTS_EQUAL(rotgen_input, eigen_result);
|
||||
|
||||
adjointInPlace(original);
|
||||
TTS_EQUAL(original, ref);
|
||||
adjointInPlace(rotgen_input);
|
||||
TTS_EQUAL(rotgen_input, eigen_ref);
|
||||
}
|
||||
}
|
||||
|
||||
if constexpr (!rotgen::use_expression_templates)
|
||||
{
|
||||
TTS_EXPECT(verify_rotgen_reentrance(original.transpose()));
|
||||
TTS_EXPECT(verify_rotgen_reentrance(original.conjugate()));
|
||||
TTS_EXPECT(verify_rotgen_reentrance(original.adjoint()));
|
||||
TTS_EXPECT(verify_rotgen_reentrance(transpose(rotgen_input)));
|
||||
TTS_EXPECT(verify_rotgen_reentrance(conjugate(rotgen_input)));
|
||||
TTS_EXPECT(verify_rotgen_reentrance(adjoint(rotgen_input)));
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T> void check_reduction_functions(T const& input)
|
||||
template<typename T> void check_reduction_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());
|
||||
prepare([&](auto r, auto c) { return input(r, c); }, ref);
|
||||
eigen_mat_t eigen_ref(rotgen_input.rows(), rotgen_input.cols());
|
||||
prepare([&](auto r, auto c) { return rotgen_input(r, c); }, eigen_ref);
|
||||
|
||||
TTS_ULP_EQUAL(sum(input), ref.sum(), 2);
|
||||
TTS_ULP_EQUAL(prod(input), ref.prod(), 2);
|
||||
TTS_ULP_EQUAL(mean(input), ref.mean(), 2);
|
||||
TTS_EQUAL(trace(input), ref.trace());
|
||||
TTS_EQUAL(minCoeff(input), ref.minCoeff());
|
||||
TTS_EQUAL(maxCoeff(input), ref.maxCoeff());
|
||||
TTS_ULP_EQUAL(sum(rotgen_input), eigen_ref.sum(), 2);
|
||||
TTS_ULP_EQUAL(prod(rotgen_input), eigen_ref.prod(), 2);
|
||||
TTS_ULP_EQUAL(mean(rotgen_input), eigen_ref.mean(), 2);
|
||||
TTS_EQUAL(trace(rotgen_input), eigen_ref.trace());
|
||||
TTS_EQUAL(minCoeff(rotgen_input), eigen_ref.minCoeff());
|
||||
TTS_EQUAL(maxCoeff(rotgen_input), eigen_ref.maxCoeff());
|
||||
|
||||
{
|
||||
int row, col, ref_row, ref_col;
|
||||
|
||||
TTS_EQUAL(minCoeff(input, &row, &col), ref.minCoeff(&ref_row, &ref_col));
|
||||
TTS_EQUAL(minCoeff(rotgen_input, &row, &col),
|
||||
eigen_ref.minCoeff(&ref_row, &ref_col));
|
||||
TTS_EQUAL(row, ref_row);
|
||||
TTS_EQUAL(col, ref_col);
|
||||
|
||||
TTS_EQUAL(maxCoeff(input, &row, &col), ref.maxCoeff(&ref_row, &ref_col));
|
||||
TTS_EQUAL(maxCoeff(rotgen_input, &row, &col),
|
||||
eigen_ref.maxCoeff(&ref_row, &ref_col));
|
||||
TTS_EQUAL(row, ref_row);
|
||||
TTS_EQUAL(col, ref_col);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,89 +5,60 @@
|
|||
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_cwise_functions(T const& input)
|
||||
template<typename T> void check_cwise_functions(T const& rotgen_input)
|
||||
{
|
||||
using EigenMatrix =
|
||||
using eigen_mat_t =
|
||||
Eigen::Matrix<typename T::value_type, Eigen::Dynamic, Eigen::Dynamic>;
|
||||
using mat_t =
|
||||
|
||||
using rotgen_mat_t =
|
||||
matrix<typename T::value_type, Dynamic, Dynamic, T::storage_order>;
|
||||
|
||||
TTS_WHEN("Unary Cwise operations")
|
||||
{
|
||||
EigenMatrix e_ref(input.rows(), input.cols());
|
||||
prepare([&](auto r, auto c) { return input(r, c); }, e_ref);
|
||||
eigen_mat_t eigen_ref(rotgen_input.rows(), rotgen_input.cols());
|
||||
prepare([&](auto r, auto c) { return rotgen_input(r, c); }, eigen_ref);
|
||||
|
||||
mat_t ref(input.rows(), input.cols());
|
||||
|
||||
TTS_AND_THEN(".cwiseAbs")
|
||||
{
|
||||
e_ref = e_ref.cwiseAbs();
|
||||
prepare([&](auto r, auto c) { return e_ref(r, c); }, ref);
|
||||
TTS_EQUAL(input.cwiseAbs(), ref);
|
||||
}
|
||||
|
||||
TTS_AND_THEN(".cwiseAbs2")
|
||||
{
|
||||
e_ref = e_ref.cwiseAbs2();
|
||||
prepare([&](auto r, auto c) { return e_ref(r, c); }, ref);
|
||||
TTS_EQUAL(input.cwiseAbs2(), ref);
|
||||
}
|
||||
|
||||
TTS_AND_THEN(".cwiseInverse")
|
||||
{
|
||||
e_ref = e_ref.cwiseInverse();
|
||||
prepare([&](auto r, auto c) { return e_ref(r, c); }, ref);
|
||||
TTS_EQUAL(input.cwiseInverse(), ref);
|
||||
}
|
||||
|
||||
TTS_AND_THEN(".cwiseSqrt")
|
||||
{
|
||||
e_ref = e_ref.cwiseAbs().cwiseSqrt();
|
||||
auto mat = input.cwiseAbs();
|
||||
auto proper_input = mat.cwiseSqrt();
|
||||
|
||||
for (rotgen::Index r = 0; r < input.rows(); ++r)
|
||||
for (rotgen::Index c = 0; c < input.cols(); ++c)
|
||||
TTS_ULP_EQUAL(proper_input(r, c), e_ref(r, c), 1);
|
||||
}
|
||||
rotgen_mat_t rotgen_ref(rotgen_input.rows(), rotgen_input.cols());
|
||||
|
||||
TTS_AND_THEN("abs()")
|
||||
{
|
||||
e_ref = e_ref.cwiseAbs();
|
||||
prepare([&](auto r, auto c) { return e_ref(r, c); }, ref);
|
||||
TTS_EQUAL(rotgen::abs(input), ref);
|
||||
eigen_ref = eigen_ref.cwiseAbs();
|
||||
prepare([&](auto r, auto c) { return eigen_ref(r, c); }, rotgen_ref);
|
||||
TTS_EQUAL(rotgen::abs(rotgen_input), rotgen_ref);
|
||||
}
|
||||
|
||||
TTS_AND_THEN("abs2()")
|
||||
{
|
||||
e_ref = e_ref.cwiseAbs2();
|
||||
prepare([&](auto r, auto c) { return e_ref(r, c); }, ref);
|
||||
TTS_EQUAL(rotgen::abs2(input), ref);
|
||||
eigen_ref = eigen_ref.cwiseAbs2();
|
||||
prepare([&](auto r, auto c) { return eigen_ref(r, c); }, rotgen_ref);
|
||||
TTS_EQUAL(rotgen::abs2(rotgen_input), rotgen_ref);
|
||||
}
|
||||
|
||||
TTS_AND_THEN("rec")
|
||||
{
|
||||
e_ref = e_ref.cwiseInverse();
|
||||
prepare([&](auto r, auto c) { return e_ref(r, c); }, ref);
|
||||
TTS_EQUAL(rotgen::rec(input), ref);
|
||||
eigen_ref = eigen_ref.cwiseInverse();
|
||||
prepare([&](auto r, auto c) { return eigen_ref(r, c); }, rotgen_ref);
|
||||
TTS_EQUAL(rotgen::rec(rotgen_input), rotgen_ref);
|
||||
}
|
||||
|
||||
TTS_AND_THEN("sqrt")
|
||||
{
|
||||
e_ref = e_ref.cwiseAbs().cwiseSqrt();
|
||||
auto mat = input.cwiseAbs();
|
||||
eigen_ref = eigen_ref.cwiseAbs().cwiseSqrt();
|
||||
auto mat = rotgen::abs(rotgen_input);
|
||||
auto proper_input = rotgen::sqrt(mat);
|
||||
|
||||
for (rotgen::Index r = 0; r < input.rows(); ++r)
|
||||
for (rotgen::Index c = 0; c < input.cols(); ++c)
|
||||
TTS_ULP_EQUAL(proper_input(r, c), e_ref(r, c), 1);
|
||||
for (rotgen::Index r = 0; r < rotgen_input.rows(); ++r)
|
||||
for (rotgen::Index c = 0; c < rotgen_input.cols(); ++c)
|
||||
TTS_ULP_EQUAL(proper_input(r, c), eigen_ref(r, c), 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,11 +5,13 @@
|
|||
SPDX-License-Identifier: BSL-1.0
|
||||
*/
|
||||
//==================================================================================================
|
||||
#pragma once
|
||||
|
||||
#include <rotgen/rotgen.hpp>
|
||||
|
||||
#include <Eigen/Dense>
|
||||
#include <vector>
|
||||
#include <tuple>
|
||||
#include <vector>
|
||||
|
||||
namespace rotgen::tests
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue