added PT::Construct_cofficient_const_iterator_range

added PT::Construct_innermost_coefficient_const_iterator_range
rm according functors _begin/_end
This commit is contained in:
Michael Hemmer 2008-10-15 08:38:34 +00:00
parent 79dec30a9c
commit 8e7bed8e6d
4 changed files with 70 additions and 63 deletions

View File

@ -79,8 +79,7 @@ Polynomial<NT> modular_gcd_utcf_dfai(
typedef typename PT::Innermost_coefficient_type IC;
typename Coercion_traits<Poly,IC>::Cast ictp;
typename PT::Innermost_coefficient_const_begin begin;
typename PT::Innermost_coefficient_const_end end;
typename PT::Construct_innermost_coefficient_const_iterator_range range;
typename PT::Innermost_leading_coefficient ilcoeff;
typedef Algebraic_extension_traits<IC> ANT;
@ -131,7 +130,7 @@ Polynomial<NT> modular_gcd_utcf_dfai(
IC denom;
{
Poly tmp = F1+F2;
denom = dfai(begin(tmp),end(tmp));
denom = dfai(range(tmp).first, range(tmp).second);
}
denom *= nfac(denom);

View File

@ -156,11 +156,10 @@ inline int square_free_factorize_for_regular_polynomial_
typedef Polynomial<Coeff> POLY;
typedef Polynomial_traits_d<POLY> PT;
typedef typename Polynomial_traits_d<POLY>::Innermost_coefficient_type IC;
typename Polynomial_traits_d<POLY>::Innermost_leading_coefficient ilcoeff;
//typename Polynomial_traits_d<POLY>::Innermost_coefficient_to_polynomial ictp;
typename Polynomial_traits_d<POLY>::Innermost_coefficient_const_begin begin;
typename Polynomial_traits_d<POLY>::Innermost_coefficient_const_end end;
typedef typename PT::Innermost_coefficient_type IC;
typename PT::Innermost_leading_coefficient ilcoeff;
//typename PT::Innermost_coefficient_to_polynomial ictp;
typename PT::Construct_innermost_coefficient_const_iterator_range range;
typename Algebraic_extension_traits<IC>::Denominator_for_algebraic_integers dfai;
typename Algebraic_extension_traits<IC>::Normalization_factor nfac;
typename Scalar_factor_traits<POLY>::Scalar_factor sfac;
@ -186,7 +185,7 @@ inline int square_free_factorize_for_regular_polynomial_
// integers, which comes out from c=gcd(a,b), such that a and b are
// divisible by c
IC lcoeff = ilcoeff(c);
IC denom = dfai(begin(c), end(c));
IC denom = dfai(range(c).first, range(c).second);
lcoeff *= denom * nfac(denom);
POLY w = (a * POLY(lcoeff)) / c;
POLY y = (b * POLY(lcoeff)) / c;
@ -209,7 +208,7 @@ inline int square_free_factorize_for_regular_polynomial_
}
i++;
lcoeff = ilcoeff(g); // same as above
denom =dfai(begin(c), end(c));
denom =dfai(range(c).first, range(c).second);
lcoeff *= denom * nfac(denom);
w = (w * POLY(lcoeff)) / g;
y = (z * POLY(lcoeff)) / g;

View File

@ -54,7 +54,16 @@
Innermost_coefficient_const_iterator; \
\
typedef typename Polynomial_d::const_iterator \
Coefficient_const_iterator;
Coefficient_const_iterator; \
\
typedef std::pair<Innermost_coefficient_const_iterator, \
Innermost_coefficient_const_iterator> \
Innermost_coefficient_const_iterator_range; \
\
typedef std::pair<Coefficient_const_iterator, \
Coefficient_const_iterator> \
Coefficient_const_iterator_range; \
CGAL_BEGIN_NAMESPACE;
@ -98,9 +107,8 @@ public:
operator()(const Polynomial_d& p) const {
typedef Innermost_coefficient_const_iterator IT;
Innermost_coefficient_type content(0);
for (IT it = typename PT::Innermost_coefficient_const_begin()(p);
it != typename PT::Innermost_coefficient_const_end()(p);
it++){
typename PT::Construct_innermost_coefficient_const_iterator_range range;
for (IT it = range(p).first; it != range(p).second; it++){
content = CGAL::gcd(content, *it);
if(CGAL::is_one(content)) break;
}
@ -437,6 +445,14 @@ class Polynomial_traits_d_base< Polynomial< Coefficient_type_ >,
typedef typename Coefficient_const_flattening::Recursive_flattening_iterator
Innermost_coefficient_const_iterator;
typedef typename Polynomial_d::const_iterator Coefficient_const_iterator;
typedef std::pair<Innermost_coefficient_const_iterator,
Innermost_coefficient_const_iterator>
Innermost_coefficient_const_iterator_range;
typedef std::pair<Coefficient_const_iterator,
Coefficient_const_iterator>
Coefficient_const_iterator_range;
// We use our own Strict Weak Ordering predicate in order to avoid
@ -966,35 +982,26 @@ public:
typedef typename ::boost::mpl::if_<IC_is_real_embeddable,Compare_,Null_functor>::type Compare;
// This is going to be in PolynomialToolBox
struct Coefficient_const_begin
: public std::unary_function< Polynomial_d, Coefficient_const_iterator > {
Coefficient_const_iterator
operator () (const Polynomial_d& p) { return p.begin(); }
};
struct Coefficient_const_end
: public std::unary_function< Polynomial_d, Coefficient_const_iterator > {
Coefficient_const_iterator
operator () (const Polynomial_d& p) { return p.end(); }
};
struct Innermost_coefficient_const_begin
: public std::unary_function< Polynomial_d, Innermost_coefficient_const_iterator > {
Innermost_coefficient_const_iterator
struct Construct_coefficient_const_iterator_range
: public std::unary_function< Polynomial_d,
Coefficient_const_iterator_range> {
Coefficient_const_iterator_range
operator () (const Polynomial_d& p) {
return typename Coefficient_const_flattening::Flatten()(p.end(),p.begin());
return make_pair( p.begin(), p.end() );
}
};
struct Construct_innermost_coefficient_const_iterator_range
: public std::unary_function< Polynomial_d,
Innermost_coefficient_const_iterator_range> {
Innermost_coefficient_const_iterator_range
operator () (const Polynomial_d& p) {
return make_pair(
typename Coefficient_const_flattening::Flatten()(p.end(),p.begin()),
typename Coefficient_const_flattening::Flatten()(p.end(),p.end()));
}
};
struct Innermost_coefficient_const_end
: public std::unary_function< Polynomial_d, Innermost_coefficient_const_iterator > {
Innermost_coefficient_const_iterator
operator () (const Polynomial_d& p) {
return typename Coefficient_const_flattening::Flatten()(p.end(),p.end());
}
};
struct Is_square_free
: public std::unary_function< Polynomial_d, bool >{
bool operator()( const Polynomial_d& p ) const {
@ -1101,8 +1108,7 @@ public:
typename PT::Construct_polynomial construct;
typename PT::Innermost_leading_coefficient ilcoeff;
typename PT::Innermost_coefficient_const_begin begin;
typename PT::Innermost_coefficient_const_end end;
typename PT::Construct_innermost_coefficient_const_iterator_range range;
typedef Algebraic_extension_traits<Innermost_coefficient_type> AET;
typename AET::Denominator_for_algebraic_integers dfai;
typename AET::Normalization_factor nfac;
@ -1110,7 +1116,7 @@ public:
IC ilcoeff_q = ilcoeff(q);
// this factor is needed in case IC is an Algebraic extension
IC dfai_q = dfai(begin(q), end(q));
IC dfai_q = dfai(range(q).first, range(q).second);
// make dfai_q a 'scalar'
ilcoeff_q *= dfai_q * nfac(dfai_q);

View File

@ -1507,19 +1507,19 @@ void test_coefficient_const_iterator(const PT&) {
typedef typename PT::Coefficient_type Coefficient;
typedef typename PT::Coefficient_const_iterator CCIterator;
typename PT::Coefficient_const_begin begin;
typename PT::Coefficient_const_end end;
typename PT::Construct_coefficient_const_iterator_range coeff_range;
typename PT::Degree degree;
typename PT::Get_coefficient coeff;
Polynomial_d p = generate_sparse_random_polynomial<Polynomial_d>();
CCIterator it = begin(p);
CCIterator it = coeff_range(p).first;
for(int i = 0; i <= degree(p); i++){
assert(*it == coeff(p,i));
it++;
}
assert(end(p) == it);
assert(coeff_range(p).second == it);
}
@ -1556,25 +1556,28 @@ void test_innermost_coefficient_const_iterator(const PT&) {
Polynomial_3 r(q1, q2, q3);
int i;
typename PT_1::Innermost_coefficient_const_iterator it1; (void) it1;
typename PT_1::Innermost_coefficient_const_begin begin1; (void) begin1;
typename PT_1::Innermost_coefficient_const_end end1; (void) end1;
typename PT_2::Innermost_coefficient_const_iterator it2; (void) it2;
typename PT_2::Innermost_coefficient_const_begin begin2; (void) begin2;
typename PT_2::Innermost_coefficient_const_end end2; (void) end2;
typename PT_3::Innermost_coefficient_const_iterator it3; (void) it3;
typename PT_3::Innermost_coefficient_const_begin begin3; (void) begin3;
typename PT_3::Innermost_coefficient_const_end end3; (void) end3;
for (i = 1, it1 = begin1(p1); i <= 3; ++i, ++it1)
typename PT_1::Innermost_coefficient_const_iterator it1; (void) it1;
typename PT_1::Construct_innermost_coefficient_const_iterator_range range1;
typename PT_2::Innermost_coefficient_const_iterator it2; (void) it2;
typename PT_2::Construct_innermost_coefficient_const_iterator_range range2;
typename PT_3::Innermost_coefficient_const_iterator it3; (void) it3;
typename PT_3::Construct_innermost_coefficient_const_iterator_range range3;
(void) range1;
(void) range2;
(void) range3;
for (i = 1, it1 = (range1(p1).first); i <= 3; ++i, ++it1)
assert(*it1 == i);
assert(it1 == end1(p1));
for (i = 1, it2 = begin2(q1); i <= 9; ++i, ++it2)
assert(it1 == range1(p1).second);
for (i = 1, it2 = range2(q1).first; i <= 9; ++i, ++it2)
assert(*it2 == i);
assert(it2 == end2(q1));
for (i = 1, it3 = begin3(r); i <= 27; ++i, ++it3)
assert(it2 == range2(q1).second);
for (i = 1, it3 = range3(r).first; i <= 27; ++i, ++it3)
assert(*it3 == i);
assert(it3 == end3(r));
assert(it3 == range3(r).second);
}
@ -1774,7 +1777,7 @@ int main(){
#ifdef CGAL_USE_CORE
{
typedef CGAL::CORE_arithmetic_kernel AT;
test_AT<AT>();
//test_AT<AT>();
}
#endif