@@ -45,6 +45,8 @@ using std::vector;
45
45
46
46
typedef int py_size_t ;
47
47
48
+ #include < fstream>
49
+
48
50
/* **************************************************************************
49
51
*
50
52
* Macros for exception handling
@@ -177,11 +179,11 @@ static PyObject* CallPythonFuncOnOneArg(PyObject* function, PyObject* single_arg
177
179
#ifndef NMZ_RELEASE
178
180
static_assert (
179
181
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." );
181
183
#endif
182
- #if NMZ_RELEASE < 30900
184
+ #if NMZ_RELEASE < 30902
183
185
static_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." );
185
187
#endif
186
188
187
189
/* **************************************************************************
@@ -1097,6 +1099,61 @@ static PyObject* _NmzConeIntern_renf(PyObject* kwargs)
1097
1099
}
1098
1100
#endif
1099
1101
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
+
1100
1157
/*
1101
1158
@Name NmzCone
1102
1159
@Arguments <keywords>
@@ -1112,7 +1169,12 @@ to machine integers instead of arbitrary precision numbers.
1112
1169
static PyObject* _NmzCone (PyObject* self, PyObject* args, PyObject* kwargs)
1113
1170
{
1114
1171
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
+
1116
1178
static const char * string_for_long = " CreateAsLongLong" ;
1117
1179
PyObject* create_as_long_long = StringToPyUnicode (string_for_long);
1118
1180
#ifdef ENFNORMALIZ
@@ -2479,7 +2541,50 @@ static PyObject* NmzWriteOutputFile(PyObject* self, PyObject* args)
2479
2541
2480
2542
/* **************************************************************************
2481
2543
*
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
2483
2588
*
2484
2589
***************************************************************************/
2485
2590
@@ -2501,6 +2606,7 @@ static PyObject* NmzGetRenfInfo(PyObject* self, PyObject* args)
2501
2606
);
2502
2607
return NULL ;
2503
2608
}
2609
+
2504
2610
const renf_class* renf = get_cone_renf_renf (cone_py);
2505
2611
std::string minpoly_str;
2506
2612
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)
2514
2620
FUNC_END
2515
2621
}
2516
2622
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
+
2517
2661
/* **************************************************************************
2518
2662
*
2519
2663
* Python init stuff
@@ -2598,8 +2742,14 @@ static PyMethodDef PyNormaliz_cppMethods[] = {
2598
2742
2599
2743
{" NmzWriteOutputFile" , (PyCFunction)NmzWriteOutputFile, METH_VARARGS,
2600
2744
" 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
+
2601
2748
{" NmzGetRenfInfo" , (PyCFunction)NmzGetRenfInfo, METH_VARARGS,
2602
2749
" Outputs info of the number field associated to a renf cone" },
2750
+ {" NmzFieldGenName" , (PyCFunction)NmzFieldGenName, METH_VARARGS,
2751
+ " Returns name of field generator" },
2752
+
2603
2753
{" NmzModifyCone" , (PyCFunction)_NmzModify_Outer, METH_VARARGS,
2604
2754
" Modifies a given input property of a cone using a new matrix" },
2605
2755
{
0 commit comments