[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: Fwd: Re: [pygame] SDL-ctypes progress



Rene Dudfield wrote:

Nums!  A new name for the group (Numpy, Numeric, Numarray) is Nums.


+1 for polymorphism. Although the current api is good too.

You can always check the return type if you need to know its type.
The nums are similar enough for lots of uses.  Often only one type
will be installed on someones machine.

pixels.as_nums() ?  which returns a globally registered num?  Or
as_globally_registered_array() for a really long name.

Ok, I can't think of a good name for it.


Another option... Maybe instead of surf.pixels.as_something()...

surf.pixels
surf.pixels_numpy
surf.pixels_numarray
surf.pixels_numeric
surf.pixels_yet_another_numeric_type_when_it_comes_up
surf.pixels_num

The pixels_num would be the globally registered type.  There would
still be surf.pixels the same as it is now.  The globally registered
type would be discovered and set the same way that pyopengl does.

What about that?

Ok, some of this discussion is somewhat pointless: Numeric and numarray cannot be supported; they do not have the functionality to construct an array from an existing buffer (even if they do in the future, we would obviously be relying on a feature that doesn't exist in the majority of users' cases). Note also that numpy supercedes numeric and numarray; according to numpy.org, "new users should start out with numpy". By definition, all users of SDL-ctypes will be new users (creators of new projects).


So the three use cases are: accessing the buffer with slices, using numpy operators, or casting to some hypothetical future array package implementing the array interface. The first is supported natively: surf.pixels[4:10] slices using ctypes. The second, as mentioned, can be constructed if the application is certain numpy is installed with surf.pixels.as_numpy(). The last is possible, if/when ctypes exposes the proposed array interface, e.g.: hypothetical_array(surf.pixels).

I am definitely _not_ a fan of having to check a return type to find out what it is (as I write this, I realise that's exactly what I've done with the event functions... hmm, better think harder about that).

Alex.