[Numpy-discussion] ufuncs for structured arrays

Anthony Scopatz scopatz@gmail....
Thu Oct 4 15:53:05 CDT 2012


On Thu, Oct 4, 2012 at 12:23 PM, Jay Bourque <jay.bourque@continuum.io>wrote:

> Hey Anthony, thanks for the comments.
>
> On Mon, Oct 1, 2012 at 10:32 PM, Anthony Scopatz <scopatz@gmail.com>wrote:
>
>> Hello Jay,
>>
>> Cool idea!  I like to see work on structured arrays.  Just a couple of
>> questions:
>>
>>    - Since there are already have ufuncs for primitive dtypes (int,
>>    float, etc), and you are just acting columnwise here, can't you write a
>>    single function which interprets the dtypes, gathers the approriate scalar
>>    ufuncs, and applies those down each field?  Yes registering individual
>>    functions using your mechanism will be faster, but it will also be more
>>    work.
>>
>> I hadn't thought of this approach, but I suppose that would work okay too
> for certain dtypes. You'd lose some flexibility with writing a ufunc for a
> specific struct dtype though (for example maybe the ufunc shouldn't be
> applied to all the fields in a record). Maybe this approach would be a good
> default to use when a ufunc hasn't been registered for a struct dtype?
>

A sensible default was use case that I had in mind.  I think that it is
cool to be register your own ufuncs and I like what you have done there.
 So what I suggested is more of an addition than a strict criticism of work
to date.


>
>
>>
>>    - I didn't try this out myself, but will the normal numpy
>>    broadcasting rules apply here?
>>
>> I need to do more testing for this, but yes, I believe normal
> broadcasting rules should work fine.
>

That'd be great!

Be Well
Anthony


>
>
>> Be Well
>> Anthony
>>
>> On Mon, Oct 1, 2012 at 10:36 AM, Jay Bourque <jay.bourque@continuum.io>wrote:
>>
>>> All,
>>>
>>> I've submitted the following pull request for NumPy:
>>>
>>> https://github.com/numpy/numpy/pull/462
>>>
>>> This change allows ufuncs to be registered for structured arrays by
>>> using a new API method PyUFunc_RegisterLoopForStructType. For example, a
>>> ufunc could be registered to take two arrays of type 'u8,u8,u8' and return
>>> an array of type 'u8,u8,u8'. I have a trivial example of this included in
>>> my pull request, along with further details of my changes. I suspect there
>>> might be a better way to do this, so any suggestions for improvements would
>>> be welcome.
>>>
>>> Thanks,
>>> -Jay
>>> continuum.io
>>>
>>> _______________________________________________
>>> NumPy-Discussion mailing list
>>> NumPy-Discussion@scipy.org
>>> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>>>
>>>
>>
>> _______________________________________________
>> NumPy-Discussion mailing list
>> NumPy-Discussion@scipy.org
>> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>>
>>
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20121004/127de8aa/attachment.html 


More information about the NumPy-Discussion mailing list