Ask Your Question
1

cython stl class

asked 2011-07-14 17:07:05 +0200

anonymous user

Anonymous

updated 2011-07-15 03:49:36 +0200

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?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2011-07-19 12:37:07 +0200

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]
edit flag offensive delete link more

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: 2011-07-14 17:07:05 +0200

Seen: 424 times

Last updated: Jul 19 '11