refactoring

parent 9e4d201b
......@@ -7,10 +7,23 @@ env = Environment( #variables = vars,
CXX = 'g++',
CXXFLAGS = Split('-I./include -I./src \
-march=native -mtune=native -std=gnu++14 -fabi-version=6 \
-fpermissive -Wall -Wextra -fopenmp'),
LIBPATH = '#lib/',
LIBS = Split('-lopenblas -lgivaro -lgmpxx -lgmp'),
LINKFLAGS = '-fopenmp'
-fpermissive -Wall -Wextra -fopenmp'),
LIBPATH = '#lib/',
LIBS = Split('-lopenblas -lgivaro -lgmpxx -lgmp'),
LINKFLAGS = '-fopenmp',
SRC_CC = ['#src/finite_field_arithmetic/givaro_wrapper.cc',
'#src/logger.cc',
'#src/monomial.cc',
'#src/select_reductors.cc',
'#src/critical_pair.cc',
'#src/polynomial_in_matrix.cc',
'#src/polynomial.cc',
'#src/matrices/io_utils.cc',
'#src/matrices/spmat.cc',
'#src/utils.cc',
'#src/linalg/storage_matrix.cc',
'#src/glob_params.cc',
'#src/matrices/rowmajmat.cc']
)
#Help(vars.GenerateHelpText(env))
......
......@@ -12,39 +12,34 @@ namespace tinygb {
template <typename T> // CRTP
class AbstractField {
public:
std::string description() const {
return static_cast<T*>(this)->description();
std::string description() const {
return static_cast<T*>(this)->description();
}
};
// T is the CRTP parameter
// Field is a concrete field
template <typename Field, typename T>
class AbstractFieldElement {
static_assert(std::is_base_of<AbstractField<Field>, Field>::value,
"Field should be derived from AbstractField");
public:
typedef Field Parent;
void operator+=(const AbstractFieldElement<Field, T>& e) {
static_cast<T*>(this)->operator+=(e);
}
void operator-=(const AbstractFieldElement<Field, T>& e) {
static_cast<T*>(this)->operator-=(e);
}
void operator*=(const AbstractFieldElement<Field, T>& e) {
static_cast<T*>(this)->operator*=(e);
}
void operator/=(const AbstractFieldElement<Field, T>& e) {
static_cast<T*>(this)->operator/=(e);
}
void inv() {
static_cast<T*>(this)->inv();
}
bool IsZero() const {
return static_cast<T*>(this)->isZero();
}
template <typename U> // CRTP
class Element {
public:
typedef T Parent;
void operator+=(const Element<U>& e) {
static_cast<T*>(this)->operator+=(e);
}
void operator-=(const Element<U>& e) {
static_cast<T*>(this)->operator-=(e);
}
void operator*=(const Element<U>& e) {
static_cast<T*>(this)->operator*=(e);
}
void operator/=(const Element<U>& e) {
static_cast<T*>(this)->operator/=(e);
}
void inv() {
static_cast<T*>(this)->inv();
}
bool IsZero() const {
return static_cast<T*>(this)->isZero();
}
};
};
} // namespace tinygb
......
......@@ -10,15 +10,14 @@ namespace tinygb {
// implementations of polynomials are implemented in subclasses via static
// polymorphism.
template <class FieldElement, class T> // T is the CRTP parameter
template <class Field, class T> // T is the CRTP parameter
class AbstractPolynomial {
static_assert(std::is_base_of<AbstractFieldElement<typename FieldElement::Parent, FieldElement>,
FieldElement>::value,
static_assert(std::is_base_of<AbstractField<Field>, Field>::value,
"Field should be derived from AbstractField");
public:
Monomial LeadingMonomial() const {
return static_cast<T*>(this)->LeadingMonomial();}
FieldElement LeadingCoefficient() const {
typename Field::Element LeadingCoefficient() const {
return static_cast<T*>(this)->LeadingCoefficient();}
void DivideByLeadingCoefficient() {
static_cast<T*>(this)->DivideByLeadingCoefficient();}
......
Import('env')
source_files = ['addcrit.cc',
'#src/finite_field_arithmetic/givaro_wrapper.cc',
'#src/logger.cc',
'#src/monomial.cc',
'#src/critical_pair.cc',
'#src/polynomial_in_matrix.cc',
'#src/polynomial.cc',
'#src/matrices/io_utils.cc',
'#src/utils.cc',
'#src/glob_params.cc',
'#src/matrices/rowmajmat.cc']
source_files = env['SRC_CC'] + ['addcrit.cc']
env.Program('addcrit', source_files)
Import('env')
source_files = ['buildmats.cc',
'#src/finite_field_arithmetic/givaro_wrapper.cc',
'#src/logger.cc',
'#src/monomial.cc',
'#src/critical_pair.cc',
'#src/polynomial_in_matrix.cc',
'#src/polynomial.cc',
'#src/matrices/spmat.cc',
'#src/matrices/io_utils.cc',
'#src/utils.cc',
'#src/glob_params.cc',
'#src/matrices/rowmajmat.cc']
source_files = env['SRC_CC'] + ['buildmats.cc']
env.Program('buildmats', source_files)
......@@ -10,53 +10,54 @@
namespace tinygb {
class GFp : public AbstractField<GFp> {
class GFp_Givaro : public AbstractField<GFp_Givaro> {
public:
std::string description() const {
return "Finite field of prime cardinality p";}
};
class Element : public AbstractField<GFp_Givaro>::Element<GFp_Givaro::Element> {
public:
typedef Givaro::Integer elt_t;
typedef Givaro::Modular<Givaro::Integer> ring_t;
class GivaroWrapper : public AbstractFieldElement<GFp, GivaroWrapper> {
public:
typedef Givaro::Integer elt_t;
typedef Givaro::Modular<Givaro::Integer> ring_t;
static ring_t k;
elt_t v;
static ring_t k;
elt_t v;
// Constructors
GivaroWrapper() {}
GivaroWrapper(const char* n) { k.init(v, n); }
GivaroWrapper(int n) { k.init(v, n); }
GivaroWrapper(const mpz_class& n) { k.init(v, n);}
GivaroWrapper(const elt_t& n) { k.init(v, n); }
GivaroWrapper(const std::string& s) { k.init(v, s.c_str()); }
// Constructors
Element() {}
Element(const char* n) { k.init(v, n); }
Element(int n) { k.init(v, n); }
Element(const mpz_class& n) { k.init(v, n);}
Element(const elt_t& n) { k.init(v, n); }
Element(const std::string& s) { k.init(v, s.c_str()); }
// Copy constructor
GivaroWrapper(const GivaroWrapper& x) { k.assign(v, x.v); }
// Copy constructor
Element(const Element& x) { k.assign(v, x.v); }
// TODO rule of 0/3/5
GivaroWrapper& operator=(const GivaroWrapper& x) {
k.assign(v, x.v);
return *this;
}
// TODO rule of 0/3/5
Element& operator=(const Element& x) {
k.assign(v, x.v);
return *this;
}
inline bool is_zero() const { return k.isZero(v); }
friend std::ostream& operator<<(std::ostream&, const GivaroWrapper&);
friend std::istream& operator>>(std::istream&, GivaroWrapper&);
inline void neg() { v = -v; }
void operator+=(const GivaroWrapper& a) { k.addin(v, a.v); }
void operator-=(const GivaroWrapper& a) { k.subin(v, a.v); }
void operator*=(const GivaroWrapper& a) { k.mulin(v, a.v); }
void operator/=(const GivaroWrapper& a) { k.divin(v, a.v); }
bool operator==(const GivaroWrapper& a) const { return v == a.v; }
bool operator!=(const GivaroWrapper& a) const { return v != a.v; }
void inv() { k.invin(v); }
mpz_srcptr get_mpz() const { return v.get_mpz(); }
void set_mpz(const mpz_class& a) { k.init(v, elt_t(a)); }
inline bool is_zero() const { return k.isZero(v); }
friend std::ostream& operator<<(std::ostream&, const Element&);
friend std::istream& operator>>(std::istream&, Element&);
inline void neg() { v = -v; }
void operator+=(const Element& a) { k.addin(v, a.v); }
void operator-=(const Element& a) { k.subin(v, a.v); }
void operator*=(const Element& a) { k.mulin(v, a.v); }
void operator/=(const Element& a) { k.divin(v, a.v); }
bool operator==(const Element& a) const { return v == a.v; }
bool operator!=(const Element& a) const { return v != a.v; }
void inv() { k.invin(v); }
mpz_srcptr get_mpz() const { return v.get_mpz(); }
void set_mpz(const mpz_class& a) { k.init(v, elt_t(a)); }
};
};
typedef GFp_Givaro::Element GivaroWrapper;
std::ostream& operator<<(std::ostream&, const GivaroWrapper &);
std::istream& operator>>(std::istream&, GivaroWrapper&);
......
Import('env')
source_files = ['matmulsub.cc',
'#src/monomial.cc',
'#src/logger.cc',
'#src/polynomial.cc',
'#src/critical_pair.cc',
'#src/polynomial_in_matrix.cc',
'#src/matrices/rowmajmat.cc',
'#src/matrices/io_utils.cc',
'#src/utils.cc',
'#src/glob_params.cc',
'#src/finite_field_arithmetic/givaro_wrapper.cc']
source_files = env['SRC_CC'] + ['matmulsub.cc']
env.Program('matmulsub', source_files)
......@@ -10,7 +10,7 @@
namespace tinygb {
class Polynomial : public AbstractPolynomial<GivaroWrapper, Polynomial> {
class Polynomial : public AbstractPolynomial<GFp_Givaro, Polynomial> {
public:
typedef std::pair<Monomial, GivaroWrapper> Term;
......
......@@ -13,7 +13,7 @@
namespace tinygb {
class PolynomialInMatrix {
class PolynomialInMatrix : public AbstractPolynomial<GFp_Givaro, PolynomialInMatrix> {
public:
PolynomialInMatrix() : pMatrix_(nullptr), row_(0), nbMonoms_(0) {}
......
Import('env')
source_files = ['rowech.cc',
'#src/finite_field_arithmetic/givaro_wrapper.cc',
'#src/logger.cc',
'#src/monomial.cc',
'#src/critical_pair.cc',
'#src/polynomial_in_matrix.cc',
'#src/polynomial.cc',
'#src/matrices/io_utils.cc',
'#src/utils.cc',
'#src/glob_params.cc',
'#src/matrices/rowmajmat.cc']
source_files = env['SRC_CC'] + ['rowech.cc']
env.Program('rowech', source_files)
Import('env')
source_files = ['selcrit.cc',
'#src/finite_field_arithmetic/givaro_wrapper.cc',
'#src/logger.cc',
'#src/monomial.cc',
'#src/critical_pair.cc',
'#src/polynomial_in_matrix.cc',
'#src/polynomial.cc',
'#src/matrices/io_utils.cc',
'#src/utils.cc',
'#src/glob_params.cc',
'#src/matrices/rowmajmat.cc']
source_files = env['SRC_CC'] + ['selcrit.cc']
env.Program('selcrit', source_files)
Import('env')
source_files = ['selred.cc',
'#src/finite_field_arithmetic/givaro_wrapper.cc',
'#src/logger.cc',
'#src/monomial.cc',
'select_reductors.cc',
'#src/critical_pair.cc',
'#src/polynomial_in_matrix.cc',
'#src/polynomial.cc',
'#src/matrices/io_utils.cc',
'#src/utils.cc',
'#src/glob_params.cc',
'#src/matrices/rowmajmat.cc']
source_files = env['SRC_CC'] + ['selred.cc']
env.Program('selred', source_files)
......@@ -5,7 +5,7 @@
#include "./finite_field_arithmetic/givaro_wrapper.h"
#include "./common.h"
#include "./utils.h"
#include "selred/select_reductors.h"
#include "./select_reductors.h"
#include "./macros.h"
#include "./logger.h"
......
Import('env')
source_files = ['tinygb_init.cc',
'#src/finite_field_arithmetic/givaro_wrapper.cc',
'#src/monomial.cc',
'#src/logger.cc',
'#src/critical_pair.cc',
'#src/polynomial_in_matrix.cc',
'#src/polynomial.cc',
'#src/matrices/io_utils.cc',
'#src/utils.cc',
'#src/glob_params.cc',
'#src/linalg/storage_matrix.cc',
'#src/matrices/rowmajmat.cc']
source_files = env['SRC_CC'] + ['tinygb_init.cc']
env.Program('tinygb_init', source_files)
Import('env')
source_files = ['utsolve.cc',
'#src/critical_pair.cc',
'#src/monomial.cc',
'#src/polynomial.cc',
'#src/polynomial_in_matrix.cc',
'#src/matrices/spmat.cc',
'#src/matrices/rowmajmat.cc',
'#src/matrices/io_utils.cc',
'#src/utils.cc',
'#src/glob_params.cc',
'#src/finite_field_arithmetic/givaro_wrapper.cc',
'#src/logger.cc']
source_files = env['SRC_CC'] + ['utsolve.cc']
env.Program('utsolve', source_files)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment