Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Normaliz/PyNormaliz
Browse files Browse the repository at this point in the history
  • Loading branch information
Winfried Bruns committed Aug 30, 2021
2 parents d9869bc + d9abe2a commit f0b1ee4
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 84 deletions.
31 changes: 11 additions & 20 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,51 +7,44 @@ on:
jobs:
our-installation:
runs-on: ubuntu-latest
env:
env:
EANTIC: yes
NAUTY: yes
COCOALIB: yes
steps:
- uses: actions/checkout@v2
- name: "Install prerequisites and Normaliz"
run: |
sudo apt-get install libgmp-dev
sudo apt-get install libpython3-dev
# pip3 install coverage
# pip install setuptools
pip3 install setuptools
# sudo apt-get install libgmp-dev libpython3-dev python3-setuptools
# (packages already installed in GitHub's Ubuntu)
./.ci-install-normaliz.sh
- name: "Install PyNormaliz"
run: |
./.ci-install-pynormaliz.sh
- name: "Run tests"
run: |
./.ci-run-tests.sh
no-eantic:
runs-on: ubuntu-latest
env:
env:
EANTIC: no
NAUTY: yes
COCOALIB: yes
steps:
- uses: actions/checkout@v2
- name: "Install prerequisites and Normaliz"
run: |
sudo apt-get install libgmp-dev
sudo apt-get install libpython3-dev
# pip2 install coverage
# pip3 install coverage
# pip install setuptools
pip3 install setuptools
# sudo apt-get install libgmp-dev libpython3-dev python3-setuptools
# (packages already installed in GitHub's Ubuntu)
./.ci-install-normaliz.sh
- name: "Install PyNormaliz"
run: |
./.ci-install-pynormaliz.sh
- name: "Run tests"
run: |
./.ci-run-tests.sh
mac-os:
runs-on: macos-latest
env:
Expand All @@ -65,7 +58,7 @@ jobs:
python-version: '3.7'
- name: "Setup compiler and build automake"
run: |
brew reinstall llvm automake
brew reinstall llvm automake
- name: "Install Python prerequisites"
run: |
pip3 install coverage
Expand All @@ -82,7 +75,7 @@ jobs:
# eantic-nauty:
# runs-on: ubuntu-latest
# env:
# env:
# EANTIC: yes
# NAUTY: yes
# COCOALIB: no
Expand All @@ -91,7 +84,7 @@ jobs:
# - uses: actions/checkout@v2
# - name: "Install prerequisites and Normaliz"
# run: |
# sudo apt-get install libgmp-dev libflint-dev
# sudo apt-get install libgmp-dev libflint-dev
# export PIP=$(which pip) # workaround so that sudo uses correct pip
# pip install coverage
# pip3 install coverage
Expand All @@ -115,5 +108,3 @@ jobs:
# python -c "import PyNormaliz"
# - name: "Upload coverage data to Codecov"
# uses: codecov/codecov-action@v1


80 changes: 40 additions & 40 deletions NormalizModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ using std::string;
#ifdef ENFNORMALIZ
using eantic::renf_elem_class;
using eantic::renf_class;
#endif
#endif

using libnormaliz::Cone;
// using libnormaliz::ConeProperty;
Expand Down Expand Up @@ -198,7 +198,7 @@ static string PyUnicodeToString(PyObject* in)
}
#if PY_MAJOR_VERSION >= 3
string out = "";
int length = PyUnicode_GET_SIZE(in);
int length = PyUnicode_GET_LENGTH(in);
for (int i = 0; i < length; i++) {
out += PyUnicode_READ_CHAR(in, i);
}
Expand Down Expand Up @@ -361,7 +361,7 @@ static PyObject* NmzToPyNumber(double in)
PyObject* x = PyFloat_FromDouble(in);
if(FloatHandler == NULL)
return x;

return CallPythonFuncOnOneArg(FloatHandler, x);
}

Expand Down Expand Up @@ -466,7 +466,7 @@ static bool prepare_nf_input(vector< vector< NumberFieldElem > >& out,
PyObject* current_element = PySequence_GetItem(current_row, j);
bool current_res;
NumberFieldElem current_elem;

if (PyList_CheckExact(current_element) || PyTuple_CheckExact(current_element)) {
vector< mpq_class > current_vector;
current_res = PyListToNmz(current_vector, current_element);
Expand All @@ -480,7 +480,7 @@ static bool prepare_nf_input(vector< vector< NumberFieldElem > >& out,
// current_elem = PyUnicodeToString(current_element);
}
if (PyFloat_Check(current_element)){
throw PyNormalizInputException("Nonintegral numbers must be given as strings");
throw PyNormalizInputException("Nonintegral numbers must be given as strings");
}
if (PyLong_Check(current_element)) {
mpq_class tmp;
Expand Down Expand Up @@ -626,7 +626,7 @@ static PyObject* NmzTriangleListToPyList(
PyList_SetItem(triple, 2, NmzToPyNumber(libnormaliz::bool_to_bitset(in.first[i].Excluded)));
PyList_SetItem(M, i, triple);
}

PyObject* Tr = PyList_New(2);
PyList_SetItem(Tr, 0,M);
PyList_SetItem(Tr, 1,NmzMatrixToPyList(in.second.get_elements()));
Expand Down Expand Up @@ -716,40 +716,40 @@ NmzAutomorphismsToPython(const AutomorphismGroup< Integer >& grp)
{
int list_size = 6;
if(grp.IsInput() || grp.IsAmbient())
list_size =7;
list_size =7;

PyObject* list = PyList_New(list_size);

PyList_SetItem(list, 0, NmzToPyNumber(grp.getOrder()));
PyList_SetItem(list, 1, BoolToPyBool(grp.IsIntegralityChecked()));
PyList_SetItem(list, 2, BoolToPyBool(grp.IsIntegral()));

if(grp.IsInput() || grp.IsAmbient()){
PyList_SetItem(list, 6, NmzMatrixToPyList(grp.getGens().get_elements()));
PyObject* current = PyList_New(2);
PyObject* current = PyList_New(2);
PyList_SetItem(current, 0, NmzMatrixToPyList(grp.getGensPerms()));
PyList_SetItem(current, 1, NmzMatrixToPyList(grp.getGensOrbits()));
PyList_SetItem(list, 3, current);

current = PyList_New(2);
vector<vector<long> > Empty;
PyList_SetItem(current, 0, NmzMatrixToPyList(Empty));
PyList_SetItem(current, 1, NmzMatrixToPyList(Empty));
PyList_SetItem(list, 4, current);

if(grp.IsAmbient()){
current = PyList_New(2);
PyList_SetItem(current, 0, NmzMatrixToPyList(grp.getLinFormsPerms()));
PyList_SetItem(current, 1, NmzMatrixToPyList(grp.getLinFormsOrbits()));
PyList_SetItem(list, 5, current);
PyList_SetItem(list, 5, current);
}
else{
vector<vector<long> > Empty;
PyList_SetItem(current, 0, NmzMatrixToPyList(Empty));
PyList_SetItem(current, 1, NmzMatrixToPyList(Empty));
PyList_SetItem(list, 5, current);
}
}
PyList_SetItem(list, 5, current);
}
}
else{
PyObject* current = PyList_New(2);
PyList_SetItem(current, 0, NmzMatrixToPyList(grp.getExtremeRaysPerms()));
Expand All @@ -766,7 +766,7 @@ NmzAutomorphismsToPython(const AutomorphismGroup< Integer >& grp)
NmzMatrixToPyList(grp.getSupportHyperplanesPerms()));
PyList_SetItem(current, 1,
NmzMatrixToPyList(grp.getSupportHyperplanesOrbits()));
PyList_SetItem(list, 5, current);
PyList_SetItem(list, 5, current);
}

return list;
Expand Down Expand Up @@ -928,7 +928,7 @@ static PyObject* NmzListConeProperties(PyObject* args)

ConeProperties goals = libnormaliz::all_goals();
ConeProperties options = libnormaliz::all_options();

int number_goals = goals.count();
int number_options = options.count();

Expand Down Expand Up @@ -1050,7 +1050,7 @@ static PyObject* _NmzConeIntern_renf(PyObject* kwargs)
string poly = PyUnicodeToString(PySequence_GetItem(number_field_data, 0));
string var = PyUnicodeToString(PySequence_GetItem(number_field_data, 1));
string emb = PyUnicodeToString(PySequence_GetItem(number_field_data, 2));
// boost::intrusive_ptr<const renf_class>* renf = new boost::intrusive_ptr<const renf_class>;
// boost::intrusive_ptr<const renf_class>* renf = new boost::intrusive_ptr<const renf_class>;
boost::intrusive_ptr<const renf_class> renf = renf_class::make(poly, var, emb);
const renf_class* my_renf = renf.get();

Expand Down Expand Up @@ -1089,7 +1089,7 @@ static PyObject* _NmzConeIntern_renf(PyObject* kwargs)

Cone< renf_elem_class >* C = new Cone< renf_elem_class >(input);
C->setRenf(my_renf);

PyObject* return_container = pack_cone(C, my_renf);

return return_container;
Expand Down Expand Up @@ -1490,7 +1490,7 @@ PyObject* NmzSetGrading_inner(Cone< renf_elem_class >* cone, PyObject* grad)
vector< renf_elem_class > grad_renf;
vector<vector< renf_elem_class> > grad_mat; // a cheap way to convert vectors
PyObject* PyHelpMat = PyList_New(1); // better: rebuild conversion to renf
PyList_SetItem(PyHelpMat, 0, grad);
PyList_SetItem(PyHelpMat, 0, grad);
prepare_nf_input(grad_mat, PyHelpMat,cone->getRenf());
grad_renf = grad_mat[0];

Expand Down Expand Up @@ -1523,7 +1523,7 @@ static PyObject* NmzSetGrading(PyObject* self, PyObject* args)
}
#endif
FUNC_END

Py_RETURN_NONE;
}

Expand All @@ -1547,7 +1547,7 @@ static PyObject* NmzSetProjectionCoords_inner(Cone< Integer >* cone, PyObject* c
if(coords_c[i]!=0 && coords_c[i]!=1)
PyErr_SetString(PyNormaliz_cppError, "Projection coordinates must be 0 or 1");
}

cone->resetProjectionCoords(coords_c);
Py_RETURN_NONE;
}
Expand All @@ -1559,7 +1559,7 @@ PyObject* NmzSetProjectionCoords_inner(Cone< renf_elem_class >* cone, PyObject*
vector< renf_elem_class > coords_renf;
vector<vector< renf_elem_class> > coords_mat; // a cheap way to convert vectors
PyObject* PyHelpMat = PyList_New(1); // better: rebuild conversion to renf
PyList_SetItem(PyHelpMat, 0, coords);
PyList_SetItem(PyHelpMat, 0, coords);
prepare_nf_input(coords_mat, PyHelpMat,cone->getRenf());
coords_renf = coords_mat[0];

Expand Down Expand Up @@ -1650,19 +1650,19 @@ _NmzResultImpl(Cone< Integer >* C, PyObject* prop_obj, const void* nf = nullptr)
libnormaliz::OutputType::Enum outputtype = libnormaliz::output_type(p);

switch (p) {

case libnormaliz::ConeProperty::Triangulation:{
return NmzTriangleListToPyList< Integer >(C->getTriangulation());
}

case libnormaliz::ConeProperty::ConeDecomposition:{
return NmzTriangleListToPyList< Integer >(C->getConeDecomposition());
}

case libnormaliz::ConeProperty::AllGeneratorsTriangulation:
return NmzTriangleListToPyList< Integer >(C->getTriangulation(
libnormaliz::ConeProperty::AllGeneratorsTriangulation));

case libnormaliz::ConeProperty::LatticePointTriangulation:
return NmzTriangleListToPyList< Integer >(C->getTriangulation(
libnormaliz::ConeProperty::LatticePointTriangulation));
Expand Down Expand Up @@ -1740,19 +1740,19 @@ _NmzResultImpl(Cone< Integer >* C, PyObject* prop_obj, const void* nf = nullptr)
case libnormaliz::ConeProperty::WeightedEhrhartQuasiPolynomial:
return NmzWeightedEhrhartQuasiPolynomialToPyList< mpz_class >(
C->getIntData());

case libnormaliz::ConeProperty::ClassGroup:
return NmzVectorToPyList(C->getClassGroup());

case libnormaliz::ConeProperty::FVector:
return NmzVectorToPyList(C->getFVector());

case libnormaliz::ConeProperty::DualFVector:
return NmzVectorToPyList(C->getDualFVector());

case libnormaliz::ConeProperty::FaceLattice:
return NmzFacelatticeToPython(C->getFaceLattice());

case libnormaliz::ConeProperty::DualFaceLattice:
return NmzFacelatticeToPython(C->getDualFaceLattice());

Expand All @@ -1763,7 +1763,7 @@ _NmzResultImpl(Cone< Integer >* C, PyObject* prop_obj, const void* nf = nullptr)
case libnormaliz::ConeProperty::AmbientAutomorphisms:
return NmzAutomorphismsToPython(C->getAutomorphismGroup(
libnormaliz::ConeProperty::AmbientAutomorphisms));

case libnormaliz::ConeProperty::InputAutomorphisms:
return NmzAutomorphismsToPython(C->getAutomorphismGroup(
libnormaliz::ConeProperty::InputAutomorphisms));
Expand Down Expand Up @@ -1826,7 +1826,7 @@ static PyObject* _NmzResult(PyObject* self, PyObject* args, PyObject* kwargs)
{

FUNC_BEGIN

RationalHandler = NULL;
FloatHandler = NULL;

Expand All @@ -1836,10 +1836,10 @@ NumberfieldElementHandler = NULL;

VectorHandler = NULL;
MatrixHandler = NULL;

if(PyTuple_Size(args)!=2){
PyErr_SetString(PyNormaliz_cppError, "Exactly one computation goal required for NmzResult");
return NULL;
return NULL;
}

PyObject* cone = PyTuple_GetItem(args, 0);
Expand Down Expand Up @@ -2059,19 +2059,19 @@ static PyObject* NmzSetPolynomial(PyObject* self, PyObject* args)
PyErr_SetString(PyNormaliz_cppError, "First argument must be a cone");
return NULL;
}

TempSignalHandler tmpHandler; // use custom signal handler

PyObject* poly_pi = PyTuple_GetItem(args, 1);

if(!string_check(poly_pi)){
PyErr_SetString(PyNormaliz_cppError, "Polynomual must be given as a string");
return NULL;
}
TempSignalHandler tmpHandler1; // use custom signal handler

string polynomial = PyUnicodeToString(poly_pi);

if (is_cone_mpz(cone)) {
Cone< mpz_class >* cone_ptr = get_cone_mpz(cone);
cone_ptr->setPolynomial(polynomial);
Expand Down Expand Up @@ -2309,7 +2309,7 @@ static PyObject* NmzGetWeightedEhrhartSeriesExpansion(PyObject* self, PyObject*
PyList_SetItem(return_list, 0, NmzVectorToPyList(ES.first.getExpansion()));
PyList_SetItem(return_list, 1, NmzToPyNumber(ES.second));
return return_list;

FUNC_END
}

Expand Down Expand Up @@ -2570,7 +2570,7 @@ static PyMethodDef PyNormaliz_cppMethods[] = {
(PyCFunction)NmzSetNumberOfNormalizThreads, METH_VARARGS,
"Sets the Normaliz thread limit"},
{"NmzSetNrCoeffQuasiPol", (PyCFunction)NmzSetNrCoeffQuasiPol,
METH_VARARGS, "Sets the number of computed coefficients for the quasi-polynomial"},
METH_VARARGS, "Sets the number of computed coefficients for the quasi-polynomial"},
{"NmzSetDecimalDigits", (PyCFunction)NmzSetDecimalDigits,
METH_VARARGS, "Sets the number of decimal digits for fixed precision"},
{"NmzSetPolynomial", (PyCFunction)NmzSetPolynomial,
Expand Down
Loading

0 comments on commit f0b1ee4

Please sign in to comment.