[Numpy-discussion] Giving numpy the ability to multi-iterate excluding an axis
John Salvatier
jsalvati at u.washington.edu
Tue Jan 4 16:05:44 EST 2011
Cython just has interfaces to the C-API, I think.
On Tue, Jan 4, 2011 at 1:01 PM, Mark Wiebe <mwwiebe at gmail.com> wrote:
> Oh, and I'm not sure about Cython, since I've never looked into its
> details. I imagine Cython will want to short circuit some of the Python
> exposure code, since accessing the iterator values creates new array
> objects.
>
> -Mark
>
>
> On Tue, Jan 4, 2011 at 12:59 PM, Mark Wiebe <mwwiebe at gmail.com> wrote:
>
>> On Tue, Jan 4, 2011 at 12:15 PM, John Salvatier <
>> jsalvati at u.washington.edu> wrote:
>>
>>> Wow, great! I'm excited to try this. I think your patch significantly
>>> increases the extendability of numpy.
>>>
>>> Is the C-API exposed currently? Can you use the API from Cython (meaning
>>> is the numpy.pxd file updated)?
>>>
>>
>> The C-API isn't exposed yet, but that won't be too difficult since it's
>> mostly a matter of adding all the functions to the arrays in the python
>> setup files. I thought I might do that and look at plugging it into numexpr
>> at the same time, since to be able to use the iterator's buffering and
>> numexpr's multithreading together will require some small additions to the
>> iterator.
>>
>> Cheers,
>> Mark
>>
>> On Tue, Jan 4, 2011 at 12:04 PM, Mark Wiebe <mwwiebe at gmail.com> wrote:
>>>
>>>> On Sat, Jan 1, 2011 at 11:23 AM, John Salvatier <
>>>> jsalvati at u.washington.edu> wrote:
>>>>
>>>>> This thread is a bit old, but since it's not possible to use the C-API
>>>>> is possible to accomplish this same thing with the Python API?
>>>>>
>>>>
>>>> I've committed Python exposure for nested iteration to the new_iterator
>>>> branch. In doing so, I also changed the mechanism in C. I found that it
>>>> was simpler to expose to Python if I added a Reset function which gives new
>>>> base data pointers, and this also simplifies C code using nested iterators.
>>>>
>>>> The Python code
>>>>
>>>> a = arange(2).reshape(2,1)
>>>> b = arange(3).reshape(1,3)
>>>>
>>>> i, j = np.nested_iters([a,b], [[0],[1]])
>>>> for x in i:
>>>> print "inner:"
>>>> for y in j:
>>>> print y[0], y[1]
>>>>
>>>>
>>>> gives
>>>>
>>>> inner:
>>>> 0 0
>>>> 0 1
>>>> 0 2
>>>> inner:
>>>> 1 0
>>>> 1 1
>>>> 1 2
>>>>
>>>>
>>>> and C code for nested iteration looks something like this:
>>>>
>>>> NpyIter *iter1, *iter1;
>>>> NpyIter_IterNext_Fn iternext1, iternext2;
>>>> char **dataptrs1;
>>>>
>>>> /*
>>>> * With the exact same operands, no copies allowed, and
>>>> * no axis in op_axes used both in iter1 and iter2.
>>>> * Buffering may be enabled for iter2, but not for iter1.
>>>> */
>>>> iter1 = ...; iter2 = ...;
>>>>
>>>> iternext1 = NpyIter_GetIterNext(iter1);
>>>> iternext2 = NpyIter_GetIterNext(iter2);
>>>> dataptrs1 = NpyIter_GetDataPtrArray(iter1);
>>>>
>>>> do {
>>>> NpyIter_ResetBasePointers(iter2, dataptrs1);
>>>> do {
>>>> /* Use the iter2 values */
>>>> } while (iternext2(iter2));
>>>> } while (iternext1(iter1));
>>>>
>>>> Cheers,
>>>> Mark
>>>>
>>>> _______________________________________________
>>>> NumPy-Discussion mailing list
>>>> NumPy-Discussion at scipy.org
>>>> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>>>>
>>>>
>>>
>>> _______________________________________________
>>> NumPy-Discussion mailing list
>>> NumPy-Discussion at scipy.org
>>> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>>>
>>>
>>
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20110104/4e901f26/attachment.html>
More information about the NumPy-Discussion
mailing list