1 /**
2 * \file util.hpp
3 *
4 * \brief Utility macros/functions for testing and debugging purpose.
5 *
6 * Basic usage:
7 * <pre>
8 * BOOST_UBLAS_TEST_DEF( test_case_1 )
9 * {
10 * // do your test stuff
11 * }
12 *
13 * BOOST_UBLAS_TEST_DEF( test_case_2 )
14 * {
15 * // do your test stuff
16 * }
17 *
18 * // ...
19 *
20 * BOOST_UBLAS_TEST_DEF( test_case_n )
21 * {
22 * // do your test stuff
23 * }
24 *
25 * int main()
26 * {
27 * BOOST_UBLAS_TEST_SUITE( "My Test Suite" ); // optional
28 *
29 * BOOST_UBLAS_TEST_BEGIN();
30 * BOOST_UBLAS_TEST_DO( test_case_1 );
31 * BOOST_UBLAS_TEST_DO( test_case_2 );
32 * // ...
33 * BOOST_UBLAS_TEST_DO( test_case_n );
34 * BOOST_UBLAS_TEST_END();
35 * }
36 * </pre>
37 * Inside each <em>test_case_<code>k</code></em> you can use the various
38 * \c BOOST_UBLAS_TEST_CHECK* macros.
39 *
40 * <hr/>
41 *
42 * Copyright (c) 2009-2012, Marco Guazzone
43 *
44 * Distributed under the Boost Software License, Version 1.0. (See
45 * accompanying file LICENSE_1_0.txt or copy at
46 * http://www.boost.org/LICENSE_1_0.txt)
47 *
48 * \author Marco Guazzone, marco.guazzone@gmail.com
49 */
50
51 #ifndef BOOST_NUMERIC_UBLAS_TEST_UTILS_HPP
52 #define BOOST_NUMERIC_UBLAS_TEST_UTILS_HPP
53
54
55 #include <boost/numeric/ublas/detail/config.hpp>
56 #include <boost/numeric/ublas/traits.hpp>
57
58 #include <boost/math/special_functions/fpclassify.hpp> // isnan, isinf
59
60 #include <cmath>
61 #include <complex>
62 #include <cstddef>
63 #include <iostream>
64 #include <limits>
65 #include <stdexcept>
66
67 #define BOOST_UBLAS_NOT_USED(x) (void)(x)
68
69 namespace boost { namespace numeric { namespace ublas { namespace test { namespace detail { namespace /*<unnamed>*/ {
70
71 using ::std::abs;
72 using ::std::max;
73
74 /// Check if the given complex number is a NaN.
75 // read the comments in fpclassify as well
76 template <typename T>
77 BOOST_UBLAS_INLINE
78 bool (isnan)(::std::complex<T> const& z)
79 {
80 // According to IEEE, NaN is different even by itself
81 return (z != z) || (boost::math::isnan)(z.real()) || (boost::math::isnan)(z.imag());
82 }
83
84 /// Check if two (real) numbers are close each other (wrt a given tolerance).
85 template <typename T1, typename T2, typename T3>
86 BOOST_UBLAS_INLINE
close_to(T1 x,T2 y,T3 tol)87 bool close_to(T1 x, T2 y, T3 tol)
88 {
89 typedef typename promote_traits<typename promote_traits<T1,T2>::promote_type,
90 T3>::promote_type real_type;
91
92 if ((boost::math::isnan)(x) || (boost::math::isnan)(y))
93 {
94 // According to IEEE, NaN is different even by itself
95 return false;
96 }
97 return abs(x-y) <= (max(static_cast<real_type>(abs(x)), static_cast<real_type>(abs(y)))*tol);
98 }
99
100 /// Check if two complex numbers are close each other (wrt a given tolerance).
101 template <typename T1, typename T2, typename T3>
102 BOOST_UBLAS_INLINE
close_to(::std::complex<T1> const & x,::std::complex<T2> const & y,T3 tol)103 bool close_to(::std::complex<T1> const& x, ::std::complex<T2> const& y, T3 tol)
104 {
105 typedef typename promote_traits<typename promote_traits<T1,T2>::promote_type,
106 T3>::promote_type real_type;
107
108 if ((isnan)(x) || (isnan)(y))
109 {
110 // According to IEEE, NaN is different even by itself
111 return false;
112 }
113 ::std::complex<real_type> xx(x);
114 ::std::complex<real_type> yy(y);
115
116 return abs(xx-yy) <= (max(abs(xx), abs(yy))*tol);
117 }
118
119 /// Check if two (real) numbers are close each other (wrt a given tolerance).
120 template <typename T1, typename T2, typename T3>
121 BOOST_UBLAS_INLINE
rel_close_to(T1 x,T2 y,T3 tol)122 bool rel_close_to(T1 x, T2 y, T3 tol)
123 {
124 //typedef typename promote_traits<typename promote_traits<T1,T2>::promote_type,
125 // T3>::promote_type real_type;
126
127 if ((boost::math::isnan)(x) || (boost::math::isnan)(y))
128 {
129 // According to IEEE, NaN is different even by itself
130 return false;
131 }
132 return abs(x-y)/abs(y) <= tol;
133 }
134
135 /// Check if two complex numbers are close each other (wrt a given tolerance).
136 template <typename T1, typename T2, typename T3>
137 BOOST_UBLAS_INLINE
rel_close_to(::std::complex<T1> const & x,::std::complex<T2> const & y,T3 tol)138 bool rel_close_to(::std::complex<T1> const& x, ::std::complex<T2> const& y, T3 tol)
139 {
140 typedef typename promote_traits<typename promote_traits<T1,T2>::promote_type,
141 T3>::promote_type real_type;
142
143 if ((isnan)(x) || (isnan)(y))
144 {
145 // According to IEEE, NaN is different even by itself
146 return false;
147 }
148 ::std::complex<real_type> xx(x);
149 ::std::complex<real_type> yy(y);
150
151 return abs(xx-yy)/abs(yy) <= tol;
152 }
153
154 }}}}}} // Namespace boost::numeric::ublas::test::detail::<unnamed>
155
156
157 /// Expand its argument \a x.
158 #define BOOST_UBLAS_TEST_EXPAND_(x) x
159
160
161 /// Expand its argument \a x inside parenthesis.
162 #define BOOST_UBLAS_TEST_EXPANDP_(x) (x)
163
164
165 /// Transform its argument \a x into a string.
166 #define BOOST_UBLAS_TEST_STRINGIFY_(x) #x
167
168
169 /// Concatenate its two \e string arguments \a x and \a y.
170 #define BOOST_UBLAS_TEST_JOIN_(x,y) x ## y
171
172
173 /// Output the message \a x if in debug-mode; otherwise output nothing.
174 /// Note: we don't use macro expansion inside parenthesis to let \a m be an
175 /// expression of the form <code>a << b</code>.
176 #ifndef NDEBUG
177 # define BOOST_UBLAS_DEBUG_TRACE(x) ::std::cerr << "[Debug>> " << BOOST_UBLAS_TEST_EXPAND_(x) << ::std::endl
178 #else
179 # define BOOST_UBLAS_DEBUG_TRACE(x) /**/
180 #endif // NDEBUG
181
182
183 /// Define the name \a m of the entire test suite.
184 #define BOOST_UBLAS_TEST_SUITE(m) ::std::cerr << "--- Test Suite: " << BOOST_UBLAS_TEST_EXPAND_(m) << " ---" << ::std::endl;
185
186
187 /// Define the beginning of a test suite.
188 #define BOOST_UBLAS_TEST_BEGIN() /* [BOOST_UBLAS_TEST_BEGIN] */ \
189 { \
190 /* Begin of Test Suite */ \
191 ::std::size_t test_fails__(0) \
192 /* [/BOOST_UBLAS_TEST_BEGIN] */
193
194
195 /// Define a test case \a x inside the current test suite.
196 #define BOOST_UBLAS_TEST_DEF(x) static void BOOST_UBLAS_TEST_EXPAND_(x)(::std::size_t& test_fails__)
197
198
199 /// Call the test case \a x.
200 #define BOOST_UBLAS_TEST_DO(x) /* [BOOST_UBLAS_TEST_DO] */ \
201 try \
202 { \
203 BOOST_UBLAS_TEST_EXPAND_(x)(test_fails__); \
204 } \
205 catch (::std::exception& e) \
206 { \
207 ++test_fails__; \
208 BOOST_UBLAS_TEST_ERROR( e.what() ); \
209 } \
210 catch (...) \
211 { \
212 ++test_fails__; \
213 } \
214 /* [/BOOST_UBLAS_TEST_DO] */
215
216
217 /// Define the end of a test suite and return non-zero value if any test failed.
218 #define BOOST_UBLAS_TEST_END() /* [BOOST_UBLAS_TEST_END] */ \
219 if (test_fails__ > 0) \
220 { \
221 ::std::cerr << "Number of failed tests: " << test_fails__ << ::std::endl; \
222 return EXIT_FAILURE; \
223 } \
224 else \
225 { \
226 ::std::cerr << "No failed test" << ::std::endl; \
227 return EXIT_SUCCESS; \
228 } \
229 } /* End of test suite */ \
230 /* [/BOOST_UBLAS_TEST_END] */
231
232
233 /// Output the message \a m.
234 /// Note: we don't use macro expansion inside parenthesis to let \a m be an
235 /// expression of the form <code>a << b</code>.
236 #define BOOST_UBLAS_TEST_TRACE(m) ::std::cerr << "[Info>> " << BOOST_UBLAS_TEST_EXPAND_(m) << ::std::endl
237
238
239 /// Check the truth of assertion \a x.
240 #define BOOST_UBLAS_TEST_CHECK(x) /* [BOOST_UBLAS_TEST_CHECK] */ \
241 if (!BOOST_UBLAS_TEST_EXPANDP_(x)) \
242 { \
243 BOOST_UBLAS_TEST_ERROR( "Failed assertion: " << BOOST_UBLAS_TEST_STRINGIFY_(x) ); \
244 ++test_fails__; \
245 } \
246 /* [/BOOST_UBLAS_TEST_CHECK] */
247
248
249 /// Check for the equality of \a x against \a y.
250 #define BOOST_UBLAS_TEST_CHECK_EQ(x,y) /* [BOOST_UBLAS_TEST_CHECK_EQUAL] */ \
251 if (!(BOOST_UBLAS_TEST_EXPANDP_(x) == BOOST_UBLAS_TEST_EXPANDP_(y))) \
252 { \
253 BOOST_UBLAS_TEST_ERROR( "Failed assertion: (" << BOOST_UBLAS_TEST_STRINGIFY_(x) << " == " << BOOST_UBLAS_TEST_STRINGIFY_(y) << ")" ); \
254 ++test_fails__; \
255 } \
256 /* [/BOOST_UBLAS_TEST_CHECK_EQUAL] */
257
258
259 /// Alias for macro \c BOOST_UBLAS_TEST_CHECK_EQ (for backward compatibility).
260 #define BOOST_UBLAS_TEST_CHECK_EQUAL(x,y) BOOST_UBLAS_TEST_CHECK_EQ(x,y)
261
262
263 /// Check that \a x and \a y are close with respect to a given precision \a e.
264 #define BOOST_UBLAS_TEST_CHECK_CLOSE(x,y,e) /* [BOOST_UBLAS_TEST_CHECK_CLOSE] */ \
265 if (!::boost::numeric::ublas::test::detail::close_to(BOOST_UBLAS_TEST_EXPAND_(x), BOOST_UBLAS_TEST_EXPAND_(y), BOOST_UBLAS_TEST_EXPAND_(e))) \
266 { \
267 BOOST_UBLAS_TEST_ERROR( "Failed assertion: abs(" << BOOST_UBLAS_TEST_STRINGIFY_(x) << "-" << BOOST_UBLAS_TEST_STRINGIFY_(y) << ") <= " << BOOST_UBLAS_TEST_STRINGIFY_(e) << " [with " << BOOST_UBLAS_TEST_STRINGIFY_(x) << " == " << BOOST_UBLAS_TEST_EXPANDP_(x) << ", " << BOOST_UBLAS_TEST_STRINGIFY_(y) << " == " << BOOST_UBLAS_TEST_EXPANDP_(y) << " and " << BOOST_UBLAS_TEST_STRINGIFY_(e) << " == " << BOOST_UBLAS_TEST_EXPANDP_(e) << "]" ); \
268 ++test_fails__; \
269 } \
270 /* [/BOOST_UBLAS_TEST_CHECK_CLOSE] */
271
272
273 /// Alias for macro \c BOOST_UBLAS_TEST_CHECK_CLOSE (for backward compatibility),
274 #define BOOST_UBLAS_TEST_CHECK_PRECISION(x,y,e) BOOST_UBLAS_TEST_CHECK_CLOSE(x,y,e)
275
276
277 /// Check that \a x is close to \a y with respect to a given relative precision \a e.
278 #define BOOST_UBLAS_TEST_CHECK_REL_CLOSE(x,y,e) /* [BOOST_UBLAS_TEST_CHECK_REL_CLOSE] */ \
279 if (!::boost::numeric::ublas::test::detail::rel_close_to(BOOST_UBLAS_TEST_EXPAND_(x), BOOST_UBLAS_TEST_EXPAND_(y), BOOST_UBLAS_TEST_EXPAND_(e))) \
280 { \
281 BOOST_UBLAS_TEST_ERROR( "Failed assertion: abs((" << BOOST_UBLAS_TEST_STRINGIFY_(x) << "-" << BOOST_UBLAS_TEST_STRINGIFY_(y) << ")/" << BOOST_UBLAS_TEST_STRINGIFY_(y) << ") <= " << BOOST_UBLAS_TEST_STRINGIFY_(e) << " [with " << BOOST_UBLAS_TEST_STRINGIFY_(x) << " == " << BOOST_UBLAS_TEST_EXPANDP_(x) << ", " << BOOST_UBLAS_TEST_STRINGIFY_(y) << " == " << BOOST_UBLAS_TEST_EXPANDP_(y) << " and " << BOOST_UBLAS_TEST_STRINGIFY_(e) << " == " << BOOST_UBLAS_TEST_EXPANDP_(e) << "]" ); \
282 ++test_fails__; \
283 } \
284 /* [/BOOST_UBLAS_TEST_CHECK_REL_CLOSE] */
285
286
287 /// Alias for macro \c BOOST_UBLAS_TEST_CHECK_REL_CLOSE (for backward compatibility),
288 #define BOOST_UBLAS_TEST_CHECK_REL_PRECISION(x,y,e) BOOST_UBLAS_TEST_CHECK_REL_CLOSE(x,y,e)
289
290
291 /// Check that elements of \a x and \a y are equal.
292 #define BOOST_UBLAS_TEST_CHECK_VECTOR_EQ(x,y,n) /* [BOOST_UBLAS_TEST_CHECK_VECTOR_EQ] */ \
293 if (BOOST_UBLAS_TEST_EXPANDP_(n) > 0) \
294 { \
295 ::std::size_t n__ = BOOST_UBLAS_TEST_EXPAND_(n); \
296 for (::std::size_t i__ = n__; i__ > 0; --i__) \
297 { \
298 if (!(BOOST_UBLAS_TEST_EXPANDP_(x)[n__-i__]==BOOST_UBLAS_TEST_EXPANDP_(y)[n__-i__])) \
299 { \
300 BOOST_UBLAS_TEST_ERROR( "Failed assertion: (" << BOOST_UBLAS_TEST_STRINGIFY_(x[i__]) << "==" << BOOST_UBLAS_TEST_STRINGIFY_(y[i__]) << ")" << " [with " << BOOST_UBLAS_TEST_STRINGIFY_(x[i__]) << " == " << BOOST_UBLAS_TEST_EXPANDP_(x)[n__-i__] << ", " << BOOST_UBLAS_TEST_STRINGIFY_(y[i__]) << " == " << BOOST_UBLAS_TEST_EXPANDP_(y)[n__-i__] << ", " << BOOST_UBLAS_TEST_STRINGIFY_(i__) << " == " << i__ << " and " << BOOST_UBLAS_TEST_STRINGIFY_(n) << " == " << n__ << "]" ); \
301 ++test_fails__; \
302 } \
303 } \
304 } \
305 /* [/BOOST_UBLAS_TEST_CHECK_VECTOR_EQ] */
306
307
308 /// Check that elements of \a x and \a y are close with respect to a given precision \a e.
309 #define BOOST_UBLAS_TEST_CHECK_VECTOR_CLOSE(x,y,n,e) /* [BOOST_UBLAS_TEST_CHECK_VECTOR_CLOSE] */ \
310 if (BOOST_UBLAS_TEST_EXPANDP_(n) > 0) \
311 { \
312 ::std::size_t n__ = BOOST_UBLAS_TEST_EXPAND_(n); \
313 for (::std::size_t i__ = n__; i__ > 0; --i__) \
314 { \
315 if (!::boost::numeric::ublas::test::detail::close_to(BOOST_UBLAS_TEST_EXPANDP_(x)[n__-i__], BOOST_UBLAS_TEST_EXPANDP_(y)[n__-i__], BOOST_UBLAS_TEST_EXPANDP_(e))) \
316 { \
317 BOOST_UBLAS_TEST_ERROR( "Failed assertion: abs((" << BOOST_UBLAS_TEST_STRINGIFY_(x[i__]) << "-" << BOOST_UBLAS_TEST_STRINGIFY_(y[i__]) << ") <= " << BOOST_UBLAS_TEST_STRINGIFY_(e) << " [with " << BOOST_UBLAS_TEST_STRINGIFY_(x[i__]) << " == " << BOOST_UBLAS_TEST_EXPANDP_(x)[n__-i__] << ", " << BOOST_UBLAS_TEST_STRINGIFY_(y[i__]) << " == " << BOOST_UBLAS_TEST_EXPANDP_(y)[n__-i__] << ", " << BOOST_UBLAS_TEST_STRINGIFY_(i__) << " == " << i__ << " and " << BOOST_UBLAS_TEST_STRINGIFY_(n) << " == " << n__ << "]" ); \
318 ++test_fails__; \
319 } \
320 } \
321 } \
322 /* [/BOOST_UBLAS_TEST_CHECK_VECTOR_CLOSE] */
323
324
325 /// Check that elements of \a x and \a y are close with respect to a given relative precision \a e.
326 #define BOOST_UBLAS_TEST_CHECK_VECTOR_REL_CLOSE(x,y,n,e) /* [BOOST_UBLAS_TEST_CHECK_VECTOR_REL_CLOSE] */ \
327 if (BOOST_UBLAS_TEST_EXPANDP_(n) > 0) \
328 { \
329 ::std::size_t n__ = BOOST_UBLAS_TEST_EXPAND_(n); \
330 for (::std::size_t i__ = n__; i__ > 0; --i__) \
331 { \
332 if (!::boost::numeric::ublas::test::detail::rel_close_to(BOOST_UBLAS_TEST_EXPANDP_(x)[n__-i__], BOOST_UBLAS_TEST_EXPANDP_(y)[n__-i__], BOOST_UBLAS_TEST_EXPANDP_(e))) \
333 { \
334 BOOST_UBLAS_TEST_ERROR( "Failed assertion: abs((" << BOOST_UBLAS_TEST_STRINGIFY_(x[i__]) << "-" << BOOST_UBLAS_TEST_STRINGIFY_(y[i__]) << ") <= " << BOOST_UBLAS_TEST_STRINGIFY_(e) << " [with " << BOOST_UBLAS_TEST_STRINGIFY_(x[i__]) << " == " << BOOST_UBLAS_TEST_EXPANDP_(x)[n__-i__] << ", " << BOOST_UBLAS_TEST_STRINGIFY_(y[i__]) << " == " << BOOST_UBLAS_TEST_EXPANDP_(y)[n__-i__] << ", " << BOOST_UBLAS_TEST_STRINGIFY_(i__) << " == " << i__ << " and " << BOOST_UBLAS_TEST_STRINGIFY_(n) << " == " << n__ << "]" ); \
335 ++test_fails__; \
336 } \
337 } \
338 } \
339 /* [/BOOST_UBLAS_TEST_CHECK_VECTOR_REL_CLOSE] */
340
341
342 /// Check that elements of matrices \a x and \a y are equal.
343 #define BOOST_UBLAS_TEST_CHECK_MATRIX_EQ(x,y,nr,nc) /* [BOOST_UBLAS_TEST_CHECK_MATRIX_EQ] */ \
344 for (::std::size_t i__ = 0; i__ < BOOST_UBLAS_TEST_EXPANDP_(nr); ++i__) \
345 { \
346 for (::std::size_t j__ = 0; j__ < BOOST_UBLAS_TEST_EXPANDP_(nc); ++j__) \
347 { \
348 if (!(BOOST_UBLAS_TEST_EXPANDP_(x)(i__,j__)==BOOST_UBLAS_TEST_EXPANDP_(y)(i__,j__))) \
349 { \
350 BOOST_UBLAS_TEST_ERROR( "Failed assertion: (" << BOOST_UBLAS_TEST_STRINGIFY_(x(i__,j__)) << " == " << BOOST_UBLAS_TEST_STRINGIFY_(y(i__,j__)) << ") [with " << BOOST_UBLAS_TEST_STRINGIFY_(x(i__,j__)) << " == " << BOOST_UBLAS_TEST_EXPANDP_(x)(i__,j__) << ", " << BOOST_UBLAS_TEST_STRINGIFY_(y(i__,j__)) << " == " << BOOST_UBLAS_TEST_EXPANDP_(y)(i__,j__) << ", " << BOOST_UBLAS_TEST_STRINGIFY_(i__) << " == " << i__ << ", " << BOOST_UBLAS_TEST_STRINGIFY_(j__) << " == " << BOOST_UBLAS_TEST_EXPANDP_(j__) << ", " << BOOST_UBLAS_TEST_STRINGIFY_(nr) << " == " << BOOST_UBLAS_TEST_EXPANDP_(nr) << " and " << BOOST_UBLAS_TEST_STRINGIFY_(nc) << " == " << BOOST_UBLAS_TEST_EXPANDP_(nc) << "]" ); \
351 ++test_fails__; \
352 } \
353 } \
354 } \
355 /* [/BOOST_UBLAS_TEST_CHECK_MATRIX_EQ] */
356
357
358 /// Check that elements of matrices \a x and \a y are close with respect to a given precision \a e.
359 #define BOOST_UBLAS_TEST_CHECK_MATRIX_CLOSE(x,y,nr,nc,e) /* [BOOST_UBLAS_TEST_CHECK_MATRIX_CLOSE] */ \
360 for (::std::size_t i__ = 0; i__ < BOOST_UBLAS_TEST_EXPANDP_(nr); ++i__) \
361 { \
362 for (::std::size_t j__ = 0; j__ < BOOST_UBLAS_TEST_EXPANDP_(nc); ++j__) \
363 { \
364 if (!::boost::numeric::ublas::test::detail::close_to(BOOST_UBLAS_TEST_EXPANDP_(x)(i__,j__), BOOST_UBLAS_TEST_EXPANDP_(y)(i__,j__), BOOST_UBLAS_TEST_EXPANDP_(e))) \
365 { \
366 BOOST_UBLAS_TEST_ERROR( "Failed assertion: abs((" << BOOST_UBLAS_TEST_STRINGIFY_(x(i__,j__)) << "-" << BOOST_UBLAS_TEST_STRINGIFY_(y(i__,j__)) << ") <= " << BOOST_UBLAS_TEST_STRINGIFY_(e) << " [with " << BOOST_UBLAS_TEST_STRINGIFY_(x(i__,j__)) << " == " << BOOST_UBLAS_TEST_EXPANDP_(x)(i__,j__) << ", " << BOOST_UBLAS_TEST_STRINGIFY_(y(i__,j__)) << " == " << BOOST_UBLAS_TEST_EXPANDP_(y)(i__,j__) << ", " << BOOST_UBLAS_TEST_STRINGIFY_(i__) << " == " << i__ << ", " << BOOST_UBLAS_TEST_STRINGIFY_(j__) << " == " << BOOST_UBLAS_TEST_EXPANDP_(j__) << ", " << BOOST_UBLAS_TEST_STRINGIFY_(nr) << " == " << BOOST_UBLAS_TEST_EXPANDP_(nr) << " and " << BOOST_UBLAS_TEST_STRINGIFY_(nc) << " == " << BOOST_UBLAS_TEST_EXPANDP_(nc) << "]" ); \
367 ++test_fails__; \
368 } \
369 } \
370 } \
371 /* [/BOOST_UBLAS_TEST_CHECK_MATRIX_CLOSE] */
372
373
374 /// Check that elements of matrices \a x and \a y are close with respect to a given relative precision \a e.
375 #define BOOST_UBLAS_TEST_CHECK_MATRIX_REL_CLOSE(x,y,nr,nc,e) /* [BOOST_UBLAS_TEST_CHECK_MATRIX_REL_CLOSE] */ \
376 for (::std::size_t i__ = 0; i__ < BOOST_UBLAS_TEST_EXPANDP_(nr); ++i__) \
377 { \
378 for (::std::size_t j__ = 0; j__ < BOOST_UBLAS_TEST_EXPANDP_(nc); ++j__) \
379 { \
380 if (!::boost::numeric::ublas::test::detail::rel_close_to(BOOST_UBLAS_TEST_EXPANDP_(x)(i__,j__), BOOST_UBLAS_TEST_EXPANDP_(y)(i__,j__), BOOST_UBLAS_TEST_EXPANDP_(e))) \
381 { \
382 BOOST_UBLAS_TEST_ERROR( "Failed assertion: abs((" << BOOST_UBLAS_TEST_STRINGIFY_(x(i__,j__)) << "-" << BOOST_UBLAS_TEST_STRINGIFY_(y(i__,j__)) << ") <= " << BOOST_UBLAS_TEST_STRINGIFY_(e) << " [with " << BOOST_UBLAS_TEST_STRINGIFY_(x(i__,j__)) << " == " << BOOST_UBLAS_TEST_EXPANDP_(x)(i__,j__) << ", " << BOOST_UBLAS_TEST_STRINGIFY_(y(i__,j__)) << " == " << BOOST_UBLAS_TEST_EXPANDP_(y)(i__,j__) << ", " << BOOST_UBLAS_TEST_STRINGIFY_(i__) << " == " << i__ << ", " << BOOST_UBLAS_TEST_STRINGIFY_(j__) << " == " << BOOST_UBLAS_TEST_EXPANDP_(j__) << ", " << BOOST_UBLAS_TEST_STRINGIFY_(nr) << " == " << BOOST_UBLAS_TEST_EXPANDP_(nr) << " and " << BOOST_UBLAS_TEST_STRINGIFY_(nc) << " == " << BOOST_UBLAS_TEST_EXPANDP_(nc) << "]" ); \
383 ++test_fails__; \
384 } \
385 } \
386 } \
387 /* [/BOOST_UBLAS_TEST_CHECK_MATRIX_REL_CLOSE] */
388
389 ///< Output the error message \a x.
390 #ifdef _MSC_VER
391 # define BOOST_UBLAS_TEST_ERROR(x) ::std::cerr << "[Error (" << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << ")>> " << BOOST_UBLAS_TEST_EXPAND_(x) << ::std::endl
392 #else
393 # define BOOST_UBLAS_TEST_ERROR(x) ::std::cerr << "[Error (" << __FILE__ << ":" << __func__ << ":" << __LINE__ << ")>> " << BOOST_UBLAS_TEST_EXPAND_(x) << ::std::endl
394 #endif
395
396 #endif // BOOST_NUMERIC_UBLAS_TEST_UTILS_HPP
397