mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-03-07 18:27:40 +08:00
enable testing of Boost.Multiprecision with expression templates
This commit is contained in:
parent
7b4abc2b1d
commit
72950effdf
@ -7,6 +7,8 @@
|
||||
// Public License v. 2.0. If a copy of the MPL was not distributed
|
||||
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#ifdef EIGEN_TEST_MAX_SIZE
|
||||
#undef EIGEN_TEST_MAX_SIZE
|
||||
#endif
|
||||
@ -57,13 +59,16 @@
|
||||
#include <boost/multiprecision/number.hpp>
|
||||
|
||||
namespace mp = boost::multiprecision;
|
||||
typedef mp::number<mp::cpp_dec_float<100>, mp::et_off> Real;
|
||||
typedef mp::number<mp::cpp_dec_float<100>, mp::et_off> Real; // swith to et_on for testing with expression templates
|
||||
|
||||
namespace Eigen {
|
||||
template<> struct NumTraits<Real> : GenericNumTraits<Real> {
|
||||
static inline Real dummy_precision() { return 1e-50; }
|
||||
};
|
||||
|
||||
template<typename T1,typename T2,typename T3,typename T4,typename T5>
|
||||
struct NumTraits<boost::multiprecision::detail::expression<T1,T2,T3,T4,T5> > : NumTraits<Real> {};
|
||||
|
||||
template<>
|
||||
Real test_precision<Real>() { return 1e-50; }
|
||||
}
|
||||
@ -82,10 +87,11 @@ namespace multiprecision {
|
||||
return internal::isApprox(a, b, test_precision<Real>());
|
||||
}
|
||||
|
||||
inline bool test_isApproxOrLessThan(const Real& a, const Real& b)
|
||||
{ return internal::isApproxOrLessThan(a, b, test_precision<Real>()); }
|
||||
inline bool test_isApproxOrLessThan(const Real& a, const Real& b) {
|
||||
return internal::isApproxOrLessThan(a, b, test_precision<Real>());
|
||||
}
|
||||
|
||||
Real get_test_precision(const Real*) {
|
||||
Real get_test_precision(const Real&) {
|
||||
return test_precision<Real>();
|
||||
}
|
||||
|
||||
@ -108,6 +114,14 @@ void test_boostmultiprec()
|
||||
std::cout << "NumTraits<Real>::lowest() = " << NumTraits<Real>::lowest() << std::endl;
|
||||
std::cout << "NumTraits<Real>::highest() = " << NumTraits<Real>::highest() << std::endl;
|
||||
|
||||
// chekc stream output
|
||||
{
|
||||
Mat A(10,10);
|
||||
A.setRandom();
|
||||
std::stringstream ss;
|
||||
ss << A;
|
||||
}
|
||||
|
||||
for(int i = 0; i < g_repeat; i++) {
|
||||
int s = internal::random<int>(1,EIGEN_TEST_MAX_SIZE);
|
||||
|
||||
|
@ -452,20 +452,20 @@ T test_relative_error(const AngleAxis<T> &a, const AngleAxis<T> &b)
|
||||
}
|
||||
|
||||
template<typename Type1, typename Type2>
|
||||
inline bool test_isApprox(const Type1& a, const Type2& b)
|
||||
inline bool test_isApprox(const Type1& a, const Type2& b, typename Type1::Scalar* = 0) // Enabled for Eigen's type only
|
||||
{
|
||||
return a.isApprox(b, test_precision<typename Type1::Scalar>());
|
||||
}
|
||||
|
||||
// get_test_precision is a small wrapper to test_precision allowing to return the scalar precision for either scalars or expressions
|
||||
template<typename T>
|
||||
typename NumTraits<typename T::Scalar>::Real get_test_precision(const T*, const typename T::Scalar* = 0)
|
||||
typename NumTraits<typename T::Scalar>::Real get_test_precision(const T&, const typename T::Scalar* = 0)
|
||||
{
|
||||
return test_precision<typename NumTraits<typename T::Scalar>::Real>();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
typename NumTraits<T>::Real get_test_precision(const T*,typename internal::enable_if<internal::is_arithmetic<typename NumTraits<T>::Real>::value, T>::type* = 0)
|
||||
typename NumTraits<T>::Real get_test_precision(const T&,typename internal::enable_if<internal::is_arithmetic<typename NumTraits<T>::Real>::value, T>::type* = 0)
|
||||
{
|
||||
return test_precision<typename NumTraits<T>::Real>();
|
||||
}
|
||||
@ -477,7 +477,7 @@ inline bool verifyIsApprox(const Type1& a, const Type2& b)
|
||||
bool ret = test_isApprox(a,b);
|
||||
if(!ret)
|
||||
{
|
||||
std::cerr << "Difference too large wrt tolerance " << get_test_precision(static_cast<Type1*>(0)) << ", relative error is: " << test_relative_error(a,b) << std::endl;
|
||||
std::cerr << "Difference too large wrt tolerance " << get_test_precision(a) << ", relative error is: " << test_relative_error(a,b) << std::endl;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user