From 70de0fdb59c11bcc801d751ec2d5caee50c6e164 Mon Sep 17 00:00:00 2001 From: Gunter Winkler Date: Mon, 10 Sep 2012 20:50:10 +0000 Subject: [PATCH] boost/numeric/ublas/traits.hpp, libs/numeric/ublas/test/test_assignment.cpp, libs/numeric/ublas/test/begin_end.cpp: see #7296, fix test issues with unsigned integer types svn path=/trunk/boost/numeric/ublas/; revision=80483 --- include/boost/numeric/ublas/traits.hpp | 8 ++++++++ test/begin_end.cpp | 8 ++++---- test/test_assignment.cpp | 4 ++-- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/include/boost/numeric/ublas/traits.hpp b/include/boost/numeric/ublas/traits.hpp index 25421efd..ae020700 100644 --- a/include/boost/numeric/ublas/traits.hpp +++ b/include/boost/numeric/ublas/traits.hpp @@ -41,6 +41,14 @@ namespace { // we'll find either std::abs or else another version via ADL: return abs (t); } + // unsigned types are always non-negative + template<> unsigned int boost_numeric_ublas_abs (const unsigned int& t) { + return t; + } + // unsigned types are always non-negative + template<> unsigned long boost_numeric_ublas_abs (const unsigned long& t) { + return t; + } } namespace boost { namespace numeric { namespace ublas { diff --git a/test/begin_end.cpp b/test/begin_end.cpp index e6a67777..270aa4a8 100644 --- a/test/begin_end.cpp +++ b/test/begin_end.cpp @@ -49,7 +49,7 @@ BOOST_UBLAS_TEST_DEF( test_vector_iteration ) ++it ) { BOOST_UBLAS_DEBUG_TRACE( "*it = " << *it << " ==> " << v(ix) ); - BOOST_UBLAS_TEST_CHECK( std::fabs(*it - v(ix)) <= TOL ); + BOOST_UBLAS_TEST_CHECK( std::abs(*it - v(ix)) <= TOL ); ++ix; } } @@ -78,7 +78,7 @@ BOOST_UBLAS_TEST_DEF( test_vector_const_iteration ) ++it ) { BOOST_UBLAS_DEBUG_TRACE( "*it = " << *it << " ==> " << v(ix) ); - BOOST_UBLAS_TEST_CHECK( std::fabs(*it - v(ix)) <= TOL ); + BOOST_UBLAS_TEST_CHECK( std::abs(*it - v(ix)) <= TOL ); ++ix; } } @@ -116,7 +116,7 @@ BOOST_UBLAS_TEST_DEF( test_row_major_matrix_iteration ) ++inner_it ) { BOOST_UBLAS_DEBUG_TRACE( "*it = " << *inner_it << " ==> " << A(row,col) ); - BOOST_UBLAS_TEST_CHECK( std::fabs(*inner_it - A(row,col)) <= TOL ); + BOOST_UBLAS_TEST_CHECK( std::abs(*inner_it - A(row,col)) <= TOL ); ++col; } @@ -158,7 +158,7 @@ BOOST_UBLAS_TEST_DEF( test_col_major_matrix_iteration ) ++inner_it ) { BOOST_UBLAS_DEBUG_TRACE( "*it = " << *inner_it << " ==> " << A(row,col) ); - BOOST_UBLAS_TEST_CHECK( std::fabs(*inner_it - A(row,col)) <= TOL ); + BOOST_UBLAS_TEST_CHECK( std::abs(*inner_it - A(row,col)) <= TOL ); ++row; } diff --git a/test/test_assignment.cpp b/test/test_assignment.cpp index cbfe0e56..4a3897c7 100644 --- a/test/test_assignment.cpp +++ b/test/test_assignment.cpp @@ -26,7 +26,7 @@ typename AE::value_type mean_square(const matrix_expression &me) { typename AE::size_type i, j; for (i=0; i!= me().size1(); i++) { for (j=0; j!= me().size2(); j++) { - s+=std::fabs(me()(i,j)); + s+= scalar_traits::type_abs(me()(i,j)); } } return s/me().size1()*me().size2(); @@ -39,7 +39,7 @@ typename AE::value_type mean_square(const vector_expression &ve) { typename AE::value_type s(0); typename AE::size_type i; for (i=0; i!= ve().size(); i++) { - s+=std::fabs(ve()(i)); + s+=scalar_traits::type_abs(ve()(i)); } return s/ve().size(); }