93 lines
2.9 KiB
C++
93 lines
2.9 KiB
C++
//==================================================================================================
|
|
/*
|
|
ROTGEN - Runtime Overlay for Eigen
|
|
Copyright : CODE RECKONS
|
|
SPDX-License-Identifier: BSL-1.0
|
|
*/
|
|
//==================================================================================================
|
|
#pragma once
|
|
|
|
#include <rotgen/rotgen.hpp>
|
|
|
|
#include "tts.hpp"
|
|
#include "unit/common/references.hpp"
|
|
#include "unit/tests.hpp"
|
|
#include <Eigen/Dense>
|
|
|
|
namespace rotgen::tests
|
|
{
|
|
template<typename T> void check_shape_functions(T rotgen_input)
|
|
{
|
|
using eigen_mat_t =
|
|
matrix<typename T::value_type, Dynamic, Dynamic, T::storage_order>;
|
|
|
|
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(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)
|
|
{
|
|
eigen_mat_t ref = rotgen_input;
|
|
transposeInPlace(rotgen_input);
|
|
TTS_EQUAL(rotgen_input, eigen_result);
|
|
|
|
adjointInPlace(rotgen_input);
|
|
TTS_EQUAL(rotgen_input, ref);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (rotgen_input.rows() == rotgen_input.cols())
|
|
{
|
|
eigen_mat_t eigen_ref = rotgen_input;
|
|
transposeInPlace(rotgen_input);
|
|
TTS_EQUAL(rotgen_input, eigen_result);
|
|
|
|
adjointInPlace(rotgen_input);
|
|
TTS_EQUAL(rotgen_input, eigen_ref);
|
|
}
|
|
}
|
|
|
|
if constexpr (!rotgen::use_expression_templates)
|
|
{
|
|
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& rotgen_input)
|
|
{
|
|
using eigen_mat_t =
|
|
Eigen::Matrix<typename T::value_type, Eigen::Dynamic, Eigen::Dynamic>;
|
|
|
|
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(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(rotgen_input, &row, &col),
|
|
eigen_ref.minCoeff(&ref_row, &ref_col));
|
|
TTS_EQUAL(row, ref_row);
|
|
TTS_EQUAL(col, 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);
|
|
}
|
|
}
|
|
}
|