On Tue, May 19, 2009 at 7:01 AM, OUARDA MEHDI <[email protected]> wrote:
> 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:

[snip]

>
> 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
>
>

>From the docs:

http://docs.cython.org/docs/extension_types.html#properties

There's a special syntax to define properties for extension types.

Instead of

---------------------------------------------------------
@property
def ndof(self):
    return 3
---------------------------------------------------------
You'd do:

---------------------------------------------------------
property ndof:
    def __get__(self):
        return 3
----------------------------------------------------------

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

Reply via email to