[Pyrex] newbie question: error using pyrex

Sven Berkvens-Matthijsse sven at pyrex.berkvens.net
Tue Sep 18 16:44:49 CEST 2007


> Hi,
> 
> I'm a first time user of pyrex and tried to translate that piece of code
> using pyrex:
> 
> cdef extern from "math.h"
> 

This should be:

cdef extern from "math.h":
    float sqrt(float)

> def pofr(vectors):
>     distances = list()
>     cdef int n
>     n = len(vectors)
>     for i from 0 <= i < n:
>         for j from i+1 <= j < n:
>             a = vector[i]
>             b = vector[j]
>             dist = sqrt((a[0]-b[0]) * (a[0]-b[0]) +
>                         (a[1]-b[1]) * (a[1]-b[1]) +
>                         (a[2]-b[2]) * (a[2]-b[2]))
>             distances.append(dist)
>     return distances
> 
> running 'pyrexc pofr_module.pyx' results in this error message:
> /home/cm/bin/mc_rigid_dir/src/pofr_module.pyx:1:25: Expected ':'

That's because line 1 (the cdef extern from "math.h") was missing its
colon. If you want to make Pyrex generate code that just includes some
header file but you don't want to use any definitions from it directly
in Pyrex, use something like:

cdef extern from "math.h":
    pass

If you included the header file because you need access to functions
and/or variables that it defines, you must declare them in Pyrex, as I
did in my correction above.

> I'm using Ubuntu's 0.9.4.1-2ubunut1 package of pyrex, for it matters.

That shouldn't matter in this case.

> TIA
> Christian

-- 
With kind regards,
Sven Berkvens-Matthijsse
sven at pyrex.berkvens.net



More information about the Pyrex mailing list