add namespace tinygb

parent 79bf1d5e
......@@ -5,6 +5,8 @@
#include "./polynomial.h"
#include "./parser.h"
namespace tinygb {
void launchF4(std::istream& in, std::ostream& out);
void initF4(std::istream& in, std::ostream& out);
......@@ -14,6 +16,8 @@ void field_init();
template <class T>
void field_clear();
} // namespace tinygb
#include "F4_launcher.tpp"
#endif // F4_LAUNCHER_H_
#include <string>
#include <vector>
namespace tinygb {
void initF4(std::istream& in, std::ostream& out);
template <class T>
......@@ -59,3 +61,5 @@ void initF4(istream &in, ostream &out) {
}
mpz_clear(max64b);
}
} // namespace tinygb
......@@ -4,6 +4,8 @@
#include <vector>
#include "./polynomial.h"
namespace tinygb {
template <class T>
void F4(const std::vector<polynomial<T> > &sys,
std::vector<polynomial<T> > &GB);
......@@ -11,5 +13,7 @@ void F4(const std::vector<polynomial<T> > &sys,
template <class T>
bool gb_is_minimal(const std::vector<polynomial<T> >&);
} // namespace tinygb
#include "algos.tpp"
#endif // ALGOS_H_
......@@ -8,6 +8,8 @@
#include "./linalg.h"
#include "./timer.h"
namespace tinygb {
// test whether a GB is minimal
template <class T>
bool gb_is_minimal(const vector<polynomial<T> > &GB) {
......@@ -322,3 +324,4 @@ void F4(const vector<polynomial<T> > &sys, vector<polynomial<T> > &res) {
std::reverse(res.begin(), res.end());
log(LOG_DEBUG) << "Is minimal: " << gb_is_minimal<T>(res) << endl;
}
} // namespace tinygb
......@@ -3,6 +3,8 @@
#include <iostream>
namespace tinygb {
enum log_level_t {
LOG_NOTHING,
LOG_ERROR,
......@@ -25,4 +27,6 @@ std::ostream& log(log_level_t level) {
else
return __noostream;
}
} // namespace tinygb
#endif // ANNOTATOR_H_
......@@ -6,6 +6,8 @@
#include "./monomial.h"
#include "./polymat.h"
namespace tinygb {
template <class T>
class critpair;
......@@ -59,7 +61,7 @@ class critpair {
bool operator==(const critpair<T> &cp2) const;
friend std::ostream& operator<< <T>(std::ostream&, const critpair<T>&);
};
} // namespace tinygb
#include "critpair.tpp"
#endif // CRITPAIR_H_
#include <utility>
namespace tinygb {
template <class T>
critpair<T>::critpair(const polymat<T> &p1, const polymat<T> &p2) {
pair<monomial, monomial> c = p1.get_LM().cofact(p2.get_LM());
......@@ -49,3 +51,4 @@ polynomial<T> critpair<T>::eval() const {
R.normalize();
return R;
}
} // namespace tinygb
......@@ -5,6 +5,8 @@
#include <string>
#include "./param.h"
namespace tinygb {
template<class T>
class _Field {
public:
......@@ -30,11 +32,11 @@ class _Field {
static_cast<T*>(this)->inv();
}
};
} // namespace tinygb
#include "fields/gfp_1.inl"
#include "fields/gfp_2.inl"
#include "fields/gfp_05.inl"
#include "fields/gf2_10.inl"
#include "fields/gf2_30.inl"
#endif // FIELD_H_
/* Written by <pierre-jean.spaenlehauer@inria.fr>
*
* ========LICENCE========
* This file is part of tinygb.
*
* tinygb is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* ========LICENCE========
*
*/
#include "mpfq/mpfq_2_10.h"
namespace tinygb {
class GF2_10 : public _Field<GF2_10>
{
public:
......@@ -71,5 +51,6 @@ class GF2_10 : public _Field<GF2_10>
std::ostream& operator<<(std::ostream&, const GF2_10&);
std::istream& operator>>(std::istream&, GF2_10&);
} // namespace tinygb
#include "gf2_10.tpp"
/* Written by <pierre-jean.spaenlehauer@inria.fr>
*
* ========LICENCE========
* This file is part of tinygb.
*
* tinygb is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* ========LICENCE========
*
*/
namespace tinygb {
mpfq_2_10_field GF2_10::k;
......@@ -39,3 +19,4 @@ std::ostream& operator<<(std::ostream& o, const GF2_10 &e)
inline bool GF2_10::is_zero() const
{return mpfq_2_10_is_zero(k,v);}
} // namespace tinygb
/* Written by <pierre-jean.spaenlehauer@inria.fr>
*
* ========LICENCE========
* This file is part of tinygb.
*
* tinygb is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* ========LICENCE========
*
*/
#include "mpfq/mpfq_2_30.h"
class GF2_30 : public _Field<GF2_30>
{
public:
static mpfq_2_30_field k;
mpfq_2_30_elt v;
GF2_30() {
mpfq_2_30_init(k,&v);
mpfq_2_30_set_uipoly(k,v,0);
}
GF2_30(const GF2_30& x) {
mpfq_2_30_init(k, &v);
mpfq_2_30_set(GF2_30::k, v, x.v);
}
GF2_30(unsigned long _v) {
mpfq_2_30_init(k,&v);
mpfq_2_30_set_uipoly(k,v,_v);
}
GF2_30(std::string s) {
mpfq_2_30_init(k,&v);
mpfq_2_30_set_uipoly(GF2_30::k,v,(unsigned)atoi(s.c_str()));
}
~GF2_30() {mpfq_2_30_clear(k,&v);}
GF2_30& operator=(const GF2_30& x) {
mpfq_2_30_init(k, &v);
mpfq_2_30_set(GF2_30::k, v, x.v);
return *this;
}
bool is_zero() const;
friend std::ostream& operator<<(std::ostream&, const GF2_30&);
friend std::istream& operator>>(std::istream&, GF2_30&);
inline void neg() {mpfq_2_30_neg(k,v,v);}
void operator+=(const GF2_30 &a) {mpfq_2_30_add(k,v,v,a.v);}
void operator-=(const GF2_30 &a) {mpfq_2_30_sub(k,v,v,a.v);}
void operator*=(const GF2_30 &a) {mpfq_2_30_mul(k,v,v,a.v);}
void operator/=(const GF2_30 &a) {mpfq_2_30_elt vv; mpfq_2_30_init(k,&vv); mpfq_2_30_inv(k,vv,a.v); mpfq_2_30_mul(k,v,v,vv);mpfq_2_30_clear(k,&vv);}
bool operator==(const GF2_30 &a) const {return mpfq_2_30_cmp(k,v,a.v)==0;}
bool operator!=(const GF2_30 &a) const {return mpfq_2_30_cmp(k,v,a.v)!=0;}
void inv() {mpfq_2_30_inv(k, v, v);}
};
std::ostream& operator<<(std::ostream&, const GF2_30&);
std::istream& operator>>(std::istream&, GF2_30&);
#include "gf2_30.tpp"
/* Written by <pierre-jean.spaenlehauer@inria.fr>
*
* ========LICENCE========
* This file is part of tinygb.
*
* tinygb is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* ========LICENCE========
*
*/
mpfq_2_30_field GF2_30::k;
std::istream& operator>>(std::istream& i, GF2_30& x)
{
std::string s;
i>>s;
x=GF2_30(s);
return i;
}
std::ostream& operator<<(std::ostream& o, const GF2_30 &e)
{
// char buffer[100];
// sprintf(buffer, "%x",(unsigned)(mpfq_2_30_get_uipoly(GF2_30::k,e.v)));
unsigned pol=(unsigned)(mpfq_2_30_get_uipoly(GF2_30::k,e.v));
o<<"(";
for(unsigned i = 0; i<32; ++i)
{
if (pol & 1) o<<"w^"<<i<<"+";
pol>>=1;
}
o<<"0)";
// sprintf(buffer, "%x",);
// return o<<buffer;
return o;
}
inline bool GF2_30::is_zero() const
{return mpfq_2_30_is_zero(k,v);}
/* Written by <pierre-jean.spaenlehauer@inria.fr>
*
* ========LICENCE========
* This file is part of tinygb.
*
* tinygb is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* ========LICENCE========
*
*/
#include "mpfq/mpfq_p_0_5.h"
namespace tinygb {
class GFp_05 : public _Field<GFp_05>
{
public:
......@@ -68,5 +48,6 @@ class GFp_05 : public _Field<GFp_05>
std::ostream& operator<<(std::ostream&, const GFp_05&);
std::istream& operator>>(std::istream&, GFp_05&);
} // namespace tinygb
#include "gfp_05.tpp"
/* Written by <pierre-jean.spaenlehauer@inria.fr>
*
* ========LICENCE========
* This file is part of tinygb.
*
* tinygb is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* ========LICENCE========
*
*/
namespace tinygb {
mpfq_p_0_5_field GFp_05::k;
......@@ -54,3 +34,4 @@ std::istream& operator>>(std::istream& i, GFp_05& x)
mpz_clear(val);
return i;
}
} // namespace tinygb
/* Written by <pierre-jean.spaenlehauer@inria.fr>
*
* ========LICENCE========
* This file is part of tinygb.
*
* tinygb is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* ========LICENCE========
*
*/
#include "mpfq/mpfq_pm_1.h"
namespace tinygb {
class GFp_1 : public _Field<GFp_1>
{
public:
......@@ -73,5 +53,6 @@ class GFp_1 : public _Field<GFp_1>
std::ostream& operator<<(std::ostream&, const GFp_1 &);
std::istream& operator>>(std::istream&, GFp_1&);
} // namespace tinygb
#include "gfp_1.tpp"
/* Written by <pierre-jean.spaenlehauer@inria.fr>
*
* ========LICENCE========
* This file is part of tinygb.
*
* tinygb is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* ========LICENCE========
*
*/
namespace tinygb {
mpfq_pm_1_field GFp_1::k;
......@@ -50,3 +30,4 @@ GFp_1::GFp_1(std::string s) {
mpfq_pm_1_set_mpz(GFp_1::k,v,val);
mpz_clear(val);
}
} // namespace tinygb
/* Written by <pierre-jean.spaenlehauer@inria.fr>
*
* ========LICENCE========
* This file is part of tinygb.
*
* tinygb is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* ========LICENCE========
*
*/
#include "mpfq/mpfq_pm_2.h"
namespace tinygb {
class GFp_2 : public _Field<GFp_2>
{
public:
......@@ -68,5 +48,6 @@ class GFp_2 : public _Field<GFp_2>
std::ostream& operator<<(std::ostream&, const GFp_2 &);
std::istream& operator>>(std::istream&, GFp_2&);
} // namespace tinygb
#include "gfp_2.tpp"
/* Written by <pierre-jean.spaenlehauer@inria.fr>
*
* ========LICENCE========
* This file is part of tinygb.
*
* tinygb is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* ========LICENCE========
*
*/
namespace tinygb {
mpfq_pm_2_field GFp_2::k;
......@@ -57,3 +37,4 @@ GFp_2::GFp_2(std::string s) {
mpfq_pm_2_set_mpz(GFp_2::k,v,val);
mpz_clear(val);
}
} // namespace tinygb
#ifndef LINALG_H_
#define LINALG_H_
#define THRESHOLD_INTERLEAVING 100
#include <sys/types.h>
#include <unistd.h>
#include <list>
......@@ -12,6 +10,10 @@
#include "./polynomial.h"
#include "./timer.h"
#define THRESHOLD_INTERLEAVING 100
namespace tinygb {
template<class T>
class polymat;
......@@ -238,6 +240,7 @@ class matrix_interleaved {
M1->get_rsize(), M2->get_csize(), M1->get_csize());
}
};
} // namespace tinygb
#include "linalg.tpp"
#include "linalg_blas.tpp"
......
......@@ -6,6 +6,8 @@
#include <utility>
#include <vector>
namespace tinygb {
bool operator<(const std::pair<monomial, unsigned> &mm1,
const std::pair<monomial, unsigned> &mm2) {
if (mm2.first < mm1.first)
......@@ -650,4 +652,4 @@ void matrix_rowmajor<T>::multiply_sub(matrix_rowmajor *&D,
iB->to_matrix(B, 1);
delete iB;
}
} // namespace tinygb
#include <fflas-ffpack/fflas-ffpack.h>
#include <gmp.h>
#include <omp.h>
#include <algorithm>
......@@ -7,8 +6,11 @@
#include <cstdlib>
#include <list>
#include <map>
#include "fflas-ffpack/fflas-ffpack.h"
#include "./linalg.h"
namespace tinygb {
// TODO(pj): cast FFLAS<Modular> -> double
// ModularBalanced<double>
......@@ -177,3 +179,4 @@ void sparse_uptriang_matrix<GFp_05>::apply_inverse(matrix_rowmajor<GFp_05> *M) {
delete valB;
mpz_clear(tmp);
}
} // namespace tinygb
......@@ -38,7 +38,7 @@ int main(int argc, char** argv) {
return 0;
break;
case 'v':
GLOBAL_LOG_LEVEL = LOG_INFO;
tinygb::GLOBAL_LOG_LEVEL = tinygb::LOG_INFO;
break;
case 'i':
input = new std::ifstream(optarg);
......@@ -53,8 +53,8 @@ int main(int argc, char** argv) {
abort();
}
log(LOG_INFO) << PACKAGE_STRING << endl;
initF4(*input, *output);
log(tinygb::LOG_INFO) << PACKAGE_STRING << endl;
tinygb::initF4(*input, *output);
if (flag_input_file)
delete input;
......
......@@ -7,6 +7,8 @@
#include "./field.h"
#include "./param.h"
namespace tinygb {
#if SIZE_EXPONENT <= 8
typedef uint8_t expo_int;
#else
......@@ -59,6 +61,7 @@ inline bool operator<(const std::pair<monomial, T> &p1,
const std::pair<monomial, T> &p2) {
return p1.first < p2.first;
}
} // namespace tinygb
#include "monomial.tpp"
#endif // MONOMIAL_H_
......@@ -4,6 +4,8 @@
#include <iostream>
#include <utility>
namespace tinygb {
monomial::monomial(const monomial_carrier _exp) {
#ifndef NBVAR
exp = new expo_int[NBVAR];
......@@ -213,3 +215,4 @@ std::ostream& operator<<(std::ostream& o, const monomial &m) {
if (m.exp[i]) o << "*x" << i << "^" << (unsigned)m.exp[i];