Skip to content

Commit

Permalink
Merge pull request #5937 from danston/Number_types-add_benchmarks-dan…
Browse files Browse the repository at this point in the history
…ston

Robust Quotient with cpp_int
  • Loading branch information
lrineau committed May 6, 2022
2 parents 6da2784 + 4bd7049 commit 8f233c2
Show file tree
Hide file tree
Showing 8 changed files with 1,223 additions and 46 deletions.
4 changes: 2 additions & 2 deletions Arithmetic_kernel/include/CGAL/BOOST_MP_arithmetic_kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
//
// Author: Marc Glisse <[email protected]>

#ifndef CGAL_GMPXX_ARITHMETIC_KERNEL_H
#define CGAL_GMPXX_ARITHMETIC_KERNEL_H
#ifndef CGAL_BOOST_MP_ARITHMETIC_KERNEL_H
#define CGAL_BOOST_MP_ARITHMETIC_KERNEL_H

#include <CGAL/Arithmetic_kernel/Arithmetic_kernel_base.h>
#include <CGAL/Get_arithmetic_kernel.h>
Expand Down
1 change: 0 additions & 1 deletion NewKernel_d/test/NewKernel_d/Epick_d.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include <boost/config.hpp>

//#define BOOST_RESULT_OF_USE_DECLTYPE 1
#include <CGAL/Epick_d.h>
#include <CGAL/Epeck_d.h>
#include <typeinfo>
Expand Down
38 changes: 19 additions & 19 deletions Number_types/include/CGAL/Exact_integer.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,30 +50,30 @@ typedef unspecified_type Exact_integer;

#else // not DOXYGEN_RUNNING

#if CGAL_USE_GMPXX

#if ( (defined(CGAL_TEST_SUITE) && CGAL_VERSION_NR == 1050500900) || defined(CGAL_FORCE_USE_BOOST_MP))\
&& BOOST_VERSION > 107800 && defined(CGAL_USE_BOOST_MP)
// use boost-mp by default in the testsuite until 5.5-beta is out
typedef BOOST_cpp_arithmetic_kernel::Integer Exact_integer;
#else // BOOST_VERSION > 107800
#ifdef CGAL_USE_GMPXX
typedef mpz_class Exact_integer;

#elif CGAL_USE_GMP
# ifdef CGAL_USE_BOOST_MP
typedef boost::multiprecision::mpz_int Exact_integer;
# else
#elif defined(CGAL_USE_GMP)
#if defined(CGAL_USE_BOOST_MP)
typedef BOOST_gmp_arithmetic_kernel::Integer Exact_integer;
#else
typedef Gmpz Exact_integer;
# endif

#elif CGAL_USE_LEDA

#endif
#elif defined(CGAL_USE_LEDA)
typedef leda_integer Exact_integer;

#elif CGAL_USE_CORE

#elif defined(CGAL_USE_BOOST_MP)
typedef BOOST_cpp_arithmetic_kernel::Integer Exact_integer;
#elif defined(CGAL_USE_CORE)
typedef CORE::BigInt Exact_integer;

#elif defined CGAL_USE_BOOST_MP

typedef boost::multiprecision::cpp_int Exact_integer;

#else
#error "ERROR: Cannot determine a BigInt type!"
#endif // CGAL_USE_CORE
#endif // BOOST_VERSION > 107800

#endif // not DOXYGEN_RUNNING

} /* end namespace CGAL */
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
# include <CGAL/leda_real.h>
#endif
#ifdef CGAL_USE_CORE
// # include <CGAL/CORE_Expr.h>
// # include <CGAL/CORE_Expr.h>
namespace CORE {
class Expr;
}
Expand All @@ -54,23 +54,39 @@ namespace CGAL { namespace internal {
// It should support the built-in types.
template < typename >
struct Exact_field_selector

#if ( (defined(CGAL_TEST_SUITE) && CGAL_VERSION_NR == 1050500900) || defined(CGAL_FORCE_USE_BOOST_MP))\
&& BOOST_VERSION > 107800 && defined(CGAL_USE_BOOST_MP)
// use boost-mp by default in the testsuite until 5.5-beta is out
// Boost
{ typedef BOOST_cpp_arithmetic_kernel::Rational Type; };
#else // BOOST_VERSION > 107800
#ifdef CGAL_USE_GMPXX
{ typedef mpq_class Type; };
#elif defined(CGAL_USE_GMP)
# if defined(CGAL_USE_BOOST_MP)
{ typedef boost::multiprecision::mpq_rational Type; };
# else
#if defined(CGAL_USE_BOOST_MP)
{ typedef BOOST_gmp_arithmetic_kernel::Rational Type; };
#else
{ typedef Gmpq Type; };
# endif
#endif
#elif defined(CGAL_USE_LEDA)
{ typedef leda_rational Type; };
#elif 0 && defined(CGAL_USE_BOOST_MP)
#elif defined(CGAL_USE_BOOST_MP)
// See the discussion in https://github.com/CGAL/cgal/pull/3614
// This is disabled for now because cpp_rational is even slower than Quotient<MP_Float>. Quotient<cpp_int> will be a good candidate after some polishing.
// In fact, the new version of cpp_rational from here: https://github.com/boostorg/multiprecision/pull/366
// is much better than Quotient<cpp_int> because it is using smart gcd and is well-supported
// while Quotient does not. Though, we can still use it if needed.
#if BOOST_VERSION <= 107800
// See this comment: https://github.com/CGAL/cgal/pull/5937#discussion_r721533675
{ typedef Quotient<boost::multiprecision::cpp_int> Type; };
#else
{ typedef BOOST_cpp_arithmetic_kernel::Rational Type; };
#endif
#else
{ typedef Quotient<MP_Float> Type; };
#endif
#endif // BOOST_VERSION > 107800

// By default, a field is a safe choice of ring.
template < typename T >
Expand Down
14 changes: 13 additions & 1 deletion Number_types/include/CGAL/Quotient.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
#include <CGAL/Kernel/mpl.h>

#include <boost/operators.hpp>
#ifdef CGAL_USE_BOOST_MP
#include <boost/multiprecision/cpp_int.hpp>
#endif // CGAL_USE_BOOST_MP

namespace CGAL {

Expand All @@ -46,6 +49,15 @@ template < typename NT >
inline void
simplify_quotient(NT &, NT &) {}

#ifdef CGAL_USE_BOOST_MP
inline void
simplify_quotient(boost::multiprecision::cpp_int & a, boost::multiprecision::cpp_int & b) {
const boost::multiprecision::cpp_int r = boost::multiprecision::gcd(a, b);
a /= r;
b /= r;
}
#endif // CGAL_USE_BOOST_MP

// This one should be replaced by some functor or tag.
// Meanwhile, the class is specialized for Gmpz, mpz_class, leda_integer.
template < typename NT >
Expand Down Expand Up @@ -687,7 +699,7 @@ template < class NT > class Real_embeddable_traits_quotient_base< Quotient<NT> >
: public CGAL::cpp98::unary_function< Type, std::pair< double, double > > {
public:
std::pair<double, double> operator()( const Type& x ) const {
Interval_nt<> quot =
const Interval_nt<> quot =
Interval_nt<>(CGAL_NTS to_interval(x.numerator())) /
Interval_nt<>(CGAL_NTS to_interval(x.denominator()));
return std::make_pair(quot.inf(), quot.sup());
Expand Down
Loading

0 comments on commit 8f233c2

Please sign in to comment.