[Numpy-discussion] suggestion for generalizing numpy functions

Darren Dale dsdale24@gmail....
Sun Sep 13 12:01:56 CDT 2009


On Sat, Jul 25, 2009 at 8:33 PM, Darren Dale <dsdale24@gmail.com> wrote:
> On Thu, Jul 23, 2009 at 12:54 PM, Darren Dale<dsdale24@gmail.com> wrote:
>> On Tue, Jul 21, 2009 at 10:11 AM, Darren Dale<dsdale24@gmail.com> wrote:
>>> On Tue, Jul 21, 2009 at 7:44 AM, Darren Dale<dsdale24@gmail.com> wrote:
>>>> 2009/7/20 Stéfan van der Walt <stefan@sun.ac.za>:
>>>>> Hi Chuck
>>>>>
>>>>> 2009/7/17 Charles R Harris <charlesr.harris@gmail.com>:
>>>>>> PyObject* PyTuple_GetItem(PyObject *p, Py_ssize_t pos)
>>>>>> Return value: Borrowed reference.
>>>>>> Return the object at position pos in the tuple pointed to by p. If pos is
>>>>>> out of bounds, return NULL and sets an IndexError exception. It's a borrowed
>>>>>> reference so you need to call Py_INCREF on it. I find this Python C-API
>>>>>> documentation useful.
>>>>>
>>>>> Have you had a look over the rest of the code?  I think this would
>>>>> make a good addition.  Travis mentioned Contexts for doing something
>>>>> similar, but I don't know enough about that concept to compare the
>>>>> two.
>>>>
>>>> I think contexts would be very different from what is already in
>>>> place. For now, it would be nice to make this one small improvement to
>>>> the existing ufunc infrastructure, and maybe consider contexts (which
>>>> I still don't understand) at a later time. I have improved the code
>>>> slightly and added a few tests, and will post a new patch later this
>>>> morning. I just need to add some documentation.
>>>
>>> Here is a better patch, which includes a few additional tests and adds
>>> some documentation. It also attempts to improve the docstring and
>>> sphinx docs for __array_wrap__, which may have been a little bit
>>> misleading. There is also some whitespace cleanup in a few places.
>>> Would someone please review my work and commit the patch if it is
>>> acceptable? Pierre or Travis, would either of you have a chance to
>>> look over the implementation and the documentation changes, since you
>>> two seem to be most familiar with ufuncs and subclassing ndarray?
>>
>> It looks like part of my patch has been clobbered by changes
>> introduced in svn 7184-7191. What else should I be doing so a patch
>> like this can be committed relatively quickly?
>
> Could I please obtain commit privileges so I can commit this feature
> to svn myself?

I guess I forgot to follow up here, I committed the patch during the
SciPy conference. Thank you to the devs for granting me commit
privileges, I'll use them with care.

Are the numpy developers familiar with predicative dispatch in
general, and PEP 3124 (generic functions) in particular? I've been
reading about them all weekend. They seem particularly applicable to
numpy, and not just where we currently use __array_prepare__ and
__array_wrap__. The PEP seems to have stalled, but there is currently
some discussion about it at python-dev. If anyone is interested in
commenting on how generic functions could be useful to numpy,
commenting in tho thread at python-dev could help establish what
features would be desirable in generic functions and motivation for
including them in the standard library.

Here are some links for anyone who is interested:

The PEP:
http://ftp.python.org/dev/peps/pep-3124/

A presentation of Eby's implementation in PEAK:
http://peak.telecommunity.com/PyCon05Talk/img0.html

One of the paper's Eby cites in the presentation:
http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.47.1167

A Charming Python article an Eby's implementation:
http://www.ibm.com/developerworks/library/l-cppeak2/

Guido's musings on the topic
http://www.artima.com/weblogs/viewpost.jsp?thread=155123


Darren


More information about the NumPy-Discussion mailing list