From 821bd5f6ab41fc35b5311fd991b97013dd25b858 Mon Sep 17 00:00:00 2001 From: Winfried Bruns Date: Mon, 20 Jul 2020 15:54:32 +0200 Subject: [PATCH] Clean up of high level interface --- NormalizModule.cpp | 47 ++++++++++++++++++++++++++++++++++++++++++++++ PyNormaliz.py | 37 +++--------------------------------- README.md | 5 +++-- 3 files changed, 53 insertions(+), 36 deletions(-) diff --git a/NormalizModule.cpp b/NormalizModule.cpp index 4e5d7cf..51f722e 100644 --- a/NormalizModule.cpp +++ b/NormalizModule.cpp @@ -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 @@ -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"}, diff --git a/PyNormaliz.py b/PyNormaliz.py index 341e668..77b236f 100644 --- a/PyNormaliz.py +++ b/PyNormaliz.py @@ -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) @@ -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) diff --git a/README.md b/README.md index 5ee10e6..a26d09d 100644 --- a/README.md +++ b/README.md @@ -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 +* Normaliz 3.8.5 or higher The source packages of the Normaliz realeases contain PyNormaliz. @@ -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