hi people,
her is my issue: I'm working on optimization of a simulator  written in python 
and using numpy a lot.as i'm a new user of cython, I'm asking help about 
defining functions like cpdef foo(..)  and using at the same time  @proprety 
decorator.i got this msg when compiling the .pyx file:
Error converting Pyrex file to C:
------------------------------------------------------------
...

    @property
    def pose(self):
        return homogeneousmatrix.rotzyx(self.gpos)

    @property
   ^
------------------------------------------------------------
/home/tenninos/stage/arboris-python/src/joints_c.pyx:109:4: Cdef functions 
cannot take arbitrary decorators.

and here is both my python and cython code.i'd be really grateful  if you could 
help me  further in my optimisation :

from numpy import array, zeros, eye, dot, sin, cos, dot
from abc import ABCMeta, abstractmethod
import homogeneousmatrix
from misc import NamedObject
from arboris import Joint
class RzRyRxJoint(LinearConfigurationSpaceJoint):
    """Ball and socket (3-dof) implemented with 3 serial hinges

    the resulting homogeneous matrix is given by H = Rz*Ry*Rx
    """
    def __init__(self, gpos=[0.,0.,0.], gvel=[0.,0.,0.], name=None):
        self.gpos = array(gpos).reshape((3))
        self.gvel = array(gvel).reshape((3))
        Joint.__init__(self, name)

    @property
    def ndof(self):
        return 3

    @property
    def pose(self):
        return homogeneousmatrix.rotzyx(self.gpos)

    @property
    def jacobian(self):
        """
        T_n/r = 
        """   
        sx = sin(self.gpos[0])
        cx = cos(self.gpos[0])
        sy = sin(self.gpos[1])
        cy = cos(self.gpos[1])
        return array(
            [[ 1.   ,  0. , -sy    ],
             [ 0.   , cx  ,  sx*sy ],
             [ 0.   ,-sx  ,  cx*cy ],
             [ 0.   ,  0. ,  0.    ],
             [ 0.   ,  0. ,  0.    ],
             [ 0.   ,  0. ,  0.    ]])

cython:....

from numpy import array, zeros, eye, dot, sin, cos, dot
from abc import ABCMeta, abstractmethod
import homogeneousmatrix
from misc import NamedObject
from arboris import Joint

#mes modifs....
cimport numpy as np
DTYPE = np.float 
ctypedef np.float_t DTYPE_t
cdef extern from "math.h":
    float cosf(float theta)
    float sinf(float theta)

cdef class RzRyRxJoint(LinearConfigurationSpaceJoint):
    """Ball and socket (3-dof) implemented with 3 serial hinges

    the resulting homogeneous matrix is given by H = Rz*Ry*Rx
    """
    def __init__(self, gpos=[0.,0.,0.], gvel=[0.,0.,0.], name=None):
        self.gpos = array(gpos).reshape((3))
        self.gvel = array(gvel).reshape((3))
        Joint.__init__(self, name)

    @property
    def ndof(self):
        return 3

    @property
    def pose(self):
        return homogeneousmatrix.rotzyx(self.gpos)

    @property
    cpdef jacobian(self):           #mes modifs.......
        """
        T_n/r = 
        """   
        cdef float sx = sinf(self.gpos[0])
        cdef float cx = cosf(self.gpos[0])
        cdef float sy = sinf(self.gpos[1])
        cdef float cy = cosf(self.gpos[1])
        cdef np.ndarray[DTYPE_t, ndim=2] value = np.array (
            ([ 1.   ,  0. , -sy    ],
             [ 0.   , cx  ,  sx*sy ],
             [ 0.   ,-sx  ,  cx*cy ],
             [ 0.   ,  0. ,  0.    ],
             [ 0.   ,  0. ,  0.    ],
             [ 0.   ,  0. ,  0.    ]),   dtype=DTYPE)
        return value

_________________________________________________________________
Découvrez toutes les possibilités de communication avec vos proches
http://www.microsoft.com/windows/windowslive/default.aspx
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to