Skip to content

Commit 95d4ad0

Browse files
committed
Towards 2.23
1 parent fd1a24a commit 95d4ad0

File tree

3 files changed

+88
-6
lines changed

3 files changed

+88
-6
lines changed

NormalizModule.cpp

Lines changed: 83 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ using libnormaliz::Cone;
2828
using libnormaliz::ConeProperties;
2929
using libnormaliz::Sublattice_Representation;
3030
using libnormaliz::Type::InputType;
31+
// using libnormaliz::BoolParam::Param;
3132
using libnormaliz::AutomorphismGroup;
3233
using libnormaliz::Matrix;
3334

@@ -180,11 +181,11 @@ static PyObject* CallPythonFuncOnOneArg(PyObject* function, PyObject* single_arg
180181
#ifndef NMZ_RELEASE
181182
static_assert(
182183
false,
183-
"Your Normaliz version (unknown) is too old! Update to 3.10.4 or newer.");
184+
"Your Normaliz version (unknown) is too old! Update to 3.11.0 or newer.");
184185
#endif
185-
#if NMZ_RELEASE < 31004
186+
#if NMZ_RELEASE < 31100
186187
static_assert(false,
187-
"Your Normaliz version is too old! Update to 3.10.4 or newer.");
188+
"Your Normaliz version is too old! Update to 3.11.0 or newer.");
188189
#endif
189190

190191
/***************************************************************************
@@ -1631,6 +1632,82 @@ static PyObject* NmzSetGrading(PyObject* self, PyObject* args)
16311632
Py_RETURN_NONE;
16321633
}
16331634

1635+
/***************************************************************************
1636+
*
1637+
* Boolean parameters
1638+
*
1639+
***************************************************************************/
1640+
template < typename Integer >
1641+
static PyObject* NmzSetBoolParam_inner(Cone<Integer>* cone_ptr, const libnormaliz::BoolParam::Param bool_param, bool value){
1642+
1643+
if(bool_param == libnormaliz::BoolParam::verbose)
1644+
cone_ptr->setVerbose(value);
1645+
1646+
if(bool_param == libnormaliz::BoolParam::nonnegative)
1647+
cone_ptr->setNonnegative(value);
1648+
1649+
if(bool_param == libnormaliz::BoolParam::total_degree)
1650+
cone_ptr->setTotalDegree(value);
1651+
1652+
if(bool_param == libnormaliz::BoolParam::convert_equations)
1653+
cone_ptr->setConvertEquations(value);
1654+
1655+
if(bool_param == libnormaliz::BoolParam::no_coord_transf)
1656+
cone_ptr->setNoCoordTransf(value);
1657+
1658+
1659+
if(bool_param == libnormaliz::BoolParam::list_polynomials)
1660+
cone_ptr->setListPolynomials(value);
1661+
1662+
if(bool_param == libnormaliz::BoolParam::no_pos_orth_def)
1663+
cone_ptr->setNoPosOrthDef(value);
1664+
1665+
if(bool_param == libnormaliz::BoolParam::not_a_bool_param)
1666+
throw libnormaliz::BadInputException("Invalid boolean parameter");
1667+
1668+
Py_RETURN_NONE;
1669+
}
1670+
1671+
static PyObject* NmzSetBoolParam(PyObject* self, PyObject* args)
1672+
{
1673+
FUNC_BEGIN
1674+
PyObject* cone = PyTuple_GetItem(args, 0);
1675+
PyObject* bool_param_py = PyTuple_GetItem(args, 1);
1676+
PyObject* bool_value_py = PyTuple_GetItem(args,2);
1677+
if (!is_cone(cone)) {
1678+
PyErr_SetString(PyNormaliz_cppError, "First argument must be a cone");
1679+
return NULL;
1680+
}
1681+
1682+
string param_as_string = PyUnicodeToString(bool_param_py);
1683+
libnormaliz::BoolParam::Param bool_param = libnormaliz::to_boolpar(param_as_string);
1684+
1685+
if (bool_value_py != Py_True && bool_value_py != Py_False) {
1686+
PyErr_SetString(PyNormaliz_cppError,
1687+
"Argument must be True or False");
1688+
return NULL;
1689+
}
1690+
bool bool_value = (bool_value_py == Py_True);
1691+
1692+
if (is_cone_long(cone)) {
1693+
Cone< long long >* cone_ptr = get_cone_long(cone);
1694+
return NmzSetBoolParam_inner(cone_ptr, bool_param, bool_value);
1695+
}
1696+
if (is_cone_mpz(cone)) {
1697+
Cone< mpz_class >* cone_ptr = get_cone_mpz(cone);
1698+
return NmzSetBoolParam_inner(cone_ptr, bool_param, bool_value);
1699+
}
1700+
#ifdef ENFNORMALIZ
1701+
if (is_cone_renf(cone)) {
1702+
Cone< renf_elem_class >* cone_ptr = get_cone_renf(cone);
1703+
return NmzSetBoolParam_inner(cone_ptr, bool_param, bool_value);
1704+
}
1705+
#endif
1706+
FUNC_END
1707+
Py_RETURN_NONE;
1708+
}
1709+
1710+
16341711
/***************************************************************************
16351712
*
16361713
* NmzSetProjectionCoords
@@ -1667,7 +1744,7 @@ PyObject* NmzSetProjectionCoords_inner(Cone< renf_elem_class >* cone, PyObject*
16671744
prepare_nf_input(coords_mat, PyHelpMat,cone->getRenf());
16681745
coords_renf = coords_mat[0];
16691746

1670-
cone->resetGrading(coords_renf);
1747+
cone->resetProjectionCoords(coords_renf);
16711748
Py_RETURN_NONE;
16721749
}
16731750
#endif
@@ -3017,6 +3094,8 @@ static PyMethodDef PyNormaliz_cppMethods[] = {
30173094
"Check if property is computed "},
30183095
{"NmzSetGrading", (PyCFunction)NmzSetGrading, METH_VARARGS,
30193096
"Reset the grading of a cone"},
3097+
{"NmzSetBoolParam", (PyCFunction)NmzSetBoolParam, METH_VARARGS,
3098+
"Swts boolean parameters of a cone"},
30203099
{"NmzSetProjectionCoords", (PyCFunction)NmzSetProjectionCoords, METH_VARARGS,
30213100
"Reset the projection coordinates"},
30223101
{"NmzResult", (PyCFunction)_NmzResult, METH_VARARGS | METH_KEYWORDS,

PyNormaliz.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,9 @@ def IsComputed(self, *args):
351351
def SetVerbose(self, verbose=True):
352352
return NmzSetVerbose(self.cone, verbose)
353353

354+
def SetBoolParam(self, bool_param, bool_value = True):
355+
return NmzSetBoolParam(self.cone,bool_param, bool_value)
356+
354357
# This one is not like the others!
355358
def IntegerHull(self):
356359
input_list=["IntegerHull"]
@@ -437,7 +440,7 @@ def _generic_getter(self, name, **kwargs):
437440
return PyNormaliz_cpp.NmzResult(self.cone, name,RationalHandler = our_rat_handler, \
438441
NumberfieldElementHandler=our_renf_handler, FloatHandler = our_float_handler)
439442

440-
# Generate getters for a bunch of Normalize properties
443+
# Generate getters for a bunch of Normaliz properties
441444
def add_dyn_getter(name):
442445
if hasattr(Cone, name):
443446
return

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = PyNormaliz
3-
version = 2.22
3+
version = 2.23
44
description = An interface to Normaliz
55
author = Sebastian Gutsche, Richard Sieg, Winfried Bruns
66
author_email = wbruns@uos.de

0 commit comments

Comments
 (0)