@@ -45,6 +45,8 @@ using std::vector;
4545
4646typedef int py_size_t ;
4747
48+ #include < fstream>
49+
4850/* **************************************************************************
4951 *
5052 * Macros for exception handling
@@ -177,11 +179,11 @@ static PyObject* CallPythonFuncOnOneArg(PyObject* function, PyObject* single_arg
177179#ifndef NMZ_RELEASE
178180static_assert (
179181 false ,
180- " Your Normaliz version (unknown) is to old! Update to 3.9.0 or newer." );
182+ " Your Normaliz version (unknown) is too old! Update to 3.9.2 or newer." );
181183#endif
182- #if NMZ_RELEASE < 30900
184+ #if NMZ_RELEASE < 30902
183185static_assert (false ,
184- " Your Normaliz version is to old! Update to 3.9.0 or newer." );
186+ " Your Normaliz version is too old! Update to 3.9.2 or newer." );
185187#endif
186188
187189/* **************************************************************************
@@ -1097,6 +1099,61 @@ static PyObject* _NmzConeIntern_renf(PyObject* kwargs)
10971099}
10981100#endif
10991101
1102+ static PyObject* _NmzConeFromFile (PyObject* kwargs)
1103+ {
1104+
1105+ static const char * from_file = " file" ;
1106+ PyObject* create_from_file = StringToPyUnicode (from_file);
1107+ PyObject* FileName = PyDict_GetItem (kwargs, create_from_file);
1108+ string project (PyUnicodeToString (FileName));
1109+
1110+ std::string name_in = project + " .in" ;
1111+ const char * file_in = name_in.c_str ();
1112+
1113+ #ifdef ENFNORMALIZ
1114+ std::ifstream in;
1115+ in.open (file_in, std::ifstream::in);
1116+ if (!in.is_open ()) {
1117+ string message = " error: Failed to open file " + name_in;
1118+ throw libnormaliz::BadInputException (message);
1119+ }
1120+ bool number_field_in_input = false ;
1121+ std::string poly, var, emb;
1122+ std::string test;
1123+ while (in.good ()){
1124+ in >> test;
1125+ if (test == " number_field" ){
1126+ number_field_in_input = true ;
1127+ libnormaliz::read_number_field_strings (in, poly, var, emb);
1128+ break ;
1129+ }
1130+ }
1131+ in.close ();
1132+
1133+ if (number_field_in_input){
1134+ boost::intrusive_ptr<const renf_class> renf = renf_class::make (poly, var, emb);
1135+ const renf_class* my_renf = renf.get ();
1136+ Cone< renf_elem_class >* C = new Cone< renf_elem_class >(project);
1137+ PyObject* return_container = pack_cone (C, my_renf);
1138+ return return_container;
1139+ }
1140+ #endif
1141+
1142+ static const char * string_for_long_long = " CreateAsLongLong" ;
1143+ PyObject* create_as_long_long = StringToPyUnicode (string_for_long_long);
1144+
1145+ if (PyDict_Contains (kwargs, create_as_long_long) == 1 ) {
1146+ Cone< long long >* C = new Cone< long long >(project);
1147+ PyObject* return_container = pack_cone (C);
1148+ return return_container;
1149+ }
1150+ else {
1151+ Cone< mpz_class >* C = new Cone< mpz_class >(project);
1152+ PyObject* return_container = pack_cone (C);
1153+ return return_container;
1154+ }
1155+ }
1156+
11001157/*
11011158@Name NmzCone
11021159@Arguments <keywords>
@@ -1112,7 +1169,12 @@ to machine integers instead of arbitrary precision numbers.
11121169static PyObject* _NmzCone (PyObject* self, PyObject* args, PyObject* kwargs)
11131170{
11141171 FUNC_BEGIN
1115-
1172+ static const char * from_file = " file" ;
1173+ PyObject* create_from_file = StringToPyUnicode (from_file);
1174+ if (kwargs != NULL && PyDict_Contains (kwargs, create_from_file) == 1 ) {
1175+ return _NmzConeFromFile (kwargs);
1176+ }
1177+
11161178 static const char * string_for_long = " CreateAsLongLong" ;
11171179 PyObject* create_as_long_long = StringToPyUnicode (string_for_long);
11181180#ifdef ENFNORMALIZ
@@ -2479,7 +2541,50 @@ static PyObject* NmzWriteOutputFile(PyObject* self, PyObject* args)
24792541
24802542/* **************************************************************************
24812543 *
2482- * Get renf precision
2544+ * Write file with precomputed data
2545+ *
2546+ ***************************************************************************/
2547+
2548+ static PyObject* NmzWritePrecompData (PyObject* self, PyObject* args)
2549+ {
2550+ FUNC_BEGIN
2551+
2552+ if ((!PyTuple_Check (args)) || (PyTuple_Size (args) != 2 )) {
2553+ throw PyNormalizInputException (
2554+ " The arguments must be a cone and a string" );
2555+ return NULL ;
2556+ }
2557+
2558+ PyObject* cone_py = PyTuple_GetItem (args, 0 );
2559+ PyObject* filename_py = PyTuple_GetItem (args, 1 );
2560+
2561+ string filename = PyUnicodeToString (filename_py);
2562+
2563+ if (is_cone_mpz (cone_py)) {
2564+ Cone< mpz_class >* cone = get_cone_mpz (cone_py);
2565+ cone->write_precomp_for_input (filename);
2566+ Py_RETURN_TRUE;
2567+ }
2568+ if (is_cone_long (cone_py)) {
2569+ Cone< long long >* cone = get_cone_long (cone_py);
2570+ cone->write_precomp_for_input (filename);
2571+ Py_RETURN_TRUE;
2572+ }
2573+ #ifdef ENFNORMALIZ
2574+ if (is_cone_renf (cone_py)) {
2575+ Cone< renf_elem_class >* cone = get_cone_renf (cone_py);
2576+ cone->write_precomp_for_input (filename);
2577+ Py_RETURN_TRUE;
2578+ }
2579+ #endif
2580+ Py_RETURN_FALSE;
2581+
2582+ FUNC_END
2583+ }
2584+
2585+ /* **************************************************************************
2586+ *
2587+ * Get renf minpoly and precision
24832588 *
24842589 ***************************************************************************/
24852590
@@ -2501,6 +2606,7 @@ static PyObject* NmzGetRenfInfo(PyObject* self, PyObject* args)
25012606 );
25022607 return NULL ;
25032608 }
2609+
25042610 const renf_class* renf = get_cone_renf_renf (cone_py);
25052611 std::string minpoly_str;
25062612 minpoly_str = fmpq_poly_get_str_pretty (renf->get_renf ()->nf ->pol , renf->gen_name ().c_str ());
@@ -2514,6 +2620,44 @@ static PyObject* NmzGetRenfInfo(PyObject* self, PyObject* args)
25142620 FUNC_END
25152621}
25162622
2623+ /* **************************************************************************
2624+ *
2625+ * Get name of field generator
2626+ *
2627+ ***************************************************************************/
2628+
2629+ static PyObject* NmzFieldGenName (PyObject* self, PyObject* args)
2630+ {
2631+ FUNC_BEGIN
2632+
2633+ if ( (!PyTuple_Check (args)) || (PyTuple_Size (args) != 1 ) ){
2634+ throw PyNormalizInputException (
2635+ " Only one argument allowed"
2636+ );
2637+ return NULL ;
2638+ }
2639+ PyObject* cone_py = PyTuple_GetItem (args, 0 );
2640+
2641+ std::string gen_name_string = " " ;
2642+
2643+ if (is_cone_mpz (cone_py)) {
2644+ return PyUnicode_FromString (gen_name_string.c_str ());
2645+ }
2646+ if (is_cone_long (cone_py)) {
2647+ return PyUnicode_FromString (gen_name_string.c_str ());
2648+ }
2649+ #ifdef ENFNORMALIZ
2650+ if (is_cone_renf (cone_py)) {
2651+ Cone< renf_elem_class >* cone_ptr = get_cone_renf (cone_py);
2652+ gen_name_string = cone_ptr->getRenfGenerator ();
2653+ return PyUnicode_FromString (gen_name_string.c_str ());
2654+ }
2655+
2656+ #endif
2657+
2658+ FUNC_END
2659+ }
2660+
25172661/* **************************************************************************
25182662 *
25192663 * Python init stuff
@@ -2598,8 +2742,14 @@ static PyMethodDef PyNormaliz_cppMethods[] = {
25982742
25992743 {" NmzWriteOutputFile" , (PyCFunction)NmzWriteOutputFile, METH_VARARGS,
26002744 " Prints the Normaliz cone output into a file" },
2745+ {" NmzWritePrecompData" , (PyCFunction)NmzWritePrecompData, METH_VARARGS,
2746+ " Prints the Normaliz cone precomputed data for further input" },
2747+
26012748 {" NmzGetRenfInfo" , (PyCFunction)NmzGetRenfInfo, METH_VARARGS,
26022749 " Outputs info of the number field associated to a renf cone" },
2750+ {" NmzFieldGenName" , (PyCFunction)NmzFieldGenName, METH_VARARGS,
2751+ " Returns name of field generator" },
2752+
26032753 {" NmzModifyCone" , (PyCFunction)_NmzModify_Outer, METH_VARARGS,
26042754 " Modifies a given input property of a cone using a new matrix" },
26052755 {
0 commit comments