On Mon, Jul 13, 2009 at 7:12 PM, Darren Dale <dsdale24@gmail.com> wrote:
2009/7/13 Stéfan van der Walt <stefan@sun.ac.za>

Hi Darren

2009/7/13 Darren Dale <dsdale24@gmail.com>:
> I've put together a first cut at implementing __array_prepare__, which
> appears to work, and I would like to request feedback. Here is an overview
> of the approach:

This is pretty neat!  Do you have a quick snippet at hand illustrating its use?

That would be helpful, wouldn't it? The attached script is a modified version of RealisticInfoArray from http://docs.scipy.org/doc/numpy/user/basics.subclassing.html . It should yield the following output:

 
starting with [0 1 2 3 4]
which is of type <class '__main__.MyArray'>
and has info attribute = "information"
subtracting 3 from [0 1 2 3 4]
subtract calling __array_prepare__ on [0 1 2 3 4] input
output array is now of type <class '__main__.MyArray'>
output array values are still uninitialized:
        [139911601789568        39578752 139911614885536        39254560
              48]
__array_prepare__ is updating info attribute on output
__array_prepare__ finished, subtract ufunc is taking over
subtract calling __array_wrap__ on [0 1 2 3 4] input
output array has initial value: [-3 -2 -1  0  1]
__array_wrap__ is setting output endpoints to 0
yielding [ 0 -2 -1  0  0]
which is of type <class '__main__.MyArray'>
and has info attribute = "new_information"

This is a gentle ping, hoping to get some feedback so this feature has a chance of being included in the next release.

Darren