Am I the only one thinking Jelle might know which bits of his function
are slow? :)

Jelle Feringa  wrote:
>       n=1
>       for a in ogrid[ 0:1:complex(n_samples)].tolist():
>               for b in ogrid[ 0:1:complex(n_samples)].tolist():
>                       curv = curvature( a, b )
>                       a_wrapped_datatype( n, curv )
>                       n+=1
>       return a_wrapped_datatype

I think your loop might be doing unnecessary work. See if this helps:
        cdef int a, b, arrlen
        myarray = ogrid[ 0:1:complex(n_samples)]
        arrlen = len(myarray)
        for a from 0 <= a < arrlen:
                for b from 0 <= b < arrlen:
                        curv = curvature( myarr[a], myarr[b])

The "cdef int" shouldn't give you any benefit right now, rather being
slower. If you can index the  array (or its buffer) with non-Python
ints, it should be faster (look at numpy integration, Dag's work :).
If not, just avoiding the calls to tolist() in the inner loop could be
nice.

Check http://docs.cython.org/docs/numpy_tutorial.html

Now, if you could bypass the python layer in certain places, like
calling the real C++_curvature with a real float instead of a python
float, cdef'ing n to [numpy]int and a_wrapped_datatype to (int,
float?), you'd get things going faster without having to start a new
wrapper from zero.

Regards,
Daniel
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to