17 #ifndef EIGEN_TEST_FUNC 18 #error EIGEN_TEST_FUNC must be defined 21 #define DEFAULT_REPEAT 10 25 static std::vector<std::string> g_test_stack;
29 #define EI_PP_MAKE_STRING2(S) #S 30 #define EI_PP_MAKE_STRING(S) EI_PP_MAKE_STRING2(S) 32 #define EI_PP_CAT2(a,b) a ## b 33 #define EI_PP_CAT(a,b) EI_PP_CAT2(a,b) 35 #ifndef EIGEN_NO_ASSERTION_CHECKING 39 static const bool should_raise_an_assert =
false;
44 static bool no_more_assert =
false;
60 #ifdef EIGEN_DEBUG_ASSERTS 64 static bool ei_push_assert =
false;
65 static std::vector<std::string> eigen_assert_list;
68 #define eigen_assert(a) \ 69 if( (!(a)) && (!no_more_assert) ) \ 71 Eigen::no_more_assert = true; \ 72 throw Eigen::eigen_assert_exception(); \ 74 else if (Eigen::ei_push_assert) \ 76 eigen_assert_list.push_back(std::string(EI_PP_MAKE_STRING(__FILE__)" ("EI_PP_MAKE_STRING(__LINE__)") : "#a) ); \ 79 #define VERIFY_RAISES_ASSERT(a) \ 81 Eigen::no_more_assert = false; \ 83 Eigen::eigen_assert_list.clear(); \ 84 Eigen::ei_push_assert = true; \ 86 Eigen::ei_push_assert = false; \ 87 std::cerr << "One of the following asserts should have been raised:\n"; \ 88 for (uint ai=0 ; ai<eigen_assert_list.size() ; ++ai) \ 89 std::cerr << " " << eigen_assert_list[ai] << "\n"; \ 90 VERIFY(Eigen::should_raise_an_assert && # a); \ 91 } catch (Eigen::eigen_assert_exception e) { \ 92 Eigen::ei_push_assert = false; VERIFY(true); \ 96 #else // EIGEN_DEBUG_ASSERTS 101 #define eigen_assert(a) \ 102 if( (!Eigen::internal::copy_bool(a)) && (!no_more_assert) ) \ 104 Eigen::no_more_assert = true; \ 105 throw Eigen::eigen_assert_exception(); \ 108 #define VERIFY_RAISES_ASSERT(a) { \ 109 Eigen::no_more_assert = false; \ 110 try { a; VERIFY(Eigen::should_raise_an_assert && # a); } \ 111 catch (Eigen::eigen_assert_exception e) { VERIFY(true); } \ 114 #endif // EIGEN_DEBUG_ASSERTS 116 #define EIGEN_USE_CUSTOM_ASSERT 118 #else // EIGEN_NO_ASSERTION_CHECKING 120 #define VERIFY_RAISES_ASSERT(a) {} 122 #endif // EIGEN_NO_ASSERTION_CHECKING 125 #define EIGEN_INTERNAL_DEBUGGING 126 #define EIGEN_NICE_RANDOM 127 #include <Eigen/Array> 130 #define VERIFY(a) do { if (!(a)) { \ 131 std::cerr << "Test " << g_test_stack.back() << " failed in "EI_PP_MAKE_STRING(__FILE__) << " (" << EI_PP_MAKE_STRING(__LINE__) << ")" \ 132 << std::endl << " " << EI_PP_MAKE_STRING(a) << std::endl << std::endl; \ 136 #define VERIFY_IS_APPROX(a, b) VERIFY(test_ei_isApprox(a, b)) 137 #define VERIFY_IS_NOT_APPROX(a, b) VERIFY(!test_ei_isApprox(a, b)) 138 #define VERIFY_IS_MUCH_SMALLER_THAN(a, b) VERIFY(test_ei_isMuchSmallerThan(a, b)) 139 #define VERIFY_IS_NOT_MUCH_SMALLER_THAN(a, b) VERIFY(!test_ei_isMuchSmallerThan(a, b)) 140 #define VERIFY_IS_APPROX_OR_LESS_THAN(a, b) VERIFY(test_ei_isApproxOrLessThan(a, b)) 141 #define VERIFY_IS_NOT_APPROX_OR_LESS_THAN(a, b) VERIFY(!test_ei_isApproxOrLessThan(a, b)) 143 #define CALL_SUBTEST(FUNC) do { \ 144 g_test_stack.push_back(EI_PP_MAKE_STRING(FUNC)); \ 146 g_test_stack.pop_back(); \ 152 template<>
inline int test_precision<int>() {
return 0; }
153 template<>
inline float test_precision<float>() {
return 1e-3f; }
154 template<>
inline double test_precision<double>() {
return 1e-6; }
155 template<>
inline float test_precision<std::complex<float> >() {
return test_precision<float>(); }
156 template<>
inline double test_precision<std::complex<double> >() {
return test_precision<double>(); }
157 template<>
inline long double test_precision<long double>() {
return 1e-6; }
159 inline bool test_ei_isApprox(
const int& a,
const int& b)
160 {
return ei_isApprox(a, b, test_precision<int>()); }
161 inline bool test_ei_isMuchSmallerThan(
const int& a,
const int& b)
162 {
return ei_isMuchSmallerThan(a, b, test_precision<int>()); }
163 inline bool test_ei_isApproxOrLessThan(
const int& a,
const int& b)
164 {
return ei_isApproxOrLessThan(a, b, test_precision<int>()); }
166 inline bool test_ei_isApprox(
const float& a,
const float& b)
167 {
return ei_isApprox(a, b, test_precision<float>()); }
168 inline bool test_ei_isMuchSmallerThan(
const float& a,
const float& b)
169 {
return ei_isMuchSmallerThan(a, b, test_precision<float>()); }
170 inline bool test_ei_isApproxOrLessThan(
const float& a,
const float& b)
171 {
return ei_isApproxOrLessThan(a, b, test_precision<float>()); }
173 inline bool test_ei_isApprox(
const double& a,
const double& b)
174 {
return ei_isApprox(a, b, test_precision<double>()); }
175 inline bool test_ei_isMuchSmallerThan(
const double& a,
const double& b)
176 {
return ei_isMuchSmallerThan(a, b, test_precision<double>()); }
177 inline bool test_ei_isApproxOrLessThan(
const double& a,
const double& b)
178 {
return ei_isApproxOrLessThan(a, b, test_precision<double>()); }
180 inline bool test_ei_isApprox(
const std::complex<float>& a,
const std::complex<float>& b)
181 {
return ei_isApprox(a, b, test_precision<std::complex<float> >()); }
182 inline bool test_ei_isMuchSmallerThan(
const std::complex<float>& a,
const std::complex<float>& b)
183 {
return ei_isMuchSmallerThan(a, b, test_precision<std::complex<float> >()); }
185 inline bool test_ei_isApprox(
const std::complex<double>& a,
const std::complex<double>& b)
186 {
return ei_isApprox(a, b, test_precision<std::complex<double> >()); }
187 inline bool test_ei_isMuchSmallerThan(
const std::complex<double>& a,
const std::complex<double>& b)
188 {
return ei_isMuchSmallerThan(a, b, test_precision<std::complex<double> >()); }
190 inline bool test_ei_isApprox(
const long double& a,
const long double& b)
191 {
return ei_isApprox(a, b, test_precision<long double>()); }
192 inline bool test_ei_isMuchSmallerThan(
const long double& a,
const long double& b)
193 {
return ei_isMuchSmallerThan(a, b, test_precision<long double>()); }
194 inline bool test_ei_isApproxOrLessThan(
const long double& a,
const long double& b)
195 {
return ei_isApproxOrLessThan(a, b, test_precision<long double>()); }
197 template<
typename Type1,
typename Type2>
198 inline bool test_ei_isApprox(
const Type1& a,
const Type2& b)
200 return a.isApprox(b, test_precision<typename Type1::Scalar>());
203 template<
typename Derived1,
typename Derived2>
210 template<
typename Derived>
224 {
typedef std::complex<typename GetDifferentType<T>::type> type; };
227 void EI_PP_CAT(test_,EIGEN_TEST_FUNC)();
229 using namespace Eigen;
231 #ifdef EIGEN_TEST_PART_1 232 #define CALL_SUBTEST_1(FUNC) CALL_SUBTEST(FUNC) 234 #define CALL_SUBTEST_1(FUNC) 237 #ifdef EIGEN_TEST_PART_2 238 #define CALL_SUBTEST_2(FUNC) CALL_SUBTEST(FUNC) 240 #define CALL_SUBTEST_2(FUNC) 243 #ifdef EIGEN_TEST_PART_3 244 #define CALL_SUBTEST_3(FUNC) CALL_SUBTEST(FUNC) 246 #define CALL_SUBTEST_3(FUNC) 249 #ifdef EIGEN_TEST_PART_4 250 #define CALL_SUBTEST_4(FUNC) CALL_SUBTEST(FUNC) 252 #define CALL_SUBTEST_4(FUNC) 255 #ifdef EIGEN_TEST_PART_5 256 #define CALL_SUBTEST_5(FUNC) CALL_SUBTEST(FUNC) 258 #define CALL_SUBTEST_5(FUNC) 261 #ifdef EIGEN_TEST_PART_6 262 #define CALL_SUBTEST_6(FUNC) CALL_SUBTEST(FUNC) 264 #define CALL_SUBTEST_6(FUNC) 267 #ifdef EIGEN_TEST_PART_7 268 #define CALL_SUBTEST_7(FUNC) CALL_SUBTEST(FUNC) 270 #define CALL_SUBTEST_7(FUNC) 273 #ifdef EIGEN_TEST_PART_8 274 #define CALL_SUBTEST_8(FUNC) CALL_SUBTEST(FUNC) 276 #define CALL_SUBTEST_8(FUNC) 279 #ifdef EIGEN_TEST_PART_9 280 #define CALL_SUBTEST_9(FUNC) CALL_SUBTEST(FUNC) 282 #define CALL_SUBTEST_9(FUNC) 285 #ifdef EIGEN_TEST_PART_10 286 #define CALL_SUBTEST_10(FUNC) CALL_SUBTEST(FUNC) 288 #define CALL_SUBTEST_10(FUNC) 291 #ifdef EIGEN_TEST_PART_11 292 #define CALL_SUBTEST_11(FUNC) CALL_SUBTEST(FUNC) 294 #define CALL_SUBTEST_11(FUNC) 297 #ifdef EIGEN_TEST_PART_12 298 #define CALL_SUBTEST_12(FUNC) CALL_SUBTEST(FUNC) 300 #define CALL_SUBTEST_12(FUNC) 303 #ifdef EIGEN_TEST_PART_13 304 #define CALL_SUBTEST_13(FUNC) CALL_SUBTEST(FUNC) 306 #define CALL_SUBTEST_13(FUNC) 309 #ifdef EIGEN_TEST_PART_14 310 #define CALL_SUBTEST_14(FUNC) CALL_SUBTEST(FUNC) 312 #define CALL_SUBTEST_14(FUNC) 315 #ifdef EIGEN_TEST_PART_15 316 #define CALL_SUBTEST_15(FUNC) CALL_SUBTEST(FUNC) 318 #define CALL_SUBTEST_15(FUNC) 321 #ifdef EIGEN_TEST_PART_16 322 #define CALL_SUBTEST_16(FUNC) CALL_SUBTEST(FUNC) 324 #define CALL_SUBTEST_16(FUNC) 329 int main(
int argc,
char *argv[])
331 bool has_set_repeat =
false;
332 bool has_set_seed =
false;
333 bool need_help =
false;
334 unsigned int seed = 0;
335 int repeat = DEFAULT_REPEAT;
337 for(
int i = 1; i < argc; i++)
339 if(argv[i][0] ==
'r')
343 std::cout <<
"Argument " << argv[i] <<
" conflicting with a former argument" << std::endl;
346 repeat = std::atoi(argv[i]+1);
347 has_set_repeat =
true;
350 std::cout <<
"Invalid \'repeat\' value " << argv[i]+1 << std::endl;
354 else if(argv[i][0] ==
's')
358 std::cout <<
"Argument " << argv[i] <<
" conflicting with a former argument" << std::endl;
361 seed = int(std::strtoul(argv[i]+1, 0, 10));
366 std::cout <<
"Invalid \'seed\' value " << argv[i]+1 << std::endl;
378 std::cout <<
"This test application takes the following optional arguments:" << std::endl;
379 std::cout <<
" rN Repeat each test N times (default: " << DEFAULT_REPEAT <<
")" << std::endl;
380 std::cout <<
" sN Use N as seed for random numbers (default: based on current time)" << std::endl;
384 if(!has_set_seed) seed = (
unsigned int) std::time(NULL);
385 if(!has_set_repeat) repeat = DEFAULT_REPEAT;
387 std::cout <<
"Initializing random number generator with seed " << seed << std::endl;
389 std::cout <<
"Repeating each test " << repeat <<
" times" << std::endl;
391 Eigen::g_repeat = repeat;
392 Eigen::g_test_stack.push_back(EI_PP_MAKE_STRING(EIGEN_TEST_FUNC));
394 EI_PP_CAT(test_,EIGEN_TEST_FUNC)();
iterative scaling algorithm to equilibrate rows and column norms in matrices
Definition: TestIMU_Common.h:87
Definition: TypeSafeIdHash.h:44
Holds information about the various numeric (i.e.
Definition: NumTraits.h:88
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48