[SciPy-Dev] Multilinear interpolation

Pablo Winant pablo.winant@gmail....
Fri Mar 1 04:58:27 CST 2013


So I have updated the tempita template using fused types. I also 
included code generation helper functions in python blocks.

I found a problem with the template generation engine 
(https://groups.google.com/forum/?fromgroups=#!topic/paste-users/bwrf6xPhIjo). 
Basically, functions defined in python blocks cannot depend upon each 
other. In particular, they cannot be recursive. I avoided the problem by 
defining a dummy function but this is of course not very elegant.

On the pyx side:
- I included a "with nogil, parallel():" instruction but I am not sure 
if it has enabled any parallel calculation at all. Cpu usage seems to 
rely on one core only.
- By looking at the generated C file, I suspect there is still a small 
cython overhead. I see conditional branches inside the loop while there 
should be none.
- Maybe I should not be using memoryviews and use arrays of pointers 
instead inside the loop ? Then would it be enough to pass memoryviews as 
arguments in order to ensure data continuity ?
- Performances are not so bad if I compare to matlab. I tried to 
evaluate a function defined over a [4,3,5,6] 4d-grid on 10000000 random 
points and I got 0.2s vs 1.4s for matlab's interpn(...,'linear*'). Of 
course this is to be taken with a grain of salt and I think it could 
still be improved a bit.



On 25/02/2013 21:19, Pauli Virtanen wrote:
> 25.02.2013 22:04, Pablo Winant kirjoitti:
> [clip]
>>> - The code assumes C-contiguous arrays, but does not check for it.
>> right
> Note that you can make Cython to check for this, the syntax is
> sometype[::1] or sometype[:,::1] for multidim (see below).
>
> [clip]
>>> You can use fused types instead of templating; the end result is the same,
>>> but Cython takes care of picking the correct routine.
>>>
>> I tried it but I didn't see how to do it. I would like to do define a
>> function like
>>
>> def function(ndarray[fused_type, ndim=2]):
>>       ...
>>       cdef fused_type internal_variable
>>       ...
>>       return something
> The syntax for these arrays is
>
> 	cdef fused number_t:
> 	    double
> 	    double complex
>
>
> 	def my_function(fused_type[:,:] arg)
> 	    ...
>
> I think it doesn't work with the (old) np.ndarray syntax.
>



More information about the SciPy-Dev mailing list