ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 19 Jul 2011 12:37:07 +0200cython stl classhttps://ask.sagemath.org/question/8225/cython-stl-class/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?
Thu, 14 Jul 2011 17:07:05 +0200https://ask.sagemath.org/question/8225/cython-stl-class/Answer by Volker Braun for <p>sage complains about importing the following spyx file:</p>
<pre><code>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]
</code></pre>
<p>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?</p>
https://ask.sagemath.org/question/8225/cython-stl-class/?answer=12524#post-id-12524You 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]
Tue, 19 Jul 2011 12:37:07 +0200https://ask.sagemath.org/question/8225/cython-stl-class/?answer=12524#post-id-12524