First time here? Check out the FAQ!

Ask Your Question
1

cython stl class

asked 13 years ago

anonymous user

Anonymous

updated 13 years ago

sage complains about importing the following spyx file:

from libcpp.vector cimport vector as vec

cdef test_vector(): 
   cdef vec[int] vect 
   cdef int i 
   for i in range(10): 
       vect.push_back(i) 
   for i in range(10): 
       print vect[i]

I have no problem translating a pyx file with the same contents with cython and generating a module with test_vector ... . What is the right way to access the stl cpp vector class in a pyx file?

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
2

answered 13 years ago

Volker Braun gravatar image

You are probably not compiling it in c++ mode, though you don't quite say what you do. The following works if you paste it into a Sage-4.7 worksheet cell:

%cython 
#clang c++

from libcpp.vector cimport vector as vec

cpdef test_vector(): 
   cdef vec[int] vect 
   cdef int i 
   for i in range(10): 
       vect.push_back(i) 
   for i in range(10): 
       print vect[i]
Preview: (hide)
link

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 13 years ago

Seen: 519 times

Last updated: Jul 19 '11