python - Passing cdef class object as argument to cdef method -


in cython, possible pass cython cdef class object instance argument cdef method. example if have below class:

# foo.pyx cdef class foo:     def __cinit__(self, double arg):         self.arg = arg      def get_arg_sqr(self):         return self.arg * 2  # bar.pyx  foo cimport foo cdef exec_foo(foo foo):     cdef double sqr = foo.get_arg_sqr() 

how achieve ?

# test.py foo import foo import bar foo f = foo(2.33) exec_foo(f) 

exec_foo should def not cdef if want access outside cython code. in notebook following seems work (without pyd/pyx files)

in opening cell

import cython %load_ext cython 

in next cell:

%%cython  cdef class foo:     cdef double arg      def __cinit__(self, double arg):         self.arg = arg      def get_arg_sqr(self):         return self.arg * 2  def exec_foo(foo foo):     cdef double sqr = foo.get_arg_sqr()     return sqr 

in final cell.

f = foo(1.0) exec_foo(f) 

Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -