Hoyt Koepke wrote:
> Hi,
>
>> I've now got a bit more time.
>>
>> I don't know how things are going at Sage days; but if you're still up
>> for it, and e.g. Robert has an hour for you later on, I could spend some
>> time posting an outline for how I'd go about the (2) project and then
>> perhaps Robert could mentor a bit from there.
>>
>> I.e. the goal would be to allow for instance
>>
>> cdef np.ndarray[int, ndim=3] arr1 = ..., arr2
>> for idx in cython.iterate(arr1, arr2):
>> arr1[idx] = arr1[idx] + arr2[idx]
>>
>> where idx is some "psuedo-tuple" of ndim length, and have it compile to
>> a native loop.
>
> I have been swamped the past week trying to get a research project
> back on track, so unfortunately I haven't been able to take advantage
> of sage days here :-(. Bummer. However, I still want to help out
> with this and take up your mentoring offer and work on this. To be honest,
> I probably won't have a significant chunk of time, though, until after June 5.
Sure, just ask again when you do.
> I'm wondering, though, if it would be better to do this in two stages.
> It seems like having a type, say index_tuple, which the user can
> define and then manipulate. It seems we would be doing this anyway,
> and explicitly exposing it to the user could have use cases. In the C
> code, it seems like it'd just be an int array.
I was actually thinking it would be slightly more magic than this (for
speed) and that "arr[idx]" would translate to "*head", where head was a
pointer in the innermost loop:
while (not at end) {
...iterate n-1 outermost dimension.., set head and rowend
while (++head != rowend) { // iterator innermost, perhaps contiguous
BODY
}
}
however, if "idx" was used, one would add updating an idx array to this
scheme (but it would only be used for <object>idx and idx[dim], not
arr[idx]).
> cdef size_t i
> cdef index_tuple[2] idx
> cdef ndarray[double, ndim=2] A
>
> idx[0] = 0
>
> for 0 <= i < A.shape[1]:
> idx[1] = i
> A[idx] = 1
>
>
> Obviously this is a simple example, but there might easily be other
> use cases, such as passing indices to a function, etc..
>
> What do you think?
Sounds ok to me, and definitely would be a stepping stone for the above.
I'd have another look at the syntax and make it more generic though --
some proposals:
cdef tuple[Py_ssize_t, len=2] idx
cdef (Py_ssize_t, Py_ssize_t) idx
I'm actually leaning towards the latter, although it would be an
entirely new construct. The reason is that it could be used as a syntax
to support multiple return values:
cdef (int, float) hello(): return (3, 3.14)
Perhaps even
cdef (Py_ssize_t,)*4 idx
:-)
--
Dag Sverre
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev