mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
Clang-format tests, examples, libraries, benchmarks, etc.
This commit is contained in:
committed by
Rasmus Munk Larsen
parent
3252ecc7a4
commit
46e9cdb7fe
@@ -15,96 +15,85 @@ using namespace std;
|
||||
|
||||
namespace Eigen {
|
||||
namespace internal {
|
||||
template<int Size>
|
||||
struct increment_if_fixed_size
|
||||
{
|
||||
enum {
|
||||
ret = (Size == Dynamic) ? Dynamic : Size+1
|
||||
};
|
||||
template <int Size>
|
||||
struct increment_if_fixed_size {
|
||||
enum { ret = (Size == Dynamic) ? Dynamic : Size + 1 };
|
||||
};
|
||||
}
|
||||
}
|
||||
} // namespace internal
|
||||
} // namespace Eigen
|
||||
|
||||
template<typename Scalar_, int Deg_>
|
||||
void realRoots_to_monicPolynomial_test(int deg)
|
||||
{
|
||||
typedef internal::increment_if_fixed_size<Deg_> Dim;
|
||||
typedef Matrix<Scalar_,Dim::ret,1> PolynomialType;
|
||||
typedef Matrix<Scalar_,Deg_,1> EvalRootsType;
|
||||
template <typename Scalar_, int Deg_>
|
||||
void realRoots_to_monicPolynomial_test(int deg) {
|
||||
typedef internal::increment_if_fixed_size<Deg_> Dim;
|
||||
typedef Matrix<Scalar_, Dim::ret, 1> PolynomialType;
|
||||
typedef Matrix<Scalar_, Deg_, 1> EvalRootsType;
|
||||
|
||||
PolynomialType pols(deg+1);
|
||||
PolynomialType pols(deg + 1);
|
||||
EvalRootsType roots = EvalRootsType::Random(deg);
|
||||
roots_to_monicPolynomial( roots, pols );
|
||||
roots_to_monicPolynomial(roots, pols);
|
||||
|
||||
EvalRootsType evr( deg );
|
||||
for( int i=0; i<roots.size(); ++i ){
|
||||
evr[i] = std::abs( poly_eval( pols, roots[i] ) ); }
|
||||
EvalRootsType evr(deg);
|
||||
for (int i = 0; i < roots.size(); ++i) {
|
||||
evr[i] = std::abs(poly_eval(pols, roots[i]));
|
||||
}
|
||||
|
||||
bool evalToZero = evr.isZero( test_precision<Scalar_>() );
|
||||
if( !evalToZero ){
|
||||
cerr << evr.transpose() << endl; }
|
||||
VERIFY( evalToZero );
|
||||
bool evalToZero = evr.isZero(test_precision<Scalar_>());
|
||||
if (!evalToZero) {
|
||||
cerr << evr.transpose() << endl;
|
||||
}
|
||||
VERIFY(evalToZero);
|
||||
}
|
||||
|
||||
template<typename Scalar_> void realRoots_to_monicPolynomial_scalar()
|
||||
{
|
||||
CALL_SUBTEST_2( (realRoots_to_monicPolynomial_test<Scalar_,2>(2)) );
|
||||
CALL_SUBTEST_3( (realRoots_to_monicPolynomial_test<Scalar_,3>(3)) );
|
||||
CALL_SUBTEST_4( (realRoots_to_monicPolynomial_test<Scalar_,4>(4)) );
|
||||
CALL_SUBTEST_5( (realRoots_to_monicPolynomial_test<Scalar_,5>(5)) );
|
||||
CALL_SUBTEST_6( (realRoots_to_monicPolynomial_test<Scalar_,6>(6)) );
|
||||
CALL_SUBTEST_7( (realRoots_to_monicPolynomial_test<Scalar_,7>(7)) );
|
||||
CALL_SUBTEST_8( (realRoots_to_monicPolynomial_test<Scalar_,17>(17)) );
|
||||
template <typename Scalar_>
|
||||
void realRoots_to_monicPolynomial_scalar() {
|
||||
CALL_SUBTEST_2((realRoots_to_monicPolynomial_test<Scalar_, 2>(2)));
|
||||
CALL_SUBTEST_3((realRoots_to_monicPolynomial_test<Scalar_, 3>(3)));
|
||||
CALL_SUBTEST_4((realRoots_to_monicPolynomial_test<Scalar_, 4>(4)));
|
||||
CALL_SUBTEST_5((realRoots_to_monicPolynomial_test<Scalar_, 5>(5)));
|
||||
CALL_SUBTEST_6((realRoots_to_monicPolynomial_test<Scalar_, 6>(6)));
|
||||
CALL_SUBTEST_7((realRoots_to_monicPolynomial_test<Scalar_, 7>(7)));
|
||||
CALL_SUBTEST_8((realRoots_to_monicPolynomial_test<Scalar_, 17>(17)));
|
||||
|
||||
CALL_SUBTEST_9( (realRoots_to_monicPolynomial_test<Scalar_,Dynamic>(
|
||||
internal::random<int>(18,26) )) );
|
||||
CALL_SUBTEST_9((realRoots_to_monicPolynomial_test<Scalar_, Dynamic>(internal::random<int>(18, 26))));
|
||||
}
|
||||
|
||||
template <typename Scalar_, int Deg_>
|
||||
void CauchyBounds(int deg) {
|
||||
typedef internal::increment_if_fixed_size<Deg_> Dim;
|
||||
typedef Matrix<Scalar_, Dim::ret, 1> PolynomialType;
|
||||
typedef Matrix<Scalar_, Deg_, 1> EvalRootsType;
|
||||
|
||||
|
||||
|
||||
template<typename Scalar_, int Deg_>
|
||||
void CauchyBounds(int deg)
|
||||
{
|
||||
typedef internal::increment_if_fixed_size<Deg_> Dim;
|
||||
typedef Matrix<Scalar_,Dim::ret,1> PolynomialType;
|
||||
typedef Matrix<Scalar_,Deg_,1> EvalRootsType;
|
||||
|
||||
PolynomialType pols(deg+1);
|
||||
PolynomialType pols(deg + 1);
|
||||
EvalRootsType roots = EvalRootsType::Random(deg);
|
||||
roots_to_monicPolynomial( roots, pols );
|
||||
Scalar_ M = cauchy_max_bound( pols );
|
||||
Scalar_ m = cauchy_min_bound( pols );
|
||||
roots_to_monicPolynomial(roots, pols);
|
||||
Scalar_ M = cauchy_max_bound(pols);
|
||||
Scalar_ m = cauchy_min_bound(pols);
|
||||
Scalar_ Max = roots.array().abs().maxCoeff();
|
||||
Scalar_ min = roots.array().abs().minCoeff();
|
||||
bool eval = (M >= Max) && (m <= min);
|
||||
if( !eval )
|
||||
{
|
||||
if (!eval) {
|
||||
cerr << "Roots: " << roots << endl;
|
||||
cerr << "Bounds: (" << m << ", " << M << ")" << endl;
|
||||
cerr << "Min,Max: (" << min << ", " << Max << ")" << endl;
|
||||
}
|
||||
VERIFY( eval );
|
||||
VERIFY(eval);
|
||||
}
|
||||
|
||||
template<typename Scalar_> void CauchyBounds_scalar()
|
||||
{
|
||||
CALL_SUBTEST_2( (CauchyBounds<Scalar_,2>(2)) );
|
||||
CALL_SUBTEST_3( (CauchyBounds<Scalar_,3>(3)) );
|
||||
CALL_SUBTEST_4( (CauchyBounds<Scalar_,4>(4)) );
|
||||
CALL_SUBTEST_5( (CauchyBounds<Scalar_,5>(5)) );
|
||||
CALL_SUBTEST_6( (CauchyBounds<Scalar_,6>(6)) );
|
||||
CALL_SUBTEST_7( (CauchyBounds<Scalar_,7>(7)) );
|
||||
CALL_SUBTEST_8( (CauchyBounds<Scalar_,17>(17)) );
|
||||
template <typename Scalar_>
|
||||
void CauchyBounds_scalar() {
|
||||
CALL_SUBTEST_2((CauchyBounds<Scalar_, 2>(2)));
|
||||
CALL_SUBTEST_3((CauchyBounds<Scalar_, 3>(3)));
|
||||
CALL_SUBTEST_4((CauchyBounds<Scalar_, 4>(4)));
|
||||
CALL_SUBTEST_5((CauchyBounds<Scalar_, 5>(5)));
|
||||
CALL_SUBTEST_6((CauchyBounds<Scalar_, 6>(6)));
|
||||
CALL_SUBTEST_7((CauchyBounds<Scalar_, 7>(7)));
|
||||
CALL_SUBTEST_8((CauchyBounds<Scalar_, 17>(17)));
|
||||
|
||||
CALL_SUBTEST_9( (CauchyBounds<Scalar_,Dynamic>(
|
||||
internal::random<int>(18,26) )) );
|
||||
CALL_SUBTEST_9((CauchyBounds<Scalar_, Dynamic>(internal::random<int>(18, 26))));
|
||||
}
|
||||
|
||||
EIGEN_DECLARE_TEST(polynomialutils)
|
||||
{
|
||||
for(int i = 0; i < g_repeat; i++)
|
||||
{
|
||||
EIGEN_DECLARE_TEST(polynomialutils) {
|
||||
for (int i = 0; i < g_repeat; i++) {
|
||||
realRoots_to_monicPolynomial_scalar<double>();
|
||||
realRoots_to_monicPolynomial_scalar<float>();
|
||||
CauchyBounds_scalar<double>();
|
||||
|
||||
Reference in New Issue
Block a user