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.<div>
<br></div><div>-Mark<br><br><div class="gmail_quote">On Tue, Jan 4, 2011 at 12:59 PM, Mark Wiebe <span dir="ltr"><<a href="mailto:mwwiebe@gmail.com">mwwiebe@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="gmail_quote"><div class="im">On Tue, Jan 4, 2011 at 12:15 PM, John Salvatier <span dir="ltr"><<a href="mailto:jsalvati@u.washington.edu" target="_blank">jsalvati@u.washington.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

Wow, great! I'm excited to try this. I think your patch significantly increases the extendability of numpy.<div><br></div><div>Is the C-API exposed currently? Can you use the API from Cython (meaning is the numpy.pxd file updated)?<br>

</div></blockquote><div><br></div></div><div>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.</div>

<div><br></div><div>Cheers,</div><div>Mark</div><div><div></div><div class="h5"><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div></div><div>On Tue, Jan 4, 2011 at 12:04 PM, Mark Wiebe <span dir="ltr"><<a href="mailto:mwwiebe@gmail.com" target="_blank">mwwiebe@gmail.com</a>></span> wrote:</div>

<div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div></div><div>
<div class="gmail_quote"><div>On Sat, Jan 1, 2011 at 11:23 AM, John Salvatier <span dir="ltr"><<a href="mailto:jsalvati@u.washington.edu" target="_blank">jsalvati@u.washington.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">



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?<br></blockquote><div><br></div></div><div>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.</div>



<div><br></div><div>The Python code</div><div><br></div></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div class="gmail_quote"><div><div>a = arange(2).reshape(2,1)</div>
</div></div><div class="gmail_quote"><div><div>b = arange(3).reshape(1,3)</div></div></div><div class="gmail_quote"><div><div><br></div></div></div><div class="gmail_quote"><div><div>i, j = np.nested_iters([a,b], [[0],[1]])</div>



</div></div><div class="gmail_quote"><div><div>for x in i:</div></div></div><div class="gmail_quote"><div><div>    print "inner:"</div></div></div><div class="gmail_quote"><div><div>    for y in j:</div></div></div>



<div class="gmail_quote"><div><div>        print y[0], y[1]</div></div></div></blockquote><div class="gmail_quote"><div><div> </div></div><div>gives</div><div><br></div></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px">



<div class="gmail_quote"><div>inner:</div></div><div class="gmail_quote"><div>0 0</div></div><div class="gmail_quote"><div>0 1</div></div><div class="gmail_quote"><div>0 2</div></div><div class="gmail_quote"><div>inner:</div>



</div><div class="gmail_quote"><div>1 0</div></div><div class="gmail_quote"><div>1 1</div></div><div class="gmail_quote"><div>1 2</div></div></blockquote><div class="gmail_quote"><div><br></div><div>and C code for nested iteration looks something like this:</div>



<div><br></div><div><div>        NpyIter *iter1, *iter1;</div><div>        NpyIter_IterNext_Fn iternext1, iternext2;</div><div>        char **dataptrs1;</div><div><br></div><div>        /*</div><div>         * With the exact same operands, no copies allowed, and</div>



<div>         * no axis in op_axes used both in iter1 and iter2.</div><div>         * Buffering may be enabled for iter2, but not for iter1.</div><div>         */</div><div>        iter1 = ...; iter2 = ...;</div><div><br>



</div><div>        iternext1 = NpyIter_GetIterNext(iter1);</div><div>        iternext2 = NpyIter_GetIterNext(iter2);</div><div>        dataptrs1 = NpyIter_GetDataPtrArray(iter1);</div><div><br></div><div>        do {</div>



<div>            NpyIter_ResetBasePointers(iter2, dataptrs1);</div><div>            do {</div><div>                /* Use the iter2 values */</div><div>            } while (iternext2(iter2));</div><div>        } while (iternext1(iter1));</div>



</div><div><br></div><div>Cheers,</div><div>Mark</div></div>
<br></div></div><div>_______________________________________________<br>
NumPy-Discussion mailing list<br>
<a href="mailto:NumPy-Discussion@scipy.org" target="_blank">NumPy-Discussion@scipy.org</a><br>
<a href="http://mail.scipy.org/mailman/listinfo/numpy-discussion" target="_blank">http://mail.scipy.org/mailman/listinfo/numpy-discussion</a><br>
<br></div></blockquote></div><br></div>
<br>_______________________________________________<br>
NumPy-Discussion mailing list<br>
<a href="mailto:NumPy-Discussion@scipy.org" target="_blank">NumPy-Discussion@scipy.org</a><br>
<a href="http://mail.scipy.org/mailman/listinfo/numpy-discussion" target="_blank">http://mail.scipy.org/mailman/listinfo/numpy-discussion</a><br>
<br></blockquote></div></div></div><br>
</blockquote></div><br></div>