Robert Bradshaw wrote: > On Jun 23, 2009, at 1:40 AM, Jon Olav Vik wrote: > >> I have a Cython extension class that wraps the N_Vector type [1] >> from the >> Sundials solver suite for differential equations. (Thanks to Dag >> Sverre >> Seljebotn for guidance [2].) However, I have problems using the >> class outside >> of the module where it was defined (cynvector.pyx). >> >> The following couple of trivial operations work when included at >> the end of >> cynvector.pyx: >> >> cdef CythonNVector v = CythonNVector(2) # allocates empty N_Vector >> of length 2 >> cdef N_Vector p = v.nvector # alias to an attribute of the >> CythonNVector >> >> (I've learned that both v and p need to have their type specified by >> "cdef ...", otherwise they default to generic Python objects and >> the "nvector" >> attribute isn't recognized.) >> >> However, the same statements fail if I move them to another file, say >> test_cynvector.pyx: >> >> from sundials cimport * # sundials.pxd contains type declaration >> for N_Vector >> from cynvector import * >> cdef CythonNVector v = CythonNVector(2) # allocates empty N_Vector >> of length 2 >> cdef N_Vector p = v.nvector # alias to an attribute of the >> CythonNVector >> >> fails with: >> >> cdef CythonNVector v = CythonNVector(2) >> ^ >> 'CythonNVector' is not a type identifier >> >> Why isn't type CythonNVector recognized outside of cynvector.pyx? A >> similar >> error results if I try "from cynvector cimport CythonNVector"; then >> I get "Name >> 'CythonNVector' not declared in module 'cynvector'". > > What does your cynvector.pxd look like? You probably need to declare > CythonNVector there so other modules can cimport it.
Actually there probably is no -- it says import, not cimport. So you need a cynvector.pxd as well, and cimport in in addition to the normal import. (There's a wishlist item for automatically deducing this from pyx files, but it isn't there yet.) http://docs.cython.org/docs/sharing_declarations.html -- Dag Sverre _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
