45 #if __cplusplus >= 201103L 47 #ifdef EIGEN_USE_THREADS 56 #define min(A,B) please_protect_your_min_with_parentheses 57 #define max(A,B) please_protect_your_max_with_parentheses 58 #define isnan(X) please_protect_your_isnan_with_parentheses 59 #define isinf(X) please_protect_your_isinf_with_parentheses 60 #define isfinite(X) please_protect_your_isfinite_with_parentheses 64 #define M_PI please_use_EIGEN_PI_instead_of_M_PI 66 #define FORBIDDEN_IDENTIFIER (this_identifier_is_forbidden_to_avoid_clashes) this_identifier_is_forbidden_to_avoid_clashes 68 #define B0 FORBIDDEN_IDENTIFIER 72 #ifndef EIGEN_NO_DEBUG_SMALL_PRODUCT_BLOCKS 73 #define EIGEN_DEBUG_SMALL_PRODUCT_BLOCKS 77 #define TEST_SET_BUT_UNUSED_VARIABLE(X) EIGEN_UNUSED_VARIABLE(X) 79 #ifdef TEST_ENABLE_TEMPORARY_TRACKING 81 static long int nb_temporaries;
83 inline void on_temporary_creation(
long int size) {
85 if(size!=0) nb_temporaries++;
88 #define EIGEN_DENSE_STORAGE_CTOR_PLUGIN { on_temporary_creation(size); } 90 #define VERIFY_EVALUATION_COUNT(XPR,N) {\ 93 if(nb_temporaries!=N) { std::cerr << "nb_temporaries == " << nb_temporaries << "\n"; }\ 94 VERIFY( (#XPR) && nb_temporaries==N ); \ 100 #include "split_test_helper.h" 112 #if defined(__ALTIVEC__) || defined(__VSX__) 113 #define EIGEN_MAKING_DOCS 116 #ifndef EIGEN_TEST_FUNC 117 #error EIGEN_TEST_FUNC must be defined 120 #define DEFAULT_REPEAT 10 124 static std::vector<std::string> g_test_stack;
127 static int g_test_level = 0;
129 static unsigned int g_seed;
130 static bool g_has_set_repeat, g_has_set_seed;
133 #define TRACK std::cerr << __FILE__ << " " << __LINE__ << std::endl 136 #define EI_PP_MAKE_STRING2(S) #S 137 #define EI_PP_MAKE_STRING(S) EI_PP_MAKE_STRING2(S) 139 #define EIGEN_DEFAULT_IO_FORMAT IOFormat(4, 0, " ", "\n", "", "", "", "") 141 #if (defined(_CPPUNWIND) || defined(__EXCEPTIONS)) && !defined(__CUDA_ARCH__) 142 #define EIGEN_EXCEPTIONS 145 #ifndef EIGEN_NO_ASSERTION_CHECKING 149 static const bool should_raise_an_assert =
false;
154 static bool no_more_assert =
false;
155 static bool report_on_cerr_on_assert_failure =
true;
170 #ifdef EIGEN_DEBUG_ASSERTS 176 static bool push_assert =
false;
178 static std::vector<std::string> eigen_assert_list;
180 #define eigen_assert(a) \ 181 if( (!(a)) && (!no_more_assert) ) \ 183 if(report_on_cerr_on_assert_failure) \ 184 std::cerr << #a << " " __FILE__ << "(" << __LINE__ << ")\n"; \ 185 Eigen::no_more_assert = true; \ 186 EIGEN_THROW_X(Eigen::eigen_assert_exception()); \ 188 else if (Eigen::internal::push_assert) \ 190 eigen_assert_list.push_back(std::string(EI_PP_MAKE_STRING(__FILE__) " (" EI_PP_MAKE_STRING(__LINE__) ") : " #a) ); \ 193 #ifdef EIGEN_EXCEPTIONS 194 #define VERIFY_RAISES_ASSERT(a) \ 196 Eigen::no_more_assert = false; \ 197 Eigen::eigen_assert_list.clear(); \ 198 Eigen::internal::push_assert = true; \ 199 Eigen::report_on_cerr_on_assert_failure = false; \ 202 std::cerr << "One of the following asserts should have been triggered:\n"; \ 203 for (uint ai=0 ; ai<eigen_assert_list.size() ; ++ai) \ 204 std::cerr << " " << eigen_assert_list[ai] << "\n"; \ 205 VERIFY(Eigen::should_raise_an_assert && # a); \ 206 } catch (Eigen::eigen_assert_exception) { \ 207 Eigen::internal::push_assert = false; VERIFY(true); \ 209 Eigen::report_on_cerr_on_assert_failure = true; \ 210 Eigen::internal::push_assert = false; \ 212 #endif //EIGEN_EXCEPTIONS 214 #elif !defined(__CUDACC__) // EIGEN_DEBUG_ASSERTS 216 #define eigen_assert(a) \ 217 if( (!Eigen::internal::copy_bool(a)) && (!no_more_assert) )\ 219 Eigen::no_more_assert = true; \ 220 if(report_on_cerr_on_assert_failure) \ 221 eigen_plain_assert(a); \ 223 EIGEN_THROW_X(Eigen::eigen_assert_exception()); \ 225 #ifdef EIGEN_EXCEPTIONS 226 #define VERIFY_RAISES_ASSERT(a) { \ 227 Eigen::no_more_assert = false; \ 228 Eigen::report_on_cerr_on_assert_failure = false; \ 231 VERIFY(Eigen::should_raise_an_assert && # a); \ 233 catch (Eigen::eigen_assert_exception&) { VERIFY(true); } \ 234 Eigen::report_on_cerr_on_assert_failure = true; \ 236 #endif //EIGEN_EXCEPTIONS 237 #endif // EIGEN_DEBUG_ASSERTS 239 #ifndef VERIFY_RAISES_ASSERT 240 #define VERIFY_RAISES_ASSERT(a) \ 241 std::cout << "Can't VERIFY_RAISES_ASSERT( " #a " ) with exceptions disabled\n"; 244 #if !defined(__CUDACC__) 245 #define EIGEN_USE_CUSTOM_ASSERT 248 #else // EIGEN_NO_ASSERTION_CHECKING 250 #define VERIFY_RAISES_ASSERT(a) {} 252 #endif // EIGEN_NO_ASSERTION_CHECKING 255 #define EIGEN_INTERNAL_DEBUGGING 258 inline void verify_impl(
bool condition,
const char *testname,
const char *file,
int line,
const char *condition_as_string)
262 if(Eigen::g_test_level>0)
263 std::cerr <<
"WARNING: ";
264 std::cerr <<
"Test " << testname <<
" failed in " << file <<
" (" << line <<
")" 265 << std::endl <<
" " << condition_as_string << std::endl;
266 std::cerr <<
"Stack:\n";
267 const int test_stack_size =
static_cast<int>(Eigen::g_test_stack.size());
268 for(
int i=test_stack_size-1; i>=0; --i)
269 std::cerr <<
" - " << Eigen::g_test_stack[i] <<
"\n";
271 if(Eigen::g_test_level==0)
276 #define VERIFY(a) ::verify_impl(a, g_test_stack.back().c_str(), __FILE__, __LINE__, EI_PP_MAKE_STRING(a)) 278 #define VERIFY_GE(a, b) ::verify_impl(a >= b, g_test_stack.back().c_str(), __FILE__, __LINE__, EI_PP_MAKE_STRING(a >= b)) 279 #define VERIFY_LE(a, b) ::verify_impl(a <= b, g_test_stack.back().c_str(), __FILE__, __LINE__, EI_PP_MAKE_STRING(a <= b)) 282 #define VERIFY_IS_EQUAL(a, b) VERIFY(test_is_equal(a, b, true)) 283 #define VERIFY_IS_NOT_EQUAL(a, b) VERIFY(test_is_equal(a, b, false)) 284 #define VERIFY_IS_APPROX(a, b) VERIFY(verifyIsApprox(a, b)) 285 #define VERIFY_IS_NOT_APPROX(a, b) VERIFY(!test_isApprox(a, b)) 286 #define VERIFY_IS_MUCH_SMALLER_THAN(a, b) VERIFY(test_isMuchSmallerThan(a, b)) 287 #define VERIFY_IS_NOT_MUCH_SMALLER_THAN(a, b) VERIFY(!test_isMuchSmallerThan(a, b)) 288 #define VERIFY_IS_APPROX_OR_LESS_THAN(a, b) VERIFY(test_isApproxOrLessThan(a, b)) 289 #define VERIFY_IS_NOT_APPROX_OR_LESS_THAN(a, b) VERIFY(!test_isApproxOrLessThan(a, b)) 291 #define VERIFY_IS_UNITARY(a) VERIFY(test_isUnitary(a)) 293 #define CALL_SUBTEST(FUNC) do { \ 294 g_test_stack.push_back(EI_PP_MAKE_STRING(FUNC)); \ 296 g_test_stack.pop_back(); \ 303 template<>
inline float test_precision<float>() {
return 1e-3f; }
304 template<>
inline double test_precision<double>() {
return 1e-6; }
305 template<>
inline long double test_precision<long double>() {
return 1e-6l; }
306 template<>
inline float test_precision<std::complex<float> >() {
return test_precision<float>(); }
307 template<>
inline double test_precision<std::complex<double> >() {
return test_precision<double>(); }
308 template<>
inline long double test_precision<std::complex<long double> >() {
return test_precision<long double>(); }
310 inline bool test_isApprox(
const int& a,
const int& b)
311 {
return internal::isApprox(a, b, test_precision<int>()); }
312 inline bool test_isMuchSmallerThan(
const int& a,
const int& b)
313 {
return internal::isMuchSmallerThan(a, b, test_precision<int>()); }
314 inline bool test_isApproxOrLessThan(
const int& a,
const int& b)
315 {
return internal::isApproxOrLessThan(a, b, test_precision<int>()); }
317 inline bool test_isApprox(
const float& a,
const float& b)
318 {
return internal::isApprox(a, b, test_precision<float>()); }
319 inline bool test_isMuchSmallerThan(
const float& a,
const float& b)
320 {
return internal::isMuchSmallerThan(a, b, test_precision<float>()); }
321 inline bool test_isApproxOrLessThan(
const float& a,
const float& b)
322 {
return internal::isApproxOrLessThan(a, b, test_precision<float>()); }
324 inline bool test_isApprox(
const double& a,
const double& b)
325 {
return internal::isApprox(a, b, test_precision<double>()); }
326 inline bool test_isMuchSmallerThan(
const double& a,
const double& b)
327 {
return internal::isMuchSmallerThan(a, b, test_precision<double>()); }
328 inline bool test_isApproxOrLessThan(
const double& a,
const double& b)
329 {
return internal::isApproxOrLessThan(a, b, test_precision<double>()); }
331 #ifndef EIGEN_TEST_NO_COMPLEX 332 inline bool test_isApprox(
const std::complex<float>& a,
const std::complex<float>& b)
333 {
return internal::isApprox(a, b, test_precision<std::complex<float> >()); }
334 inline bool test_isMuchSmallerThan(
const std::complex<float>& a,
const std::complex<float>& b)
335 {
return internal::isMuchSmallerThan(a, b, test_precision<std::complex<float> >()); }
337 inline bool test_isApprox(
const std::complex<double>& a,
const std::complex<double>& b)
338 {
return internal::isApprox(a, b, test_precision<std::complex<double> >()); }
339 inline bool test_isMuchSmallerThan(
const std::complex<double>& a,
const std::complex<double>& b)
340 {
return internal::isMuchSmallerThan(a, b, test_precision<std::complex<double> >()); }
342 #ifndef EIGEN_TEST_NO_LONGDOUBLE 343 inline bool test_isApprox(
const std::complex<long double>& a,
const std::complex<long double>& b)
344 {
return internal::isApprox(a, b, test_precision<std::complex<long double> >()); }
345 inline bool test_isMuchSmallerThan(
const std::complex<long double>& a,
const std::complex<long double>& b)
346 {
return internal::isMuchSmallerThan(a, b, test_precision<std::complex<long double> >()); }
350 #ifndef EIGEN_TEST_NO_LONGDOUBLE 351 inline bool test_isApprox(
const long double& a,
const long double& b)
353 bool ret = internal::isApprox(a, b, test_precision<long double>());
355 << std::endl <<
" actual = " << a
356 << std::endl <<
" expected = " << b << std::endl << std::endl;
360 inline bool test_isMuchSmallerThan(
const long double& a,
const long double& b)
361 {
return internal::isMuchSmallerThan(a, b, test_precision<long double>()); }
362 inline bool test_isApproxOrLessThan(
const long double& a,
const long double& b)
363 {
return internal::isApproxOrLessThan(a, b, test_precision<long double>()); }
364 #endif // EIGEN_TEST_NO_LONGDOUBLE 366 inline bool test_isApprox(
const half& a,
const half& b)
367 {
return internal::isApprox(a, b, test_precision<half>()); }
368 inline bool test_isMuchSmallerThan(
const half& a,
const half& b)
369 {
return internal::isMuchSmallerThan(a, b, test_precision<half>()); }
370 inline bool test_isApproxOrLessThan(
const half& a,
const half& b)
371 {
return internal::isApproxOrLessThan(a, b, test_precision<half>()); }
374 template<
typename T1,
typename T2>
378 typedef typename T1::RealScalar RealScalar;
381 return sqrt(RealScalar((ea-eb).cwiseAbs2().sum()) / RealScalar((std::min)(eb.cwiseAbs2().sum(),ea.cwiseAbs2().sum())));
384 template<
typename T1,
typename T2>
385 typename T1::RealScalar test_relative_error(
const T1 &a,
const T2 &b,
const typename T1::Coefficients* = 0)
387 return test_relative_error(a.coeffs(), b.coeffs());
390 template<
typename T1,
typename T2>
391 typename T1::Scalar test_relative_error(
const T1 &a,
const T2 &b,
const typename T1::MatrixType* = 0)
393 return test_relative_error(a.matrix(), b.matrix());
396 template<
typename S,
int D>
399 return test_relative_error(a.vector(), b.vector());
402 template <
typename S,
int D,
int O>
405 return (std::max)(test_relative_error(a.origin(), b.origin()), test_relative_error(a.origin(), b.origin()));
408 template <
typename S,
int D>
411 return (std::max)(test_relative_error((a.
min)(), (b.
min)()), test_relative_error((a.
max)(), (b.
max)()));
415 template<
typename T1,
typename T2>
418 return test_relative_error(a,b.toDense());
422 template<
typename T1,
typename T2>
425 return test_relative_error(a.toDense(),b);
429 template<
typename T1,
typename T2>
432 return test_relative_error(a.toDense(),b.toDense());
435 template<
typename T1,
typename T2>
439 return numext::sqrt(RealScalar(numext::abs2(a-b))/RealScalar((numext::mini)(numext::abs2(a),numext::abs2(b))));
445 return test_relative_error(a.
angle(), b.
angle());
451 return (std::max)(test_relative_error(a.
angle(), b.
angle()), test_relative_error(a.
axis(), b.
axis()));
454 template<
typename Type1,
typename Type2>
455 inline bool test_isApprox(
const Type1& a,
const Type2& b,
typename Type1::Scalar* = 0)
457 return a.isApprox(b, test_precision<typename Type1::Scalar>());
464 return test_precision<typename NumTraits<typename T::Scalar>::Real>();
470 return test_precision<typename NumTraits<T>::Real>();
474 template<
typename Type1,
typename Type2>
475 inline bool verifyIsApprox(
const Type1& a,
const Type2& b)
477 bool ret = test_isApprox(a,b);
480 std::cerr <<
"Difference too large wrt tolerance " << get_test_precision(a) <<
", relative error is: " << test_relative_error(a,b) << std::endl;
492 template<
typename Scalar,
typename ScalarRef>
493 inline bool test_isApproxWithRef(
const Scalar& a,
const Scalar& b,
const ScalarRef& ref)
495 return test_isApprox(a+ref, b+ref);
498 template<
typename Derived1,
typename Derived2>
505 template<
typename Derived>
512 template<
typename Derived>
519 template<
typename T,
typename U>
520 bool test_is_equal(
const T& actual,
const U& expected,
bool expect_equal=
true);
522 template<
typename T,
typename U>
523 bool test_is_equal(
const T& actual,
const U& expected,
bool expect_equal)
525 if ((actual==expected) == expect_equal)
529 <<
"\n actual = " << actual
530 <<
"\n expected " << (expect_equal ?
"= " :
"!=") << expected <<
"\n\n";
540 template<
typename MatrixType>
542 template<
typename MatrixType>
546 enum { Rows = MatrixType::RowsAtCompileTime, Cols = MatrixType::ColsAtCompileTime };
552 if(desired_rank == 0)
558 if(desired_rank == 1)
561 m = VectorType::Random(rows).normalized() * VectorType::Random(cols).normalized().transpose();
565 MatrixAType a = MatrixAType::Random(rows,rows);
566 MatrixType d = MatrixType::Identity(rows,cols);
567 MatrixBType b = MatrixBType::Random(cols,cols);
570 const Index diag_size = (std::min)(d.rows(),d.cols());
571 if(diag_size != desired_rank)
572 d.diagonal().segment(desired_rank, diag_size-desired_rank) = VectorType::Zero(diag_size-desired_rank);
580 template<
typename PermutationVectorType>
581 void randomPermutationVector(PermutationVectorType& v,
Index size);
582 template<
typename PermutationVectorType>
583 void randomPermutationVector(PermutationVectorType& v,
Index size)
585 typedef typename PermutationVectorType::Scalar Scalar;
587 for(
Index i = 0; i < size; ++i) v(i) = Scalar(i);
588 if(size == 1)
return;
589 for(
Index n = 0; n < 3 * size; ++n)
591 Index i = internal::random<Index>(0, size-1);
593 do j = internal::random<Index>(0, size-1);
while(j==i);
594 std::swap(v(i), v(j));
598 template<
typename T>
bool isNotNaN(
const T& x)
603 template<
typename T>
bool isPlusInf(
const T& x)
608 template<
typename T>
bool isMinusInf(
const T& x)
610 return x < NumTraits<T>::lowest();
620 {
typedef std::complex<typename GetDifferentType<T>::type> type; };
623 template<
typename T> std::string type_name();
624 template<
typename T> std::string type_name() {
return "other"; }
625 template<> std::string type_name<float>() {
return "float"; }
626 template<> std::string type_name<double>() {
return "double"; }
627 template<> std::string type_name<long double>() {
return "long double"; }
628 template<> std::string type_name<int>() {
return "int"; }
629 template<> std::string type_name<std::complex<float> >() {
return "complex<float>"; }
630 template<> std::string type_name<std::complex<double> >() {
return "complex<double>"; }
631 template<> std::string type_name<std::complex<long double> >() {
return "complex<long double>"; }
632 template<> std::string type_name<std::complex<int> >() {
return "complex<int>"; }
635 void EIGEN_CAT(test_,EIGEN_TEST_FUNC)();
637 using namespace Eigen;
639 inline void set_repeat_from_string(
const char *str)
642 g_repeat = int(strtoul(str, 0, 10));
643 if(errno || g_repeat <= 0)
645 std::cout <<
"Invalid repeat value " << str << std::endl;
648 g_has_set_repeat =
true;
651 inline void set_seed_from_string(
const char *str)
654 g_seed = int(strtoul(str, 0, 10));
655 if(errno || g_seed == 0)
657 std::cout <<
"Invalid seed value " << str << std::endl;
660 g_has_set_seed =
true;
663 int main(
int argc,
char *argv[])
665 g_has_set_repeat =
false;
666 g_has_set_seed =
false;
667 bool need_help =
false;
669 for(
int i = 1; i < argc; i++)
671 if(argv[i][0] ==
'r')
675 std::cout <<
"Argument " << argv[i] <<
" conflicting with a former argument" << std::endl;
678 set_repeat_from_string(argv[i]+1);
680 else if(argv[i][0] ==
's')
684 std::cout <<
"Argument " << argv[i] <<
" conflicting with a former argument" << std::endl;
687 set_seed_from_string(argv[i]+1);
697 std::cout <<
"This test application takes the following optional arguments:" << std::endl;
698 std::cout <<
" rN Repeat each test N times (default: " << DEFAULT_REPEAT <<
")" << std::endl;
699 std::cout <<
" sN Use N as seed for random numbers (default: based on current time)" << std::endl;
700 std::cout << std::endl;
701 std::cout <<
"If defined, the environment variables EIGEN_REPEAT and EIGEN_SEED" << std::endl;
702 std::cout <<
"will be used as default values for these parameters." << std::endl;
706 char *env_EIGEN_REPEAT = getenv(
"EIGEN_REPEAT");
707 if(!g_has_set_repeat && env_EIGEN_REPEAT)
708 set_repeat_from_string(env_EIGEN_REPEAT);
709 char *env_EIGEN_SEED = getenv(
"EIGEN_SEED");
710 if(!g_has_set_seed && env_EIGEN_SEED)
711 set_seed_from_string(env_EIGEN_SEED);
713 if(!g_has_set_seed) g_seed = (
unsigned int) time(NULL);
714 if(!g_has_set_repeat) g_repeat = DEFAULT_REPEAT;
716 std::cout <<
"Initializing random number generator with seed " << g_seed << std::endl;
717 std::stringstream ss;
718 ss <<
"Seed: " << g_seed;
719 g_test_stack.push_back(ss.str());
721 std::cout <<
"Repeating each test " << g_repeat <<
" times" << std::endl;
723 Eigen::g_test_stack.push_back(std::string(EI_PP_MAKE_STRING(EIGEN_TEST_FUNC)));
725 EIGEN_CAT(test_,EIGEN_TEST_FUNC)();
730 #if defined __INTEL_COMPILER 737 #pragma warning disable 279 383 1418 1572 742 #pragma warning( disable : 4503) EIGEN_DEVICE_FUNC const VectorType &() min() const
Definition: AlignedBox.h:106
bool isUnitary(const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
Definition: Dot.h:298
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:85
Holds information about the various numeric (i.e.
Definition: NumTraits.h:150
Definition: ForwardDeclarations.h:272
Common base class for all classes T such that MatrixBase has an operator=(T) and a constructor Matrix...
Definition: EigenBase.h:28
Definition: ForwardDeclarations.h:271
Base class of any sparse matrices or sparse expressions.
Definition: ForwardDeclarations.h:281
EIGEN_DEVICE_FUNC Scalar angle() const
Definition: AngleAxis.h:91
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:33
HouseholderSequenceType householderQ() const
This method returns an expression of the unitary matrix Q as a sequence of Householder transformation...
Definition: HouseholderQR.h:154
EIGEN_DEVICE_FUNC Derived & setZero(Index size)
Resizes to the given size, and sets all coefficients in this expression to zero.
Definition: CwiseNullaryOp.h:515
EIGEN_DEVICE_FUNC const Vector3 & axis() const
Definition: AngleAxis.h:96
Definition: BandTriangularSolver.h:13
Definition: ForwardDeclarations.h:269
Householder QR decomposition of a matrix.
Definition: ForwardDeclarations.h:254
void createRandomPIMatrixOfRank(Index desired_rank, Index rows, Index cols, MatrixType &m)
Creates a random Partial Isometry matrix of given rank.
Definition: main.h:543
Definition: datatypes.h:12
Generic expression where a coefficient-wise unary operator is applied to an expression.
Definition: CwiseUnaryOp.h:55
EIGEN_DEVICE_FUNC const VectorType &() max() const
Definition: AlignedBox.h:110
EIGEN_DEVICE_FUNC Scalar angle() const
Definition: Rotation2D.h:78
EIGEN_DEVICE_FUNC Derived & derived()
Definition: EigenBase.h:44
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48
Definition: ForwardDeclarations.h:275
Definition: ForwardDeclarations.h:270
Definition: ForwardDeclarations.h:17