46 #if __cplusplus >= 201103L 48 #ifdef EIGEN_USE_THREADS 54 #if defined(__CUDACC_VER_MAJOR__) && (__CUDACC_VER_MAJOR__ >= 9) 55 #define EIGEN_TEST_CUDACC_VER ((__CUDACC_VER_MAJOR__ * 10000) + (__CUDACC_VER_MINOR__ * 100)) 56 #elif defined(__CUDACC_VER__) 57 #define EIGEN_TEST_CUDACC_VER __CUDACC_VER__ 59 #define EIGEN_TEST_CUDACC_VER 0 62 #if EIGEN_TEST_CUDACC_VER >= 70500 63 #include <cuda_fp16.h> 70 #define min(A,B) please_protect_your_min_with_parentheses 71 #define max(A,B) please_protect_your_max_with_parentheses 72 #define isnan(X) please_protect_your_isnan_with_parentheses 73 #define isinf(X) please_protect_your_isinf_with_parentheses 74 #define isfinite(X) please_protect_your_isfinite_with_parentheses 78 #define M_PI please_use_EIGEN_PI_instead_of_M_PI 80 #define FORBIDDEN_IDENTIFIER (this_identifier_is_forbidden_to_avoid_clashes) this_identifier_is_forbidden_to_avoid_clashes 82 #define B0 FORBIDDEN_IDENTIFIER 86 #ifndef EIGEN_NO_DEBUG_SMALL_PRODUCT_BLOCKS 87 #define EIGEN_DEBUG_SMALL_PRODUCT_BLOCKS 91 #define TEST_SET_BUT_UNUSED_VARIABLE(X) EIGEN_UNUSED_VARIABLE(X) 93 #ifdef TEST_ENABLE_TEMPORARY_TRACKING 96 static long int nb_temporaries_on_assert = -1;
101 if(nb_temporaries_on_assert>0) assert(
nb_temporaries<nb_temporaries_on_assert);
104 #define EIGEN_DENSE_STORAGE_CTOR_PLUGIN { on_temporary_creation(size); } 106 #define VERIFY_EVALUATION_COUNT(XPR,N) {\ 107 nb_temporaries = 0; \ 109 if(nb_temporaries!=N) { std::cerr << "nb_temporaries == " << nb_temporaries << "\n"; }\ 110 VERIFY( (#XPR) && nb_temporaries==N ); \ 116 #include "split_test_helper.h" 128 #if defined(__ALTIVEC__) || defined(__VSX__) 129 #define EIGEN_MAKING_DOCS 132 #ifndef EIGEN_TEST_FUNC 133 #error EIGEN_TEST_FUNC must be defined 136 #define DEFAULT_REPEAT 10 149 #define TRACK std::cerr << __FILE__ << " " << __LINE__ << std::endl 152 #define EI_PP_MAKE_STRING2(S) #S 153 #define EI_PP_MAKE_STRING(S) EI_PP_MAKE_STRING2(S) 155 #define EIGEN_DEFAULT_IO_FORMAT IOFormat(4, 0, " ", "\n", "", "", "", "") 157 #if (defined(_CPPUNWIND) || defined(__EXCEPTIONS)) && !defined(__CUDA_ARCH__) 158 #define EIGEN_EXCEPTIONS 161 #ifndef EIGEN_NO_ASSERTION_CHECKING 192 #ifdef EIGEN_DEBUG_ASSERTS 198 static bool push_assert =
false;
200 static std::vector<std::string> eigen_assert_list;
202 #define eigen_assert(a) \ 203 if( (!(a)) && (!no_more_assert) ) \ 205 if(report_on_cerr_on_assert_failure) \ 206 std::cerr << #a << " " __FILE__ << "(" << __LINE__ << ")\n"; \ 207 Eigen::no_more_assert = true; \ 208 EIGEN_THROW_X(Eigen::eigen_assert_exception()); \ 210 else if (Eigen::internal::push_assert) \ 212 eigen_assert_list.push_back(std::string(EI_PP_MAKE_STRING(__FILE__) " (" EI_PP_MAKE_STRING(__LINE__) ") : " #a) ); \ 215 #ifdef EIGEN_EXCEPTIONS 216 #define VERIFY_RAISES_ASSERT(a) \ 218 Eigen::no_more_assert = false; \ 219 Eigen::eigen_assert_list.clear(); \ 220 Eigen::internal::push_assert = true; \ 221 Eigen::report_on_cerr_on_assert_failure = false; \ 224 std::cerr << "One of the following asserts should have been triggered:\n"; \ 225 for (uint ai=0 ; ai<eigen_assert_list.size() ; ++ai) \ 226 std::cerr << " " << eigen_assert_list[ai] << "\n"; \ 227 VERIFY(Eigen::should_raise_an_assert && # a); \ 228 } catch (Eigen::eigen_assert_exception) { \ 229 Eigen::internal::push_assert = false; VERIFY(true); \ 231 Eigen::report_on_cerr_on_assert_failure = true; \ 232 Eigen::internal::push_assert = false; \ 234 #endif //EIGEN_EXCEPTIONS 236 #elif !defined(__CUDACC__) // EIGEN_DEBUG_ASSERTS 238 #define eigen_assert(a) \ 239 if( (!Eigen::internal::copy_bool(a)) && (!no_more_assert) )\ 241 Eigen::no_more_assert = true; \ 242 if(report_on_cerr_on_assert_failure) \ 243 eigen_plain_assert(a); \ 245 EIGEN_THROW_X(Eigen::eigen_assert_exception()); \ 248 #ifdef EIGEN_EXCEPTIONS 249 #define VERIFY_RAISES_ASSERT(a) { \ 250 Eigen::no_more_assert = false; \ 251 Eigen::report_on_cerr_on_assert_failure = false; \ 254 VERIFY(Eigen::should_raise_an_assert && # a); \ 256 catch (Eigen::eigen_assert_exception&) { VERIFY(true); } \ 257 Eigen::report_on_cerr_on_assert_failure = true; \ 259 #endif // EIGEN_EXCEPTIONS 260 #endif // EIGEN_DEBUG_ASSERTS 262 #if defined(TEST_CHECK_STATIC_ASSERTIONS) && defined(EIGEN_EXCEPTIONS) 263 #define EIGEN_STATIC_ASSERT(a,MSG) \ 264 if( (!Eigen::internal::copy_bool(a)) && (!no_more_assert) )\ 266 Eigen::no_more_assert = true; \ 267 if(report_on_cerr_on_assert_failure) \ 268 eigen_plain_assert((a) && #MSG); \ 270 EIGEN_THROW_X(Eigen::eigen_static_assert_exception()); \ 272 #define VERIFY_RAISES_STATIC_ASSERT(a) { \ 273 Eigen::no_more_assert = false; \ 274 Eigen::report_on_cerr_on_assert_failure = false; \ 277 VERIFY(Eigen::should_raise_an_assert && # a); \ 279 catch (Eigen::eigen_static_assert_exception&) { VERIFY(true); } \ 280 Eigen::report_on_cerr_on_assert_failure = true; \ 282 #endif // TEST_CHECK_STATIC_ASSERTIONS 284 #ifndef VERIFY_RAISES_ASSERT 285 #define VERIFY_RAISES_ASSERT(a) \ 286 std::cout << "Can't VERIFY_RAISES_ASSERT( " #a " ) with exceptions disabled\n"; 288 #ifndef VERIFY_RAISES_STATIC_ASSERT 289 #define VERIFY_RAISES_STATIC_ASSERT(a) \ 290 std::cout << "Can't VERIFY_RAISES_STATIC_ASSERT( " #a " ) with exceptions disabled\n"; 293 #if !defined(__CUDACC__) 294 #define EIGEN_USE_CUSTOM_ASSERT 297 #else // EIGEN_NO_ASSERTION_CHECKING 299 #define VERIFY_RAISES_ASSERT(a) {} 300 #define VERIFY_RAISES_STATIC_ASSERT(a) {} 302 #endif // EIGEN_NO_ASSERTION_CHECKING 304 #define EIGEN_INTERNAL_DEBUGGING 307 inline void verify_impl(
bool condition,
const char *testname,
const char *
file,
int line,
const char *condition_as_string)
312 std::cerr <<
"WARNING: ";
313 std::cerr <<
"Test " << testname <<
" failed in " << file <<
" (" << line <<
")" 314 << std::endl <<
" " << condition_as_string << std::endl;
315 std::cerr <<
"Stack:\n";
317 for(
int i=test_stack_size-1;
i>=0; --
i)
325 #define VERIFY(a) ::verify_impl(a, g_test_stack.back().c_str(), __FILE__, __LINE__, EI_PP_MAKE_STRING(a)) 327 #define VERIFY_GE(a, b) ::verify_impl(a >= b, g_test_stack.back().c_str(), __FILE__, __LINE__, EI_PP_MAKE_STRING(a >= b)) 328 #define VERIFY_LE(a, b) ::verify_impl(a <= b, g_test_stack.back().c_str(), __FILE__, __LINE__, EI_PP_MAKE_STRING(a <= b)) 331 #define VERIFY_IS_EQUAL(a, b) VERIFY(test_is_equal(a, b, true)) 332 #define VERIFY_IS_NOT_EQUAL(a, b) VERIFY(test_is_equal(a, b, false)) 333 #define VERIFY_IS_APPROX(a, b) VERIFY(verifyIsApprox(a, b)) 334 #define VERIFY_IS_NOT_APPROX(a, b) VERIFY(!test_isApprox(a, b)) 335 #define VERIFY_IS_MUCH_SMALLER_THAN(a, b) VERIFY(test_isMuchSmallerThan(a, b)) 336 #define VERIFY_IS_NOT_MUCH_SMALLER_THAN(a, b) VERIFY(!test_isMuchSmallerThan(a, b)) 337 #define VERIFY_IS_APPROX_OR_LESS_THAN(a, b) VERIFY(test_isApproxOrLessThan(a, b)) 338 #define VERIFY_IS_NOT_APPROX_OR_LESS_THAN(a, b) VERIFY(!test_isApproxOrLessThan(a, b)) 340 #define VERIFY_IS_UNITARY(a) VERIFY(test_isUnitary(a)) 342 #define CALL_SUBTEST(FUNC) do { \ 343 g_test_stack.push_back(EI_PP_MAKE_STRING(FUNC)); \ 345 g_test_stack.pop_back(); \ 391 #ifndef EIGEN_TEST_NO_COMPLEX 397 inline bool test_isApprox(
const std::complex<double>&
a,
const std::complex<double>&
b)
402 #ifndef EIGEN_TEST_NO_LONGDOUBLE 403 inline bool test_isApprox(
const std::complex<long double>&
a,
const std::complex<long double>&
b)
410 #ifndef EIGEN_TEST_NO_LONGDOUBLE 415 << std::endl <<
" actual = " << a
416 << std::endl <<
" expected = " << b << std::endl << std::endl;
424 #endif // EIGEN_TEST_NO_LONGDOUBLE 434 template<
typename T1,
typename T2>
444 template<
typename T1,
typename T2>
450 template<
typename T1,
typename T2>
456 template<
typename S,
int D>
462 template <
typename S,
int D,
int O>
468 template <
typename S,
int D>
475 template<
typename T1,
typename T2>
482 template<
typename T1,
typename T2>
489 template<
typename T1,
typename T2>
495 template<
typename T1,
typename T2>
514 template<
typename Type1,
typename Type2>
517 return a.isApprox(b, test_precision<typename Type1::Scalar>());
534 template<
typename Type1,
typename Type2>
552 template<
typename Scalar,
typename ScalarRef>
558 template<
typename Derived1,
typename Derived2>
565 template<
typename Derived>
572 template<
typename Derived>
579 template<
typename T,
typename U>
582 template<
typename T,
typename U>
585 if ((actual==expected) == expect_equal)
589 <<
"\n actual = " << actual
590 <<
"\n expected " << (expect_equal ?
"= " :
"!=") << expected <<
"\n\n";
600 template<
typename MatrixType>
602 template<
typename MatrixType>
606 enum { Rows = MatrixType::RowsAtCompileTime,
Cols = MatrixType::ColsAtCompileTime };
612 if(desired_rank == 0)
618 if(desired_rank == 1)
621 m = VectorType::Random(rows).normalized() * VectorType::Random(cols).normalized().transpose();
625 MatrixAType
a = MatrixAType::Random(rows,rows);
627 MatrixBType
b = MatrixBType::Random(cols,cols);
631 if(diag_size != desired_rank)
632 d.diagonal().segment(desired_rank, diag_size-desired_rank) = VectorType::Zero(diag_size-desired_rank);
640 template<
typename PermutationVectorType>
642 template<
typename PermutationVectorType>
648 if(size == 1)
return;
651 Index i = internal::random<Index>(0, size-1);
653 do j = internal::random<Index>(0, size-1);
while(j==i);
670 return x < NumTraits<T>::lowest();
683 template<
typename T> std::string
type_name();
684 template<
typename T> std::string
type_name() {
return "other"; }
689 template<> std::string type_name<std::complex<float> >() {
return "complex<float>"; }
690 template<> std::string type_name<std::complex<double> >() {
return "complex<double>"; }
691 template<> std::string type_name<std::complex<long double> >() {
return "complex<long double>"; }
692 template<> std::string type_name<std::complex<int> >() {
return "complex<int>"; }
697 using namespace Eigen;
705 std::cout <<
"Invalid repeat value " << str << std::endl;
717 std::cout <<
"Invalid seed value " << str << std::endl;
723 int main(
int argc,
char *argv[])
727 bool need_help =
false;
729 for(
int i = 1;
i < argc;
i++)
731 if(argv[
i][0] ==
'r')
735 std::cout <<
"Argument " << argv[
i] <<
" conflicting with a former argument" << std::endl;
740 else if(argv[
i][0] ==
's')
744 std::cout <<
"Argument " << argv[
i] <<
" conflicting with a former argument" << std::endl;
757 std::cout <<
"This test application takes the following optional arguments:" << std::endl;
758 std::cout <<
" rN Repeat each test N times (default: " <<
DEFAULT_REPEAT <<
")" << std::endl;
759 std::cout <<
" sN Use N as seed for random numbers (default: based on current time)" << std::endl;
760 std::cout << std::endl;
761 std::cout <<
"If defined, the environment variables EIGEN_REPEAT and EIGEN_SEED" << std::endl;
762 std::cout <<
"will be used as default values for these parameters." << std::endl;
766 char *env_EIGEN_REPEAT = getenv(
"EIGEN_REPEAT");
769 char *env_EIGEN_SEED = getenv(
"EIGEN_SEED");
776 std::cout <<
"Initializing random number generator with seed " <<
g_seed << std::endl;
777 std::stringstream
ss;
781 std::cout <<
"Repeating each test " <<
g_repeat <<
" times" << std::endl;
790 #if defined __INTEL_COMPILER 797 #pragma warning disable 279 383 1418 1572 802 #pragma warning( disable : 4503)
EIGEN_DEVICE_FUNC Scalar angle() const
EIGEN_DEVICE_FUNC bool isMuchSmallerThan(const RealScalar &other, const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
long double test_precision< long double >()
HouseholderSequenceType householderQ() const
EIGEN_DEVICE_FUNC bool isMuchSmallerThan(const Scalar &x, const OtherScalar &y, const typename NumTraits< Scalar >::Real &precision=NumTraits< Scalar >::dummy_precision())
EIGEN_DEVICE_FUNC Derived & setZero(Index size)
bool test_isApprox(const short &a, const short &b)
eigen_static_assert_exception(void)
NumTraits< typename T::Scalar >::Real get_test_precision(const T &, const typename T::Scalar *=0)
double test_precision< double >()
std::complex< typename GetDifferentType< T >::type > type
EIGEN_DEVICE_FUNC const VectorType &() max() const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const CwiseAbs2ReturnType cwiseAbs2() const
static bool report_on_cerr_on_assert_failure
bool isNotNaN(const T &x)
EIGEN_DEVICE_FUNC const SqrtReturnType sqrt() const
Namespace containing all symbols from the Eigen library.
Pose2 T2(M_PI/2.0, Point2(0.0, 2.0))
EIGEN_DEVICE_FUNC const VectorType & vector() const
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
bool test_isMuchSmallerThan(const int &a, const int &b)
int main(int argc, char *argv[])
void verify_impl(bool condition, const char *testname, const char *file, int line, const char *condition_as_string)
void randomPermutationVector(PermutationVectorType &v, Index size)
static long int nb_temporaries
~eigen_static_assert_exception()
EIGEN_DEVICE_FUNC const Vector3 & axis() const
void on_temporary_creation()
Represents a translation transformation.
EIGEN_DEVICE_FUNC Scalar angle() const
void set_seed_from_string(const char *str)
static bool g_has_set_seed
static const Line3 l(Rot3(), 1, 1)
Base class of any sparse matrices or sparse expressions.
bool test_isApproxWithRef(const Scalar &a, const Scalar &b, const ScalarRef &ref)
float test_precision< float >()
static bool g_has_set_repeat
bool test_isUnitary(const MatrixBase< Derived > &m)
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
std::string type_name< double >()
eigen_assert_exception(void)
Array< double, 1, 3 > e(1./3., 0.5, 2.)
const mpreal sum(const mpreal tab[], const unsigned long int n, int &status, mp_rnd_t mode=mpreal::get_default_rnd())
NumTraits< Scalar >::Real RealScalar
#define EI_PP_MAKE_STRING(S)
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE T mini(const T &x, const T &y)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Abs2ReturnType abs2() const
static std::stringstream ss
void EIGEN_CAT(test_, EIGEN_TEST_FUNC)()
std::string type_name< float >()
EIGEN_DEVICE_FUNC const VectorType &() min() const
mp::number< mp::cpp_dec_float< 100 >, mp::et_on > Real
Represents a rotation/orientation in a 2 dimensional space.
static bool no_more_assert
bool isUnitary(const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
bool test_isApproxOrLessThan(const int &a, const int &b)
NumTraits< T >::Real test_precision()
bool isPlusInf(const T &x)
EIGEN_DEVICE_FUNC const VectorType & origin() const
static const bool should_raise_an_assert
Householder QR decomposition of a matrix.
void set_repeat_from_string(const char *str)
bool isMinusInf(const T &x)
NumTraits< typename T1::RealScalar >::NonInteger test_relative_error(const EigenBase< T1 > &a, const EigenBase< T2 > &b)
bool verifyIsApprox(const Type1 &a, const Type2 &b)
DenseMatrixType toDense() const
void createRandomPIMatrixOfRank(Index desired_rank, Index rows, Index cols, MatrixType &m)
Pose2 T1(M_PI/4.0, Point2(sqrt(0.5), sqrt(0.5)))
EIGEN_DEVICE_FUNC bool isApprox(const Scalar &x, const Scalar &y, const typename NumTraits< Scalar >::Real &precision=NumTraits< Scalar >::dummy_precision())
EIGEN_DEVICE_FUNC bool isApproxOrLessThan(const Scalar &x, const Scalar &y, const typename NumTraits< Scalar >::Real &precision=NumTraits< Scalar >::dummy_precision())
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE float sqrt(const float &x)
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x
~eigen_assert_exception()
EIGEN_DEVICE_FUNC Derived & derived()
Base class for all dense matrices, vectors, and expressions.
Represents a 3D rotation as a rotation angle around an arbitrary 3D axis.
void swap(mpfr::mpreal &x, mpfr::mpreal &y)
std::string type_name< int >()
std::string type_name< long double >()
static std::vector< std::string > g_test_stack
static unsigned int g_seed
bool test_is_equal(const T &actual, const U &expected, bool expect_equal=true)