From 6705b15c3afc91bf9ae7c58fbfa05351de557ef3 Mon Sep 17 00:00:00 2001 From: "Mike C. Fletcher" Date: Thu, 11 Jul 2013 00:53:36 -0400 Subject: [PATCH] Remove Numeric support --- OpenGL/__init__.py | 4 - OpenGL/arrays/_numeric.py | 26 ----- OpenGL/arrays/numeric.py | 127 ------------------------ OpenGL_accelerate/src/_arrays.c | 58 ----------- OpenGL_accelerate/src/_numarrayarrays.c | 41 -------- documentation/pydoc/builddocs.py | 3 +- documentation/using.html | 37 +------ 7 files changed, 5 insertions(+), 291 deletions(-) delete mode 100644 OpenGL/arrays/_numeric.py delete mode 100644 OpenGL/arrays/numeric.py delete mode 100644 OpenGL_accelerate/src/_arrays.c delete mode 100644 OpenGL_accelerate/src/_numarrayarrays.c diff --git a/OpenGL/__init__.py b/OpenGL/__init__.py index cd499d5a..a5b5a4c9 100644 --- a/OpenGL/__init__.py +++ b/OpenGL/__init__.py @@ -64,9 +64,6 @@ testing stages to prevent raising errors on recoverable conditions at run-time. - Note: this feature does not currently work with - numarray or Numeric arrays. - Default: False CONTEXT_CHECKING -- if set to True, PyOpenGL will wrap @@ -225,6 +222,5 @@ ) FormatHandler( 'ctypespointer', 'OpenGL.arrays.ctypespointers.CtypesPointerHandler' ) FormatHandler( 'numpy', 'OpenGL.arrays.numpymodule.NumpyHandler', ['numpy.ndarray'] ) -FormatHandler( 'numeric', 'OpenGL.arrays.numeric.NumericHandler', ) FormatHandler( 'vbo', 'OpenGL.arrays.vbo.VBOHandler', ['OpenGL.arrays.vbo.VBO','OpenGL_accelerate.vbo.VBO'] ) FormatHandler( 'vbooffset', 'OpenGL.arrays.vbo.VBOOffsetHandler', ['OpenGL.arrays.vbo.VBOOffset','OpenGL_accelerate.vbo.VBOOffset'] ) diff --git a/OpenGL/arrays/_numeric.py b/OpenGL/arrays/_numeric.py deleted file mode 100644 index 376fb245..00000000 --- a/OpenGL/arrays/_numeric.py +++ /dev/null @@ -1,26 +0,0 @@ -"""Run-time calculation of offset into Python Numeric (old) structures - -Numeric Python, by fortuitous chance, puts the one thing -we need precisely as the first value in the structure beyond the -PyObject * header, so that it's exactly that many bytes from the -pointer value for the object... -""" -import ctypes - -def dataPointerFunction( ): - """Calculate the data-pointer offset in the Numeric object header""" - offset = object.__basicsize__ - from_address = ctypes.c_void_p.from_address - def dataPointer( data): - """Return pointer-to-data + offset""" - return from_address( id( data ) + offset ).value - return dataPointer - -dataPointer = dataPointerFunction() - -if __name__ == "__main__": - import Numeric - test = Numeric.arange( 0,200, 1,'i' ) - aType = ctypes.c_int * 200 - test2 = aType.from_address( dataPointer( test ) ) - assert test == test2, (test,test2) \ No newline at end of file diff --git a/OpenGL/arrays/numeric.py b/OpenGL/arrays/numeric.py deleted file mode 100644 index 1adeeac5..00000000 --- a/OpenGL/arrays/numeric.py +++ /dev/null @@ -1,127 +0,0 @@ -"""Original Numeric module implementation of the OpenGL-ctypes array interfaces - -Eventual Goals: - * Be able to register handlers for a given data-storage mechanism at - run-time - * Be able to choose what data-type to use for any given operation where - we are getting return values and/or register a default format for - return values (i.e. tell OpenGL to return ctypes pointers or Numeric - arrays or Numarray arrays for glGet* calls) -""" -REGISTRY_NAME = 'numeric' -try: - import Numeric -except ImportError as err: - raise ImportError( """No Numeric module present: %s"""%(err)) -import operator -from OpenGL.arrays import _numeric - -dataPointer = _numeric.dataPointer - -from OpenGL import constants, constant -from OpenGL.arrays import formathandler - -class NumericHandler( formathandler.FormatHandler ): - """Numeric-specific data-type handler for OpenGL""" - HANDLED_TYPES = (Numeric.ArrayType, ) - isOutput = True - @classmethod - def from_param( cls, value, typeCode=None ): - return dataPointer( value ) - dataPointer = staticmethod( dataPointer ) - def voidDataPointer( cls, value ): - """Given value in a known data-pointer type, return void_p for pointer""" - return ctypes.c_void_p( self.dataPointer( value )) - def zeros( self, dims, typeCode ): - """Return Numeric array of zeros in given size""" - return Numeric.zeros( dims, GL_TYPE_TO_ARRAY_MAPPING.get(typeCode) or typeCode ) - def arrayToGLType( self, value ): - """Given a value, guess OpenGL type of the corresponding pointer""" - typeCode = value.typecode() - constant = ARRAY_TO_GL_TYPE_MAPPING.get( typeCode ) - if constant is None: - raise TypeError( - """Don't know GL type for array of type %r, known types: %s\nvalue:%s"""%( - typeCode, list(ARRAY_TO_GL_TYPE_MAPPING.keys()), value, - ) - ) - return constant - def arraySize( self, value, typeCode = None ): - """Given a data-value, calculate dimensions for the array""" - try: - dimValue = value.shape - except AttributeError as err: - # XXX it's a list or a tuple, how do we determine dimensions there??? - # for now we'll just punt and convert to an array first... - value = self.asArray( value, typeCode ) - dimValue = value.shape - dims = 1 - for dim in dimValue: - dims *= dim - return dims - def asArray( self, value, typeCode=None ): - """Convert given value to an array value of given typeCode""" - if value is None: - return value - else: - return self.contiguous( value, typeCode ) - - def contiguous( self, source, typeCode=None ): - """Get contiguous array from source - - source -- Numeric Python array (or compatible object) - for use as the data source. If this is not a contiguous - array of the given typeCode, a copy will be made, - otherwise will just be returned unchanged. - typeCode -- optional 1-character typeCode specifier for - the Numeric.array function. - - All gl*Pointer calls should use contiguous arrays, as non- - contiguous arrays will be re-copied on every rendering pass. - Although this doesn't raise an error, it does tend to slow - down rendering. - """ - typeCode = GL_TYPE_TO_ARRAY_MAPPING.get( typeCode ) - if isinstance( source, Numeric.ArrayType): - if source.iscontiguous() and (typeCode is None or typeCode==source.typecode()): - return source - else: - if typeCode is None: - typeCode = source.typecode() - # We have to do astype to avoid errors about unsafe conversions - # XXX Confirm that this will *always* create a new contiguous array - # XXX Allow a way to make this raise an error for performance reasons - # XXX Guard against wacky conversion types like uint to float, where - # we really don't want to have the C-level conversion occur. - return Numeric.array( source.astype( typeCode ), typeCode ) - elif typeCode: - return Numeric.array( source, typeCode ) - else: - return Numeric.array( source ) - def unitSize( self, value, typeCode=None ): - """Determine unit size of an array (if possible)""" - return value.shape[-1] - def dimensions( self, value, typeCode=None ): - """Determine dimensions of the passed array value (if possible)""" - return value.shape - - -ARRAY_TO_GL_TYPE_MAPPING = { - 'd': constants.GL_DOUBLE, - 'f': constants.GL_FLOAT, - 'i': constants.GL_INT, - 's': constants.GL_SHORT, - 'c': constants.GL_UNSIGNED_BYTE, - 'b': constants.GL_BYTE, - 'I': constants.GL_UNSIGNED_INT, -} -GL_TYPE_TO_ARRAY_MAPPING = { - constants.GL_DOUBLE: 'd', - constants.GL_FLOAT:'f', - constants.GL_INT: 'i', - constants.GL_UNSIGNED_INT: 'i', - constants.GL_UNSIGNED_BYTE: 'c', - constants.GL_SHORT: 's', - constants.GL_UNSIGNED_SHORT: 's', - constants.GL_BYTE: 'b', -} diff --git a/OpenGL_accelerate/src/_arrays.c b/OpenGL_accelerate/src/_arrays.c deleted file mode 100644 index a4203197..00000000 --- a/OpenGL_accelerate/src/_arrays.c +++ /dev/null @@ -1,58 +0,0 @@ -/* C helper functions for OpenGL Numeric arrays */ -#include "Python.h" -#ifdef USE_NUMPY -#include "numpy/arrayobject.h" -#else -#include "Numeric/arrayobject.h" -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -static PyObject * dataPointer( PyObject * self, PyObject * args ) { - PyObject * array = NULL; - char * dataPointer = NULL; - if (!PyArg_ParseTuple( args, "O", &array )) { - return NULL; - } - if (array==Py_None) { - dataPointer = NULL; - } else { - if (!PyArray_Check(array)){ - // raise TypeError... - PyErr_SetString( PyExc_TypeError, "Require a numpy/Numeric array" ); - return NULL; - } - /* XXX do a check here for array type! */ - dataPointer = ((PyArrayObject *) array)->data; - } - return PyInt_FromLong( (long) dataPointer ); -} - -static PyMethodDef _arrays_methods[] = { - {"dataPointer", dataPointer, 1, "dataPointer( array )\n"\ - "Retrieve data-pointer value as a Python integer\n"\ - "array -- Numeric Array pointer"}, - {NULL, NULL} -}; - -#ifdef USE_NUMPY -void -initnumpy_accel(void) -{ - Py_InitModule("numpy_accel", _arrays_methods); - import_array(); -} -#else -void -inittnumeric_accel(void) -{ - Py_InitModule("numeric_accel", _arrays_methods); - import_array(); -} -#endif - -#ifdef __cplusplus -} -#endif diff --git a/OpenGL_accelerate/src/_numarrayarrays.c b/OpenGL_accelerate/src/_numarrayarrays.c deleted file mode 100644 index f263ecf9..00000000 --- a/OpenGL_accelerate/src/_numarrayarrays.c +++ /dev/null @@ -1,41 +0,0 @@ -/* C helper functions for OpenGL Numarray arrays */ -#include -#include "numarray/libnumarray.h" -#ifdef __cplusplus -extern "C" { -#endif - -static PyObject * dataPointer( PyObject * self, PyObject * args ) { - PyObject * array = NULL; - PyObject * result = NULL; - char * dataPointer = NULL; - if (!PyArg_ParseTuple( args, "O", &array )) { - return NULL; - } - if (array==Py_None) { - dataPointer = NULL; - } else if (PyString_Check( array )) { - /* This is undocumented, is there a better way? */ - dataPointer = ((PyStringObject *) array)->ob_sval; - } else { - /* XXX do a check here for array type! */ - dataPointer = ((PyArrayObject *) array)->data; - } - return PyInt_FromLong( (long) dataPointer ); -} - -static PyMethodDef _arrays_methods[] = { - {"dataPointer", dataPointer, 1, "dataPointer( array )\n"\ - "Retrieve data-pointer value as a Python integer\n"\ - "array -- Numarray Array pointer"}, - {NULL, NULL} -}; - -void MODULE_INIT(void) -{ - Py_InitModule(MODULE_NAME, _arrays_methods); - import_libnumarray(); -} -#ifdef __cplusplus -} -#endif diff --git a/documentation/pydoc/builddocs.py b/documentation/pydoc/builddocs.py index 08340716..b708c72a 100755 --- a/documentation/pydoc/builddocs.py +++ b/documentation/pydoc/builddocs.py @@ -22,7 +22,6 @@ def isbuiltin( obj ): if __name__ == "__main__": excludes = [ - "Numeric", "numpy", "_tkinter", "Tkinter", @@ -45,4 +44,4 @@ def isbuiltin( obj ): exclusions = excludes, recursionStops = stops, ).process () - \ No newline at end of file + diff --git a/documentation/using.html b/documentation/using.html index 3d1a362d..adc97059 100644 --- a/documentation/using.html +++ b/documentation/using.html @@ -526,7 +526,7 @@

Performance Tips for Python + OpenGL

Array based geometry uses OpenGL 1.1 features (supported almost everywhere) that allow for passing large arrays of data to be processed -with a single call.  Using numpy (or Numeric) arrays, you can +with a single call.  Using numpy arrays, you can readily pass your data into those functions without any need for Python-level iteration.  This is the more flexible of the two approaches, as it allows for readily mutating the data being rendered @@ -750,37 +750,8 @@

Upgrading

  • setuptools required
  • numpy versus Numeric
  • - - - - - - - - - - -
  • strings deprecated as array return-types for all save image data
  • +
  • strings deprecated as array return-types for all save image data