Changeset: 7f460f5ba107 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=7f460f5ba107
Modified Files:
        monetdb5/extras/pyapi/Tests/pyapi_types_huge.stable.out
        monetdb5/extras/pyapi/Tests/pyapi_types_numeric.stable.out
        monetdb5/extras/pyapi/pyapi.c
Branch: pyapi
Log Message:

Added testing flag for converting huge integers to doubles.


diffs (186 lines):

diff --git a/monetdb5/extras/pyapi/Tests/pyapi_types_huge.stable.out 
b/monetdb5/extras/pyapi/Tests/pyapi_types_huge.stable.out
--- a/monetdb5/extras/pyapi/Tests/pyapi_types_huge.stable.out
+++ b/monetdb5/extras/pyapi/Tests/pyapi_types_huge.stable.out
@@ -31,9 +31,9 @@ Ready.
 # h    t  # name
 # void hge  # type
 #--------------------------#
-[ 0@0, 18044433428933534654634643698858345     ]
-[ 1@0, 895233278923448975389573895731  ]
-[ 2@0, 558372892789247104910348981249  ]
+[ 0@0, 18044433428933533865951768124325888     ]
+[ 1@0, 895233278923449014354175852544  ]
+[ 2@0, 558372892789247096313631211520  ]
 [ 3@0, -23     ]
 [ 4@0, nil     ]
 #io.print(rhge);
@@ -41,9 +41,9 @@ Ready.
 # h    t  # name
 # void hge  # type
 #--------------------------#
-[ 0@0, 54133300286800603963903931096575035     ]
-[ 1@0, 2685699836770346926168721687193 ]
-[ 2@0, 1675118678367741314731046943747 ]
+[ 0@0, 54133300286800599292012295159283712     ]
+[ 1@0, 2685699836770346902325039202304 ]
+[ 2@0, 1675118678367741218572149456896 ]
 [ 3@0, -69     ]
 [ 4@0, nil     ]
 #io.print(rhge, shge);
@@ -65,10 +65,10 @@ Ready.
 # h    t  # name
 # void str  # type
 #--------------------------#
-[ 0@0, "18044433428933534654634643698858345"   ]
-[ 1@0, "895233278923448975389573895731"        ]
-[ 2@0, "558372892789247104910348981249"        ]
-[ 3@0, "-23"   ]
+[ 0@0, "18044433428933533865951768124325888.000000"    ]
+[ 1@0, "895233278923449014354175852544.000000" ]
+[ 2@0, "558372892789247096313631211520.000000" ]
+[ 3@0, "-23.000000"    ]
 [ 4@0, nil     ]
 #io.print(rhge);
 #--------------------------#
@@ -83,9 +83,9 @@ Ready.
 # h    t       t  # name
 # void hge     hge  # type
 #--------------------------#
-[ 0@0, 18044433428933534654634643698858345,    
18044433428933534654634643698858345     ]
-[ 1@0, 895233278923448975389573895731, 895233278923448975389573895731  ]
-[ 2@0, 558372892789247104910348981249, 558372892789247104910348981249  ]
+[ 0@0, 18044433428933533865951768124325888,    
18044433428933533865951768124325888     ]
+[ 1@0, 895233278923449014354175852544, 895233278923449014354175852544  ]
+[ 2@0, 558372892789247096313631211520, 558372892789247096313631211520  ]
 [ 3@0, -23,    -23     ]
 [ 4@0, nil,    nil     ]
 #io.print(rint);
diff --git a/monetdb5/extras/pyapi/Tests/pyapi_types_numeric.stable.out 
b/monetdb5/extras/pyapi/Tests/pyapi_types_numeric.stable.out
--- a/monetdb5/extras/pyapi/Tests/pyapi_types_numeric.stable.out
+++ b/monetdb5/extras/pyapi/Tests/pyapi_types_numeric.stable.out
@@ -96,9 +96,9 @@ Ready.
 # h    t  # name
 # void hge  # type
 #--------------------------#
-[ 0@0, 18044433428933534654634643698858345     ]
-[ 1@0, 895233278923448975389573895731  ]
-[ 2@0, 558372892789247104910348981249  ]
+[ 0@0, 18044433428933533865951768124325888     ]
+[ 1@0, 895233278923449014354175852544  ]
+[ 2@0, 558372892789247096313631211520  ]
 [ 3@0, 23      ]
 [ 4@0, nil     ]
 #io.print(rflt);
diff --git a/monetdb5/extras/pyapi/pyapi.c b/monetdb5/extras/pyapi/pyapi.c
--- a/monetdb5/extras/pyapi/pyapi.c
+++ b/monetdb5/extras/pyapi/pyapi.c
@@ -65,6 +65,7 @@ const char* oldnullmask_enableflag = "en
 const char* bytearray_enableflag = "enable_bytearray";
 const char* benchmark_output_flag = "pyapi_benchmark_output";
 const char* disable_malloc_tracking = "disable_malloc_tracking";
+const char* enable_hugepyobject = "enable_hugepyobject";
 static bool option_zerocopyinput = true;
 static bool option_zerocopyoutput  = true;
 static bool option_numpy_string_array = true;
@@ -74,6 +75,7 @@ static bool option_lazyarray = false;
 static bool option_oldnullmask = false;
 static bool option_pyobject = false;
 static bool option_alwaysunicode = false;
+static bool option_hugepyobject = false;
 static bool option_disablemalloctracking = false;
 static char *benchmark_output = NULL;
 #endif
@@ -1461,6 +1463,7 @@ str
 #endif
 #ifdef _PYAPI_TESTING_
     //These flags are for testing purposes, they shouldn't be used for normal 
purposes
+    option_hugepyobject = (GDKgetenv_isyes(enable_hugepyobject) || 
GDKgetenv_istrue(enable_hugepyobject));
     option_zerocopyinput = !(GDKgetenv_isyes(zerocopyinput_disableflag) || 
GDKgetenv_istrue(zerocopyinput_disableflag));
     option_zerocopyoutput = !(GDKgetenv_isyes(zerocopyoutput_disableflag) || 
GDKgetenv_istrue(zerocopyoutput_disableflag));
     option_numpy_string_array = 
!(GDKgetenv_isyes(numpy_string_array_disableflag) || 
GDKgetenv_istrue(numpy_string_array_disableflag));
@@ -1897,32 +1900,63 @@ PyObject *PyArrayObject_FromBAT(PyInput 
 #ifdef HAVE_HGE
     case TYPE_hge:
     {
-        li = bat_iterator(b);
+#ifdef _PYAPI_TESTING_
+        if (option_hugepyobject) {
+            WARNING_MESSAGE("!PERFORMANCE WARNING: Type \"hge\" (128 bit) is 
unsupported by Numpy. The numbers are instead converted to python objects of 
type \"PyLong\". This means a python object is constructed for every huge 
integer and the entire column is copied.\n");
+            li = bat_iterator(b);
+            //create a NPY_OBJECT array to hold the huge type
+            vararray = PyArray_New(
+                &PyArray_Type,
+                1,
+                (npy_intp[1]) { t_end - t_start },
+                NPY_OBJECT,
+                NULL,
+                NULL,
+                0,
+                0,
+                NULL);
 
-        //create a NPY_OBJECT array to hold the huge type
-        vararray = PyArray_New(
-            &PyArray_Type,
-            1,
-            (npy_intp[1]) { t_end - t_start },
-            NPY_OBJECT,
-            NULL,
-            NULL,
-            0,
-            0,
-            NULL);
+            j = 0;
+            {
+                PyObject *obj;
+                PyObject **data = 
(PyObject**)PyArray_DATA((PyArrayObject*)vararray);
+                BATloop(b, p, q) {
+                    const hge *t = (const hge *) BUNtail(li, p);
+                    obj = PyLong_FromHge(*t);
+                    if (obj == NULL) {
+                        msg = createException(MAL, "pyapi.eval", "Failed to 
create PyLongObject from Huge Integer.");
+                        goto wrapup;
+                    }
+                    data[j++] = obj;
+                }
+            }
+        } else {
+#endif
+            WARNING_MESSAGE("!ACCURACY WARNING: Type \"hge\" (128 bit) is 
unsupported by Numpy. The numbers are instead converted to float64, which 
results in loss of accuracy.\n");
+            li = bat_iterator(b);
+            //create a NPY_FLOAT64 array to hold the huge type
+            vararray = PyArray_New(
+                &PyArray_Type,
+                1,
+                (npy_intp[1]) { t_end - t_start },
+                NPY_FLOAT64,
+                NULL,
+                NULL,
+                0,
+                0,
+                NULL);
 
-        j = 0;
-        WARNING_MESSAGE("!PERFORMANCE WARNING: Type \"hge\" (128 bit) is 
unsupported by Numpy. The numbers are instead converted to python objects of 
type \"PyLong\". This means a python object is constructed for every huge 
integer and the entire column is copied.\n");
-        BATloop(b, p, q) {
-            if (j >= t_start) {
-                PyObject *obj;
-                const hge *t = (const hge *) BUNtail(li, p);
-                obj = PyLong_FromHge(*t);
-                ((PyObject**)PyArray_DATA((PyArrayObject*)vararray))[j - 
t_start] = obj;
+            j = 0;
+            {
+                dbl *data = (dbl*)PyArray_DATA((PyArrayObject*)vararray);
+                BATloop(b, p, q) {
+                    const hge *t = (const hge *) BUNtail(li, p);
+                    data[j++] = (dbl) *t;
+                }
             }
-            if (j == t_end) break;
-            j++;
+#ifdef _PYAPI_TESTING_
         }
+#endif
         break;
     }
 #endif
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to