Skip to content

Commit

Permalink
Clean up of high level interface
Browse files Browse the repository at this point in the history
  • Loading branch information
Winfried Bruns committed Jul 20, 2020
1 parent d2676fb commit 821bd5f
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 36 deletions.
47 changes: 47 additions & 0 deletions NormalizModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2029,6 +2029,50 @@ static PyObject* NmzGetWeightedEhrhartSeriesExpansion(PyObject* self, PyObject*
FUNC_END
}

static PyObject* NmzGetEhrhartSeriesExpansion(PyObject* self, PyObject* args)
{

FUNC_BEGIN

PyObject* cone = PyTuple_GetItem(args, 0);
PyObject* py_degree = PyTuple_GetItem(args, 1);

if (!is_cone(cone)) {
PyErr_SetString(PyNormaliz_cppError, "First argument must be a cone");
return NULL;
}

if (!PyLong_Check(py_degree)) {
PyErr_SetString(PyNormaliz_cppError,
"Second argument must be a long");
return NULL;
}

long degree = PyLong_AsLong(py_degree);
libnormaliz::HilbertSeries ES;
TempSignalHandler tmpHandler; // use custom signal handler

if (is_cone_mpz(cone)) {
Cone< mpz_class >* cone_ptr = get_cone_mpz(cone);
ES = cone_ptr->getEhrhartSeries();
}
else if (is_cone_long(cone)) {
Cone< long long >* cone_ptr = get_cone_long(cone);
ES = cone_ptr->getEhrhartSeries();
}
else {
PyErr_SetString(
PyNormaliz_cppError,
"Ehrhart series expansion not available for renf cone");
return NULL;
}

ES.set_expansion_degree(degree);
return NmzVectorToPyList(ES.getExpansion());

FUNC_END
}

/***************************************************************************
*
* Set number of threads
Expand Down Expand Up @@ -2244,6 +2288,9 @@ static PyMethodDef PyNormaliz_cppMethods[] = {
{"NmzGetHilbertSeriesExpansion",
(PyCFunction)NmzGetHilbertSeriesExpansion, METH_VARARGS,
"Returns expansion of the hilbert series"},
{"NmzGetEhrhartSeriesExpansion",
(PyCFunction)NmzGetEhrhartSeriesExpansion, METH_VARARGS,
"Returns expansion of the Ehrhart series"},
{"NmzGetWeightedEhrhartSeriesExpansion",
(PyCFunction)NmzGetWeightedEhrhartSeriesExpansion, METH_VARARGS,
"Returns expansion of the weighted Ehrhart series"},
Expand Down
37 changes: 3 additions & 34 deletions PyNormaliz.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,40 +65,6 @@ def ProjectCone(self, **kwargs):
return_cone.cone = new_inner_cone
return return_cone

def EuclideanVolume(self, **kwargs):
input_list = self.__process_keyword_args(kwargs)
input_list.append("Volume")
PyNormaliz_cpp.NmzCompute(self.cone, input_list)
return PyNormaliz_cpp.NmzResult(self.cone, "EuclideanVolume")

def HilbertSeries(self, **kwargs):
try:
as_hsop = kwargs["HSOP"]
except KeyError:
as_hsop = 28
input_list = self.__process_keyword_args(kwargs)
input_list.append("HilbertSeries")
PyNormaliz_cpp.NmzCompute(self.cone, input_list)
if as_hsop == 28:
return PyNormaliz_cpp.NmzHilbertSeries(self.cone)
if type(as_hsop) == bool:
return PyNormaliz_cpp.NmzHilbertSeries(self.cone, as_hsop)
raise TypeError("If HSOP is given, it must be True or False")

def EhrhartSeries(self, **kwargs):
try:
as_hsop = kwargs["HSOP"]
except KeyError:
as_hsop = 28
input_list = self.__process_keyword_args(kwargs)
input_list.append("EhrhartSeries")
PyNormaliz_cpp.NmzCompute(self.cone, input_list)
if as_hsop == 28:
return PyNormaliz_cpp.NmzHilbertSeries(self.cone)
if type(as_hsop) == bool:
return PyNormaliz_cpp.NmzHilbertSeries(self.cone, as_hsop)
raise TypeError("If HSOP is given, it must be True or False")

def Polynomial(self, **kwargs):
return PyNormaliz_cpp.NmzGetPolynomial(self.cone)

Expand All @@ -115,6 +81,9 @@ def SymmetrizedCone(self, **kwargs):

def HilbertSeriesExpansion(self,degree):
return NmzGetHilbertSeriesExpansion(self.cone,degree)

def EhrhartSeriesExpansion(self,degree):
return NmzGetEhrhartSeriesExpansion(self.cone,degree)

def WeightedEhrhartSeriesExpansion(self,degree):
return NmzGetWeightedEhrhartSeriesExpansion(self.cone,degree)
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ For a first example, see [this introduction](doc/PyNormaliz_Tutorial.pdf) by Ric
## Requirements

* python 2.7 or higher or python 3.4 or higher
* Normaliz 3.8.3 or higher <https://github.com/Normaliz/Normaliz/releases>
* Normaliz 3.8.5 or higher <https://github.com/Normaliz/Normaliz/releases>

The source packages of the Normaliz realeases contain PyNormaliz.

Expand Down Expand Up @@ -89,7 +89,8 @@ By using Python functions, the functionality of Normaliz can be extended. For ex

def intersection(cone1, cone2):
intersection_ineq = cone1.SupportHyperplanes()+cone2.SupportHyperplanes()
C = Cone(inequalities = intersection_ineq)
intersection_eq = cone1.Equations()+cone2.Equations()
C = Cone(inequalities = intersection_ineq, equations = intersection_eq)
return C

computes the intersection of two cones. So
Expand Down

0 comments on commit 821bd5f

Please sign in to comment.