Re: [PyOpenGL-Users] Pointer functions copying memory.
Brought to you by:
mcfletch
From: Shane H. (Techgame) <sha...@te...> - 2003-02-04 22:27:08
|
I like the idea of python code doing the Numeric conversions, so things can be changed by the user in a straightforward manner. In essence, I set OpenGL.GL.contiguous to my own callable, in which I can raise an error if I so choose. =) This solves both concerns in a nice way. +1 Perhaps this same hibred approach can be used in other areas -- simplifying the SWIG wrappers, while maintaining the more sophisticated behavior in Python? Thanks, -Shane Mike C. Fletcher wrote: > Hmm, lots of users don't really care if there's a little inefficiency if > it means they can get on with their lives (premature optimisation and > all that), they just want to see if what they're doing is doing what > it's supposed to, and having an error raised for what is essentially a > Numeric Python internal bookkeeping difficulty would mean their > (perfectly functional as-of-now) code just won't work. A warning might > be possible, but even then, it seems a bit much. > > BTW, Here's a function that does the work of converting any given array > to a contiguous Numeric Python array: > > try: > import Numeric > except ImportError: > def contiguous( source ): > """Place-holder for contiguous-array function, just returns argument > > This is only visible if Numeric Python is not installed > """ > return source > else: > def contiguous( source, typecode=None ): > """Return source as a contiguous Numeric Python array""" > if isinstance( source, Numeric.ArrayType): > if source.iscontiguous() and (typecode is None or > typecode==source.typecode()): > return source > else: > return Numeric.array(source,typecode or source.typecode()) > elif typecode: > return Numeric.array( source, typecode ) > else: > return Numeric.array( source ) > > I'm considering adding that to OpenGL.GL.__init__.py . But would > appreciate feedback regarding it first (particularly whether it's > solving the problems with speed that gabor was noticing). It should be > possible to simply call contiguous before storing your arrays and have > no copying overhead imposed (as long as the data-types for array and > pointer match, of course). I'll add notes to this affect to the docs as > well if we go this route. > > I had considered having the gl*Pointer functions _return_ the contiguous > array, but I don't like messing with the OpenGL API just to deal with a > quirk of Numeric. > > Enjoy all, > Mike > |