added a special cache for efficient conversion of

Sqrt_extension to Bigfloat_interval, disabled by default
This commit is contained in:
Michael Hemmer 2008-09-11 08:54:12 +00:00
parent 492a11533d
commit 655514b33c
1 changed files with 63 additions and 12 deletions

View File

@ -25,6 +25,7 @@
#include <CGAL/basic.h>
#include <CGAL/Arithmetic_kernel.h>
#include <CGAL/Cache.h>
CGAL_BEGIN_NAMESPACE
@ -42,25 +43,75 @@ convert_to_bfi(const NTX& x) {
// return convert_to_bfi(x);
}
// Disbale SQRT_EXTENSION_TO_BFI_CACHE by default
#ifndef CGAL_USE_SQRT_EXTENSION_TO_BFI_CACHE
#define CGAL_USE_SQRT_EXTENSION_TO_BFI_CACHE 0
#endif
#if CGAL_USE_SQRT_EXTENSION_TO_BFI_CACHE
namespace INTERN_SQRT_EXTENSION {
template <typename BFI, typename NT, typename ROOT>
class Sqrt_extension_bfi_cache {
typedef std::pair<long , ROOT> Input;
typedef BFI Output;
typedef typename Coercion_traits<ROOT,BFI>::Cast Cast;
typedef typename Algebraic_structure_traits<BFI>::Sqrt Sqrt;
struct Creator : public std::unary_function<BFI,Input> {
BFI operator()(const Input& pair){
return Sqrt()(Cast()(pair.second));
}
};
}
public:
typedef Cache<Input,Output,Creator> Cache_type;
static Cache_type cache;
};
template <typename BFI, typename NT, typename ROOT>
typename Sqrt_extension_bfi_cache<BFI,NT,ROOT>::Cache_type
Sqrt_extension_bfi_cache<BFI,NT,ROOT>::cache;
} // namespace INTERN_SQRT_EXTENSION
// TODO: move this to sqrt_extension ?
/*
template <typename A,typename B> class Sqrt_extension;
template <typename NT, typename ROOT>
typename Get_arithmetic_kernel<NT>::Arithmetic_kernel::Bigfloat_interval
convert_to_bfi(const CGAL::Sqrt_extension<NT,ROOT>& x) {
template <typename A,typename B> class Sqrt_extension;
template <typename NT, typename ROOT>
typename Get_arithmetic_kernel<NT>::Arithmetic_kernel::Bigfloat_interval
convert_to_bfi(const CGAL::Sqrt_extension<NT,ROOT>& x) {
typedef typename Get_arithmetic_kernel<NT>::Arithmetic_kernel AK;
typedef typename AK::Bigfloat_interval BFI;
typedef Bigfloat_interval_traits<BFI> BFIT;
long precision = typename BFIT::Get_precision()();
BFI result;
if(x.is_extended()){
typedef INTERN_SQRT_EXTENSION::Sqrt_extension_bfi_cache<BFI,NT,ROOT> Get_cache;
BFI a0(convert_to_bfi(x.a0()));
BFI a1(convert_to_bfi(x.a1()));
BFI root(Get_cache::cache(std::make_pair(precision,x.root())));
result = a0+a1*root;
}else{
result = convert_to_bfi(x.a0());
}
#ifndef NDEBUG
BFI result_;
typedef typename Get_arithmetic_kernel<NT>::Arithmetic_kernel AT;
typedef typename AT::Bigfloat_interval BFI;
if(x.is_extended()){
BFI a0(convert_to_bfi(x.a0()));
BFI a1(convert_to_bfi(x.a1()));
BFI root(CGAL::sqrt(convert_to_bfi(x.root())));
return a0+a1*root;
BFI a0(convert_to_bfi(x.a0()));
BFI a1(convert_to_bfi(x.a1()));
BFI root(CGAL::sqrt(convert_to_bfi(x.root())));
result_ = a0+a1*root;
}else{
return convert_to_bfi(x.a0());
result_ = convert_to_bfi(x.a0());
}
}
*/
assert(lower(result) == lower(result_));
assert(upper(result) == upper(result_));
#endif
return result;
}
#endif
CGAL_END_NAMESPACE