[MOAB-dev] r2896 - in MOAB/trunk/tools/iMesh/python: . perf

jvporter at wisc.edu jvporter at wisc.edu
Mon May 18 12:26:35 CDT 2009


Author: jvporter
Date: 2009-05-18 12:26:35 -0500 (Mon, 18 May 2009)
New Revision: 2896

Modified:
   MOAB/trunk/tools/iMesh/python/iMesh.c
   MOAB/trunk/tools/iMesh/python/iMesh_Python.h
   MOAB/trunk/tools/iMesh/python/perf/perf.py
Log:
Cleanup Python performance test and array allocation


Modified: MOAB/trunk/tools/iMesh/python/iMesh.c
===================================================================
--- MOAB/trunk/tools/iMesh/python/iMesh.c	2009-05-18 15:50:31 UTC (rev 2895)
+++ MOAB/trunk/tools/iMesh/python/iMesh.c	2009-05-18 17:26:35 UTC (rev 2896)
@@ -1569,15 +1569,60 @@
 
 ENUM_TYPE(topology,"iMesh.topology","");
 
+
+static void
+ArrDeallocObj_dealloc(ArrDealloc_Object *self)
+{
+    free(self->memory);
+    self->ob_type->tp_free((PyObject *)self);
+}
+
+static PyTypeObject ArrDealloc_Type = {
+    PyObject_HEAD_INIT(NULL)
+    0,                                          /* ob_size */
+    "mydeallocator",                            /* tp_name */
+    sizeof(ArrDealloc_Object),                  /* tp_basicsize */
+    0,                                          /* tp_itemsize */
+    (destructor)ArrDeallocObj_dealloc,          /* tp_dealloc */
+    0,                                          /* tp_print */
+    0,                                          /* tp_getattr */
+    0,                                          /* tp_setattr */
+    0,                                          /* tp_compare */
+    0,                                          /* tp_repr */
+    0,                                          /* tp_as_number */
+    0,                                          /* tp_as_sequence */
+    0,                                          /* tp_as_mapping */
+    0,                                          /* tp_hash */
+    0,                                          /* tp_call */
+    0,                                          /* tp_str */
+    0,                                          /* tp_getattro */
+    0,                                          /* tp_setattro */
+    0,                                          /* tp_as_buffer */
+    Py_TPFLAGS_DEFAULT,                         /* tp_flags */
+    "Internal deallocator object",              /* tp_doc */
+};
+
+PyObject *
+PyArray_NewFromMallocData(int nd,npy_intp *dims,int typenum,void *data)
+{
+    ArrDealloc_Object *newobj;
+    PyObject *arr =  PyArray_New(&PyArray_Type, nd, dims, typenum, NULL,
+                                 data, 0, NPY_CARRAY, NULL);
+    newobj = PyObject_New(ArrDealloc_Object, &ArrDealloc_Type);
+    newobj->memory = data;
+    PyArray_BASE(arr) = (PyObject*)newobj;
+    return arr;
+}
+
 PyMODINIT_FUNC initiMesh(void)
 {
     PyObject *m;
     PyArray_Descr *descr;
 
     /* TODO: remove */
-    _MyDeallocType.tp_new = PyType_GenericNew;
-    if (PyType_Ready(&_MyDeallocType) < 0)
-        return;
+    ArrDealloc_Type.tp_new = PyType_GenericNew;
+    if (PyType_Ready(&ArrDealloc_Type) < 0)
+    return;
 
     m = Py_InitModule("iMesh",module_methods);
     import_array();

Modified: MOAB/trunk/tools/iMesh/python/iMesh_Python.h
===================================================================
--- MOAB/trunk/tools/iMesh/python/iMesh_Python.h	2009-05-18 15:50:31 UTC (rev 2895)
+++ MOAB/trunk/tools/iMesh/python/iMesh_Python.h	2009-05-18 17:26:35 UTC (rev 2896)
@@ -11,61 +11,17 @@
 #define PY_ARRAY_UNIQUE_SYMBOL itaps_ARRAY_API
 #include <numpy/arrayobject.h>
 
-typedef struct {
-PyObject_HEAD
-void *memory;
-} _MyDeallocObject;
-
-static void
-_mydealloc_dealloc(_MyDeallocObject *self)
+typedef struct
 {
-free(self->memory);
-self->ob_type->tp_free((PyObject *)self);
-}
+    PyObject_HEAD
+    void *memory;
+} ArrDealloc_Object;
 
-static PyTypeObject _MyDeallocType = {
-PyObject_HEAD_INIT(NULL)
-0,                                          /*ob_size*/
-"mydeallocator",                   /*tp_name*/
-sizeof(_MyDeallocObject),    /*tp_basicsize*/
-0,                                          /*tp_itemsize*/
-_mydealloc_dealloc,             /*tp_dealloc*/
-0,                         /*tp_print*/
-0,                         /*tp_getattr*/
-0,                         /*tp_setattr*/
-0,                         /*tp_compare*/
-0,                         /*tp_repr*/
-0,                         /*tp_as_number*/
-0,                         /*tp_as_sequence*/
-0,                         /*tp_as_mapping*/
-0,                         /*tp_hash */
-0,                         /*tp_call*/
-0,                         /*tp_str*/
-0,                         /*tp_getattro*/
-0,                         /*tp_setattro*/
-0,                         /*tp_as_buffer*/
-Py_TPFLAGS_DEFAULT,        /*tp_flags*/
-"Internal deallocator object",           /* tp_doc */
-};
 
 
-/*#define PyArray_NewFromMallocData(nd, dims, typenum, data)    \
-    PyArray_New(&PyArray_Type, nd, dims, typenum, NULL,         \
-    data, 0, NPY_CARRAY|NPY_OWNDATA, NULL)*/
+PyObject *
+PyArray_NewFromMallocData(int nd,npy_intp *dims,int typenum,void *data);
 
-static PyObject *
-PyArray_NewFromMallocData(int nd,npy_intp *dims,int typenum,void *data)
-{
-    PyObject *newobj;
-    PyObject *arr =  PyArray_New(&PyArray_Type, nd, dims, typenum, NULL,
-                                 data, 0, NPY_CARRAY, NULL);
-    newobj = (PyObject*)PyObject_New(_MyDeallocObject, &_MyDeallocType);
-    ((_MyDeallocObject *)newobj)->memory = data;
-    PyArray_BASE(arr) = newobj;
-    return arr;
-}
-
-
 PyObject *
 PyArray_TryFromObject(PyObject *obj,int typenum,int min_depth,int max_depth);
 

Modified: MOAB/trunk/tools/iMesh/python/perf/perf.py
===================================================================
--- MOAB/trunk/tools/iMesh/python/perf/perf.py	2009-05-18 15:50:31 UTC (rev 2895)
+++ MOAB/trunk/tools/iMesh/python/perf/perf.py	2009-05-18 17:26:35 UTC (rev 2896)
@@ -28,9 +28,9 @@
 py_stats = {}
 list_stats = {}
 
-path = raw_input('Where da files at: ')
+path = raw_input('Location of test files: ')
 if(len(path) == 0):
-    path = '/home/porterj/moab-3.99/test'
+    path = '.'
 
 ##### Run some tests in C #####
 lines = csv.reader( subprocess.Popen('./perf %s' % path, shell=True,



More information about the moab-dev mailing list